bug 455578: make sure upload.py always cleans up after itself. r=ted
authorBen Hearsum <bhearsum@mozilla.com>
Wed, 07 Jan 2009 08:52:20 -0500
changeset 23409 e30ccbc29e3ca73ad18ef622a72c0f5886caf61a
parent 23408 da2483729836094885f54fd606924f8ec351b489
child 23410 53f438686fa2090f209816328596610c8a675053
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs455578
milestone1.9.2a1pre
bug 455578: make sure upload.py always cleans up after itself. r=ted
build/upload.py
--- a/build/upload.py
+++ b/build/upload.py
@@ -157,34 +157,40 @@ def UploadFiles(user, host, path, files,
     If verbose is True, print status updates while working."""
     if upload_to_temp_dir:
         path = DoSSHCommand("mktemp -d", user, host, port=port, ssh_key=ssh_key)
     if not path.endswith("/"):
         path += "/"
     if base_path is not None:
         base_path = os.path.abspath(base_path)
     remote_files = []
-    for file in files:
-        file = os.path.abspath(file)
-        if not os.path.isfile(file):
-            raise IOError("File not found: %s" % file)
-        # first ensure that path exists remotely
-        remote_path = GetRemotePath(path, file, base_path)
-        DoSSHCommand("mkdir -p " + remote_path, user, host, port=port, ssh_key=ssh_key)
-        if verbose:
-            print "Uploading " + file
-        DoSCPFile(file, remote_path, user, host, port=port, ssh_key=ssh_key)
-        remote_files.append(remote_path + '/' + os.path.basename(file))
-    if post_upload_command is not None:
-        if verbose:
-            print "Running post-upload command: " + post_upload_command
-        file_list = '"' + '" "'.join(remote_files) + '"'
-        DoSSHCommand('%s "%s" %s' % (post_upload_command, path, file_list), user, host, port=port, ssh_key=ssh_key)
-    if upload_to_temp_dir:
-        DoSSHCommand("rm -rf %s" % path, user, host, port=port, ssh_key=ssh_key)
+    try:
+        for file in files:
+            file = os.path.abspath(file)
+            if not os.path.isfile(file):
+                raise IOError("File not found: %s" % file)
+            # first ensure that path exists remotely
+            remote_path = GetRemotePath(path, file, base_path)
+            DoSSHCommand("mkdir -p " + remote_path, user, host, port=port, ssh_key=ssh_key)
+            if verbose:
+                print "Uploading " + file
+            DoSCPFile(file, remote_path, user, host, port=port, ssh_key=ssh_key)
+            remote_files.append(remote_path + '/' + os.path.basename(file))
+        if post_upload_command is not None:
+            if verbose:
+                print "Running post-upload command: " + post_upload_command
+            file_list = '"' + '" "'.join(remote_files) + '"'
+            DoSSHCommand('%s "%s" %s' % (post_upload_command, path, file_list), user, host, port=port, ssh_key=ssh_key)
+    except:
+        print "Encountered error while uploading"
+        raise
+    finally:
+        if upload_to_temp_dir:
+            DoSSHCommand("rm -rf %s" % path, user, host, port=port,
+                         ssh_key=ssh_key)
     if verbose:
         print "Upload complete"
 
 if __name__ == '__main__':
     host = RequireEnvironmentVariable('UPLOAD_HOST')
     user = RequireEnvironmentVariable('UPLOAD_USER')
     path = OptionalEnvironmentVariable('UPLOAD_PATH')
     upload_to_temp_dir = OptionalEnvironmentVariable('UPLOAD_TO_TEMP')