Cleanup temporary dirs, even if convertor fails
authorShuangquan Zhou <shuangquan.zhou@intel.com>
Tue, 20 Sep 2011 08:27:03 +0000 (16:27 +0800)
committerShuangquan Zhou <shuangquan.zhou@intel.com>
Tue, 20 Sep 2011 08:27:03 +0000 (16:27 +0800)
plugins/imager/livecd_plugin.py
plugins/imager/liveusb_plugin.py

index 67f595f..113395e 100644 (file)
@@ -155,14 +155,16 @@ class LiveCDPlugin(ImagerPlugin):
         convertor._LoopImageCreator__imgdir = base_on_dir
         convertor._set_fstype("ext3")
         convertor._set_image_size(srcimgsize)
-        convertor.mount()
-        __mkinitrd(convertor)
-        convertor._create_bootconfig()
-        __run_post_cleanups(convertor)
-        convertor.unmount()
-        convertor.package()
-        convertor.print_outimage_info()
-        shutil.rmtree(base_on_dir, ignore_errors = True)
+        try:
+            convertor.mount()
+            __mkinitrd(convertor)
+            convertor._create_bootconfig()
+            __run_post_cleanups(convertor)
+            convertor.unmount()
+            convertor.package()
+            convertor.print_outimage_info()
+        finally:
+            shutil.rmtree(base_on_dir, ignore_errors = True)
 
     @classmethod
     def do_unpack(cls, srcimg):
index 96e03e9..23b2c24 100644 (file)
@@ -157,14 +157,16 @@ class LiveUSBPlugin(ImagerPlugin):
         convertor._set_image_size(srcimgsize)
         base_on_dir = os.path.dirname(base_on)
         convertor._LoopImageCreator__imgdir = base_on_dir
-        convertor.mount()
-        __mkinitrd(convertor)
-        convertor._create_bootconfig()
-        __run_post_cleanups(convertor)
-        convertor.unmount()
-        convertor.package()
-        convertor.print_outimage_info()
-        shutil.rmtree(base_on_dir, ignore_errors = True)
+        try:
+            convertor.mount()
+            __mkinitrd(convertor)
+            convertor._create_bootconfig()
+            __run_post_cleanups(convertor)
+            convertor.unmount()
+            convertor.package()
+            convertor.print_outimage_info()
+        finally:
+            shutil.rmtree(base_on_dir, ignore_errors = True)
 
     @classmethod
     def do_unpack(cls, srcimg):