diff mbox

[Branch,~linaro-maintainers/linaro-image-tools/trunk] Rev 258: Do not try to clean stuff up when there's nothing to cleanup.

Message ID 20110125125331.22770.44427.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

Guilherme Salgado Jan. 25, 2011, 12:53 p.m. UTC
------------------------------------------------------------
revno: 258
fixes bug(s): https://launchpad.net/bugs/705549
committer: Guilherme Salgado <salgado@canonical.com>
branch nick: trunk
timestamp: Tue 2011-01-25 10:51:19 -0200
message:
  Do not try to clean stuff up when there's nothing to cleanup.
modified:
  linaro-media-create


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'linaro-media-create'
--- linaro-media-create	2011-01-18 13:23:16 +0000
+++ linaro-media-create	2011-01-25 12:51:19 +0000
@@ -26,11 +26,11 @@ 
     )
 from linaro_media_create import get_args_parser
 
-
-TMP_DIR = tempfile.mkdtemp()
-ROOTFS_DIR = os.path.join(TMP_DIR, 'binary')
-BOOT_DISK = os.path.join(TMP_DIR, 'boot-disc')
-ROOT_DISK = os.path.join(TMP_DIR, 'root-disc')
+# Just define the global variables
+TMP_DIR = None
+ROOTFS_DIR = None
+BOOT_DISK = None
+ROOT_DISK = None
 
 
 # Registered as the first atexit handler as we want this to be the last
@@ -44,13 +44,16 @@ 
     devnull = open('/dev/null', 'w')
     # Use raw subprocess.Popen as we don't want to stop in case the
     # commands end with a non-zero return code.
-    Popen(
-        ['sudo', 'umount', BOOT_DISK], stdout=devnull, stderr=devnull).wait()
-    Popen(
-        ['sudo', 'umount', ROOT_DISK], stdout=devnull, stderr=devnull).wait()
+    if BOOT_DISK is not None:
+        Popen(['sudo', 'umount', BOOT_DISK],
+              stdout=devnull, stderr=devnull).wait()
+    if ROOT_DISK is not None:
+        Popen(['sudo', 'umount', ROOT_DISK],
+              stdout=devnull, stderr=devnull).wait()
     # Remove TMP_DIR as root because some files written there are
     # owned by root.
-    Popen(['sudo', 'rm', '-rf', TMP_DIR]).wait()
+    if TMP_DIR is not None:
+        Popen(['sudo', 'rm', '-rf', TMP_DIR]).wait()
 
 
 def ensure_required_commands(args):
@@ -71,6 +74,14 @@ 
 if __name__ == '__main__':
     parser = get_args_parser()
     args = parser.parse_args()
+
+    # If --help was specified this won't execute.
+    # Create temp dir and initialize rest of path vars.
+    TMP_DIR = tempfile.mkdtemp()
+    ROOTFS_DIR = os.path.join(TMP_DIR, 'binary')
+    BOOT_DISK = os.path.join(TMP_DIR, 'boot-disc')
+    ROOT_DISK = os.path.join(TMP_DIR, 'root-disc')
+
     board_config = board_configs[args.board]
 
     ensure_required_commands(args)