ImportAdded support for in-place and link imports

Fix for the `ImportAdded` plugin crashing during in-place imports (#1107).

Add support for the new link imports introduced in Beets 1.3.9.

Note that link-imports that preserve file modification times will follow
the links and preserve the mtimes on the link targets. The mtimes on the
links aren't modified.
This commit is contained in:
Stig Inge Lea Bjørnsen 2014-12-25 21:34:13 +01:00
parent a892128996
commit a2188d475b
2 changed files with 21 additions and 1 deletions

View file

@ -43,6 +43,16 @@ def reimported_album(album):
return album.path in replaced_album_paths
@ImportAddedPlugin.listen('import_task_start')
def record_if_inplace(task, session):
if not (session.config['copy'] or session.config['move'] or
session.config['link']):
log.debug(u"In place import detected, recording mtimes from source"
u"paths")
for item in task.items:
record_import_mtime(item, item.path, item.path)
@ImportAddedPlugin.listen('import_task_files')
def record_reimported(task, session):
global reimported_item_ids, replaced_album_paths
@ -81,6 +91,7 @@ item_mtime = dict()
@ImportAddedPlugin.listen('before_item_moved')
@ImportAddedPlugin.listen('item_copied')
@ImportAddedPlugin.listen('item_linked')
def record_import_mtime(item, source, destination):
"""Record the file mtime of an item's path before its import.
"""

View file

@ -76,13 +76,22 @@ class ImportAddedTest(unittest.TestCase, ImportHelper):
"""For comparing file modification times at a sufficient precision"""
self.assertAlmostEqual(first, second, places=4, msg=msg)
def test_import_album_with_added_dates(self):
def assertAlbumImport(self):
self.importer.run()
album = self.lib.albums().get()
self.assertEqual(album.added, self.min_mtime)
for item in album.items():
self.assertEqual(item.added, self.min_mtime)
def test_import_album_with_added_dates(self):
self.assertAlbumImport()
def test_import_album_inplace_with_added_dates(self):
self.config['import']['copy'] = False
self.config['import']['move'] = False
self.config['import']['link'] = False
self.assertAlbumImport()
def test_import_album_with_preserved_mtimes(self):
self.config['importadded']['preserve_mtimes'] = True
self.importer.run()