Skip to content

Commit

Permalink
Importer: Delete orphaned album art on re-imports
Browse files Browse the repository at this point in the history
First step towards fixing #314.
  • Loading branch information
reiv authored and sampsyo committed Nov 2, 2015
1 parent c617033 commit 629a80a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions beets/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,23 @@ def cleanup(self, copy=False, delete=False, move=False):

items = self.imported_items()

# If any original album art files were reused, leave them untouched.
for item in items:
album = item.get_album()
if album:
self.old_art_paths.discard(album.artpath)

# Delete remaining original album art files.
for old_art_path in self.old_art_paths:
log.debug('Deleting orphaned album art: {0}', old_art_path)
util.remove(syspath(old_art_path), True)
# XXX: Ideally the directory would get pruned with self.prune()
# below, but when calling `beet import -L`, self.toppath is set
# to None, making self.prune() a no-op; hence this workaround of
# calling util.prune_dirs() directly.
util.prune_dirs(os.path.dirname(old_art_path),
clutter=config['clutter'].as_str_seq())

# When copying and deleting originals, delete old files.
if copy and delete:
new_paths = [os.path.realpath(item.path) for item in items]
Expand Down Expand Up @@ -652,6 +669,11 @@ def manipulate_files(self, move=False, copy=False, write=False,
# Save the original paths of all items for deletion and pruning
# in the next step (finalization).
self.old_paths = [item.path for item in items]

# Keep track of paths of all original album art for the same reason.
self.old_art_paths = set(filter(bool,
(album.artpath for album in self.replaced_albums.values())))

for item in items:
if move or copy or link:
# In copy and link modes, treat re-imports specially:
Expand Down

0 comments on commit 629a80a

Please sign in to comment.