sane-sync-music: prune directories left empty by sync
This commit is contained in:
@@ -280,6 +280,7 @@ class Sync:
|
||||
in_files = { p.relative_to(self.in_dir) for p in Path(self.in_dir).rglob("*") if not p.is_dir() }
|
||||
logger.info(f'found {len(in_files)} files in source')
|
||||
|
||||
# create a map from source path to dest path
|
||||
in_out_map = ((in_f, self.target_name(in_f)) for in_f in in_files)
|
||||
in_out_map = dict((in_f, out_f) for (in_f, out_f) in in_out_map if out_f is not None)
|
||||
logger.info(f'recognized {len(in_files)} source files as media')
|
||||
@@ -323,7 +324,11 @@ class Sync:
|
||||
'''
|
||||
for f in files:
|
||||
logger.info(f'removing {f}')
|
||||
self.encoder.remove(Path(self.out_dir) / f)
|
||||
f = Path(self.out_dir) / f
|
||||
self.encoder.remove(f)
|
||||
# if the directory is empty after removing this file, then remove the directory (and possibly prune its parents too)
|
||||
if not os.listdir(f.parent):
|
||||
os.removedirs(f.parent)
|
||||
|
||||
def copy_one(self, src_name: Path, dest_name: Path) -> None:
|
||||
'''
|
||||
|
Reference in New Issue
Block a user