mirror of
https://github.com/beetbox/beets.git
synced 2026-02-26 17:21:24 +01:00
prune empty directories when moving (#266)
This commit is contained in:
parent
953e23cb51
commit
b327455fac
2 changed files with 24 additions and 0 deletions
|
|
@ -731,7 +731,12 @@ def apply_choices(config):
|
|||
if config.copy or config.move:
|
||||
if config.move:
|
||||
# Just move the file.
|
||||
old_path = item.path
|
||||
lib.move(item, False)
|
||||
# Clean up empty parent directory.
|
||||
if task.toppath:
|
||||
util.prune_dirs(os.path.dirname(old_path),
|
||||
task.toppath)
|
||||
else:
|
||||
# If it's a reimport, move the file. Otherwise, copy
|
||||
# and keep track of the old path.
|
||||
|
|
|
|||
|
|
@ -307,6 +307,25 @@ class ImportApplyTest(unittest.TestCase, _common.ExtraAsserts):
|
|||
# not exist.
|
||||
self.assertEqual(task.old_paths, [])
|
||||
|
||||
def test_apply_with_move(self):
|
||||
config = _common.iconfig(self.lib, move=True)
|
||||
applyc = importer.apply_choices(config)
|
||||
applyc.next()
|
||||
finalize = importer.finalize(config)
|
||||
finalize.next()
|
||||
_call_apply([applyc], [self.i], self.info)
|
||||
self.assertExists(list(self.lib.items())[0].path)
|
||||
self.assertNotExists(self.srcpath)
|
||||
|
||||
def test_apply_with_move_prunes_empty_directory(self):
|
||||
config = _common.iconfig(self.lib, move=True)
|
||||
applyc = importer.apply_choices(config)
|
||||
applyc.next()
|
||||
finalize = importer.finalize(config)
|
||||
finalize.next()
|
||||
_call_apply([applyc], [self.i], self.info, self.srcdir)
|
||||
self.assertNotExists(os.path.dirname(self.srcpath))
|
||||
|
||||
class AsIsApplyTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.dbpath = os.path.join(_common.RSRC, 'templib.blb')
|
||||
|
|
|
|||
Loading…
Reference in a new issue