Fix symlink pruning not checking for directory links.

This commit is contained in:
voussoir 2021-01-28 17:05:20 -08:00
parent 1511852e94
commit 0d918efe4c
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -253,22 +253,26 @@ def export_symlinks_argparse(args):
) )
total_paths.update(export) total_paths.update(export)
if args.prune and not args.dry_run: if not args.prune or args.dry_run:
symlinks = set(file for file in spinal.walk_generator(destination) if file.is_link) return
symlinks = symlinks.difference(total_paths)
for old_symlink in symlinks: symlinks = spinal.walk_generator(destination, yield_directories=True, yield_files=True)
print(f'Pruning {old_symlink}.') symlinks = set(path for path in symlinks if path.is_link)
os.remove(old_symlink.absolute_path) symlinks = symlinks.difference(total_paths)
if not old_symlink.parent.listdir(): for old_symlink in symlinks:
os.rmdir(old_symlink.parent.absolute_path) print(f'Pruning {old_symlink}.')
checkdirs = set(spinal.walk_generator(destination, yield_directories=True, yield_files=False)) os.remove(old_symlink.absolute_path)
while checkdirs: if not old_symlink.parent.listdir():
check = checkdirs.pop() os.rmdir(old_symlink.parent.absolute_path)
if check not in destination:
continue checkdirs = set(spinal.walk_generator(destination, yield_directories=True, yield_files=False))
if len(check.listdir()) == 0: while checkdirs:
os.rmdir(check.absolute_path) check = checkdirs.pop()
checkdirs.add(check.parent) if check not in destination:
continue
if len(check.listdir()) == 0:
os.rmdir(check.absolute_path)
checkdirs.add(check.parent)
def init_argparse(args): def init_argparse(args):
photodb = etiquette.photodb.PhotoDB(create=True) photodb = etiquette.photodb.PhotoDB(create=True)