Bug 1164443 - Mozinstall should only install in an empty dir; r=ahal
☠☠ backed out by fa788695c8fc ☠ ☠
authorJulien Pagès <j.parkouss@gmail.com>
Wed, 10 Jun 2015 23:35:33 +0200
changeset 248180 7c72328e341baee3ea5b3514703c873ad95f695e
parent 248179 15f67d969310debf74a4065eace9d62c5a053b81
child 248181 d73a15153b3b3a61dcbe1f4a8e5a0ae60715c54a
push id28893
push userkwierso@gmail.com
push dateFri, 12 Jun 2015 00:02:58 +0000
treeherderautoland@8cf9d3e497f9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs1164443
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1164443 - Mozinstall should only install in an empty dir; r=ahal
testing/mozbase/mozinstall/mozinstall/mozinstall.py
--- a/testing/mozbase/mozinstall/mozinstall/mozinstall.py
+++ b/testing/mozbase/mozinstall/mozinstall/mozinstall.py
@@ -5,16 +5,17 @@
 from optparse import OptionParser
 import os
 import shutil
 import subprocess
 import sys
 import tarfile
 import time
 import zipfile
+import tempfile
 
 import mozfile
 import mozinfo
 
 try:
     import pefile
     has_pefile = True
 except ImportError:
@@ -88,55 +89,55 @@ def get_binary(path, app_name):
     return binary
 
 
 def install(src, dest):
     """Install a zip, exe, tar.gz, tar.bz2 or dmg file, and return the path of
     the installation folder.
 
     :param src: Path to the install file
-    :param dest: Path to install to (to ensure we do not overwrite any existent
-                 files the folder should not exist yet)
+    :param dest: Path to install to
     """
     src = os.path.realpath(src)
     dest = os.path.realpath(dest)
 
     if not is_installer(src):
         raise InvalidSource(src + ' is not valid installer file.')
 
-    did_we_create = False
     if not os.path.exists(dest):
-        did_we_create = True
         os.makedirs(dest)
+    else:
+        # create a subfolder to prevent data loss
+        dest = tempfile.mkdtemp(prefix="mozinstall", dir=dest)
 
     trbk = None
+    install_dir = None
     try:
-        install_dir = None
         if zipfile.is_zipfile(src) or tarfile.is_tarfile(src):
             install_dir = mozfile.extract(src, dest)[0]
         elif src.lower().endswith('.dmg'):
             install_dir = _install_dmg(src, dest)
         elif src.lower().endswith('.exe'):
             install_dir = _install_exe(src, dest)
 
         return install_dir
 
     except:
         cls, exc, trbk = sys.exc_info()
-        if did_we_create:
-            try:
-                # try to uninstall this properly
-                uninstall(dest)
-            except:
-                # uninstall may fail, let's just try to clean the folder
-                # in this case
-                try:
-                    mozfile.remove(dest)
-                except:
-                    pass
+        # try to uninstall this properly
+        try:
+            if install_dir:
+                uninstall(install_dir)
+        except:
+            pass
+        # remove the dest folder anyway
+        try:
+            mozfile.remove(dest)
+        except:
+            pass
         if issubclass(cls, Exception):
             error = InstallError('Failed to install "%s (%s)"' % (src, str(exc)))
             raise InstallError, error, trbk
         # any other kind of exception like KeyboardInterrupt is just re-raised.
         raise cls, exc, trbk
 
     finally:
         # trbk won't get GC'ed due to circular reference