From 0d918efe4c67fd0cc37d880be7094e08940ec7dc Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 28 Jan 2021 17:05:20 -0800 Subject: [PATCH] Fix symlink pruning not checking for directory links. --- frontends/etiquette_cli.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/frontends/etiquette_cli.py b/frontends/etiquette_cli.py index c2a2df5..4cef9cb 100644 --- a/frontends/etiquette_cli.py +++ b/frontends/etiquette_cli.py @@ -253,22 +253,26 @@ def export_symlinks_argparse(args): ) total_paths.update(export) - if args.prune and not args.dry_run: - symlinks = set(file for file in spinal.walk_generator(destination) if file.is_link) - symlinks = symlinks.difference(total_paths) - for old_symlink in symlinks: - print(f'Pruning {old_symlink}.') - os.remove(old_symlink.absolute_path) - if not old_symlink.parent.listdir(): - os.rmdir(old_symlink.parent.absolute_path) - checkdirs = set(spinal.walk_generator(destination, yield_directories=True, yield_files=False)) - while checkdirs: - check = checkdirs.pop() - if check not in destination: - continue - if len(check.listdir()) == 0: - os.rmdir(check.absolute_path) - checkdirs.add(check.parent) + if not args.prune or args.dry_run: + return + + symlinks = spinal.walk_generator(destination, yield_directories=True, yield_files=True) + symlinks = set(path for path in symlinks if path.is_link) + symlinks = symlinks.difference(total_paths) + for old_symlink in symlinks: + print(f'Pruning {old_symlink}.') + os.remove(old_symlink.absolute_path) + if not old_symlink.parent.listdir(): + os.rmdir(old_symlink.parent.absolute_path) + + checkdirs = set(spinal.walk_generator(destination, yield_directories=True, yield_files=False)) + while checkdirs: + check = checkdirs.pop() + if check not in destination: + continue + if len(check.listdir()) == 0: + os.rmdir(check.absolute_path) + checkdirs.add(check.parent) def init_argparse(args): photodb = etiquette.photodb.PhotoDB(create=True)