Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Bug 931894 - [mozprofile] IOError in AddonManager.__del__ when trying…
Browse files Browse the repository at this point in the history
… to backup an already existent unpacked add-on. r=ahal
  • Loading branch information
whimboo committed Nov 5, 2013
1 parent cc12e2c commit 2de29b0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
7 changes: 5 additions & 2 deletions mozprofile/mozprofile/addons.py
Expand Up @@ -262,8 +262,9 @@ def install_from_path(self, path, unpack=False):
addon_path = os.path.join(extensions_path, addon_id)

if os.path.isfile(addon):
# save existing xpi file to restore later
addon_path += '.xpi'

# save existing xpi file to restore later
if os.path.exists(addon_path):
self.backup_dir = self.backup_dir or tempfile.mkdtemp()
shutil.copy(addon_path, self.backup_dir)
Expand All @@ -275,7 +276,9 @@ def install_from_path(self, path, unpack=False):
# save existing dir to restore later
if os.path.exists(addon_path):
self.backup_dir = self.backup_dir or tempfile.mkdtemp()
dir_util.copy_tree(addon_path, self.backup_dir, preserve_symlinks=1)
dest = os.path.join(self.backup_dir,
os.path.basename(addon_path))
dir_util.copy_tree(addon_path, dest, preserve_symlinks=1)

dir_util.copy_tree(addon, addon_path, preserve_symlinks=1)

Expand Down
1 change: 1 addition & 0 deletions mozprofile/mozprofile/profile.py
Expand Up @@ -243,6 +243,7 @@ def is_file_locked():

def cleanup(self):
"""Cleanup operations for the profile."""

if self.restore:
if self.create_new:
if os.path.exists(self.profile):
Expand Down
30 changes: 29 additions & 1 deletion mozprofile/tests/test_addons.py
Expand Up @@ -25,12 +25,22 @@ class TestAddonsManager(unittest.TestCase):

def setUp(self):
self.profile = mozprofile.profile.Profile()
self.am = mozprofile.addons.AddonManager(profile=self.profile.profile)
self.am = self.profile.addon_manager

self.profile_path = self.profile.profile
self.tmpdir = tempfile.mkdtemp()

def tearDown(self):
mozfile.rmtree(self.tmpdir)

self.am = None
self.profile = None

# Bug 934484
# Sometimes the profile folder gets recreated at the end and will be left
# behind. So we should ensure that we clean it up correctly.
mozfile.rmtree(self.profile_path)

def test_install_from_path_xpi(self):
addons_to_install = []
addons_installed = []
Expand Down Expand Up @@ -82,6 +92,24 @@ def test_install_from_path_url(self):
for addon in self.am.downloaded_addons:
self.assertTrue(os.path.isfile(addon))

def test_install_from_path_backup(self):
# Generate installer stubs for all possible types of addons
addons = []
addons.append(generate_addon('test-addon-1@mozilla.org',
path=self.tmpdir,
xpi=False))
addons.append(generate_addon('test-addon-1@mozilla.org',
path=self.tmpdir,
xpi=False,
name='test-addon-1-dupe@mozilla.org'))
addons.sort()

self.am.install_from_path(self.tmpdir)

self.assertIsNotNone(self.am.backup_dir)
self.assertEqual(os.listdir(self.am.backup_dir),
['test-addon-1@mozilla.org'])

def test_install_from_path_invalid_addons(self):
# Generate installer stubs for all possible types of addons
addons = []
Expand Down

0 comments on commit 2de29b0

Please sign in to comment.