Fix symlink pruning not checking for directory links.
This commit is contained in:
		
							parent
							
								
									1511852e94
								
							
						
					
					
						commit
						0d918efe4c
					
				
					 1 changed files with 20 additions and 16 deletions
				
			
		|  | @ -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) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue