Skip to content

Commit

Permalink
fix import deletion race
Browse files Browse the repository at this point in the history
By moving the duplicate file removal to the manipulate_files coroutine, we
ensure that all previous albums are fully moved/copied before trying to delete
their duplicate files.
  • Loading branch information
sampsyo committed Aug 26, 2013
1 parent e91a080 commit ca20605
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
18 changes: 13 additions & 5 deletions beets/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,13 +768,12 @@ def apply_choices(session):

# Delete duplicate files that are located inside the library
# directory.
task.duplicate_paths = []
for duplicate_path in [i.path for i in duplicate_items]:
if session.lib.directory in util.ancestry(duplicate_path):
log.debug(u'deleting replaced duplicate %s' %
util.displayable_path(duplicate_path))
util.remove(duplicate_path)
util.prune_dirs(os.path.dirname(duplicate_path),
session.lib.directory)
# Mark the path for deletion in the manipulate_files
# stage.
task.duplicate_paths.append(duplicate_path)

# Add items -- before path changes -- to the library. We add the
# items now (rather than at the end) so that album structures
Expand Down Expand Up @@ -823,6 +822,15 @@ def manipulate_files(session):
if task.should_skip():
continue

# Remove duplicate files marked for deletion.
if task.remove_duplicates:
for duplicate_path in task.duplicate_paths:
log.debug(u'deleting replaced duplicate %s' %
util.displayable_path(duplicate_path))
util.remove(duplicate_path)
util.prune_dirs(os.path.dirname(duplicate_path),
session.lib.directory)

# Move/copy/write files.
items = task.imported_items()
task.old_paths = [item.path for item in items] # For deletion.
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Changelog
* :doc:`/plugins/fetchart`: Look for images in the Cover Art Archive for
the release group in addition to the specific release. Thanks to Filipe
Fortes.
* Fix a race in the importer that could cause files to be deleted before they
were imported. This happened when importing one album, importing a duplicate
album, and then asking for the first album to be replaced with the second.
The situation could only arise when importing music from the library
directory and when the two albums are imported close in time.


1.2.1 (June 22, 2013)
Expand Down

0 comments on commit ca20605

Please sign in to comment.