Bug 1164443 - Mozinstall should only install in an empty dir; r=ahal

--HG--
extra : commitid : 9jTgPYAbTt0
extra : rebase_source : 89a108164c90062f2534a06d1edd466d4185c711
This commit is contained in:
Julien Pagès 2015-06-10 23:35:33 +02:00
Родитель 3aad780da9
Коммит 4d00f25d01
1 изменённых файлов: 17 добавлений и 16 удалений

Просмотреть файл

@ -10,6 +10,7 @@ import sys
import tarfile import tarfile
import time import time
import zipfile import zipfile
import tempfile
import mozfile import mozfile
import mozinfo import mozinfo
@ -93,8 +94,7 @@ def install(src, dest):
the installation folder. the installation folder.
:param src: Path to the install file :param src: Path to the install file
:param dest: Path to install to (to ensure we do not overwrite any existent :param dest: Path to install to
files the folder should not exist yet)
""" """
src = os.path.realpath(src) src = os.path.realpath(src)
dest = os.path.realpath(dest) dest = os.path.realpath(dest)
@ -102,14 +102,15 @@ def install(src, dest):
if not is_installer(src): if not is_installer(src):
raise InvalidSource(src + ' is not valid installer file.') raise InvalidSource(src + ' is not valid installer file.')
did_we_create = False
if not os.path.exists(dest): if not os.path.exists(dest):
did_we_create = True
os.makedirs(dest) os.makedirs(dest)
else:
# create a subfolder to prevent data loss
dest = tempfile.mkdtemp(prefix="mozinstall", dir=dest)
trbk = None trbk = None
try:
install_dir = None install_dir = None
try:
if zipfile.is_zipfile(src) or tarfile.is_tarfile(src): if zipfile.is_zipfile(src) or tarfile.is_tarfile(src):
install_dir = mozfile.extract(src, dest)[0] install_dir = mozfile.extract(src, dest)[0]
elif src.lower().endswith('.dmg'): elif src.lower().endswith('.dmg'):
@ -121,13 +122,13 @@ def install(src, dest):
except: except:
cls, exc, trbk = sys.exc_info() cls, exc, trbk = sys.exc_info()
if did_we_create:
try:
# try to uninstall this properly # try to uninstall this properly
uninstall(dest) try:
if install_dir:
uninstall(install_dir)
except: except:
# uninstall may fail, let's just try to clean the folder pass
# in this case # remove the dest folder anyway
try: try:
mozfile.remove(dest) mozfile.remove(dest)
except: except: