diff --git a/beets/importer.py b/beets/importer.py index cf60b791a..a499ec792 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -522,9 +522,7 @@ def apply_choices(config): # Move/copy files. items = task.items if task.is_album else [task.item] - if config.copy and config.delete: - task.old_paths = [os.path.realpath(syspath(item.path)) - for item in items] + task.old_paths = [item.path for item in items] for item in items: if config.copy: item.move(lib, True, task.is_album) @@ -547,9 +545,9 @@ def apply_choices(config): # Remove old entries if we're re-importing old items. Old # album structures are automatically cleaned up when the # last item is removed. - for item in items: + for item, old_path in zip(items, task.old_paths): dup_items = list(lib.items( - library.MatchQuery('path', item.path) + library.MatchQuery('path', old_path) )) for dup_item in dup_items: if dup_item.id != item.id: diff --git a/test/test_importer.py b/test/test_importer.py index 15173badc..0c3dd5ac4 100644 --- a/test/test_importer.py +++ b/test/test_importer.py @@ -285,7 +285,7 @@ class AsIsApplyTest(unittest.TestCase): self.assertFalse(alb.comp) self.assertEqual(alb.albumartist, self.items[2].artist) -class ApplyExistingItemsTest(unittest.TestCase): +class ApplyExistingItemsTest(unittest.TestCase, _common.ExtraAsserts): def setUp(self): self.libdir = os.path.join(_common.RSRC, 'testlibdir') os.mkdir(self.libdir) @@ -343,6 +343,36 @@ class ApplyExistingItemsTest(unittest.TestCase): # Should not be duplicated. self.assertEqual(len(list(self.lib.items())), 1) + def test_apply_existing_item_new_metadata_does_not_duplicate(self): + # We want to copy the item to a new location. + self.config.copy = True + + # Import with existing metadata. + self._apply_asis([self.i]) + + # Import again with new metadata. + item = self.lib.items().next() + new_item = library.Item.from_path(item.path) + new_item.title = 'differentTitle' + self._apply_asis([new_item]) + + # Should not be duplicated. + self.assertEqual(len(list(self.lib.items())), 1) + self.assertEqual(len(list(self.lib.albums())), 1) + + def test_apply_existing_item_new_metadata_moves_files(self): + # As above, import with old metadata and then reimport with new. + self.config.copy = True + self._apply_asis([self.i]) + item = self.lib.items().next() + new_item = library.Item.from_path(item.path) + new_item.title = 'differentTitle' + self._apply_asis([new_item]) + + item = self.lib.items().next() + self.assertTrue('differentTitle' in item.path) + self.assertExists(item.path) + class InferAlbumDataTest(unittest.TestCase): def setUp(self): i1 = _common.item()