-
Notifications
You must be signed in to change notification settings - Fork 203
Guarded rm #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Guarded rm #382
Changes from all commits
3068163
1a89c8b
5a01149
b57da9e
d722f85
0b9596c
9ea4cca
3f834ae
43340ea
0138223
37a3c38
7ce59a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| def prepare_output_message(files_to_remove): | ||
| if not files_to_remove: | ||
| return 'No files to be removed.' | ||
| else: | ||
| return 'The following files / directories will be removed:\n' + '\n'.join( | ||
| ' - ' + file[0] for file in files_to_remove) + '\nProceed? (y/N) ' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,19 @@ | |
| from trashcli.compat import Protocol | ||
|
|
||
| from trashcli.fs import ContentsOf | ||
| from trashcli.guard.guard import Guard | ||
| from trashcli.guard.is_input_interactive import is_input_interactive | ||
| from trashcli.guard.parse_reply import parse_reply | ||
| from trashcli.guard.user import User | ||
|
abstract-official marked this conversation as resolved.
|
||
| from trashcli.lib.dir_checker import DirChecker | ||
| from trashcli.lib.dir_reader import DirReader | ||
| from trashcli.lib.my_input import RealInput | ||
| from trashcli.lib.user_info import SingleUserInfoProvider | ||
| from trashcli.rm.cleanable_trashcan import CleanableTrashcan | ||
| from trashcli.rm.file_remover import FileRemover | ||
| from trashcli.rm.filter import Filter | ||
| from trashcli.rm.list_trashinfo import ListTrashinfos | ||
| from trashcli.rm.prepare_output_message import prepare_output_message | ||
| from trashcli.trash_dirs_scanner import TrashDirsScanner, TopTrashDirRules, \ | ||
| trash_dir_found | ||
|
|
||
|
|
@@ -60,6 +66,7 @@ def run(self, argv, uid): | |
|
|
||
| for event, args in scanner.scan_trash_dirs(self.environ, uid): | ||
| if event == trash_dir_found: | ||
| files_to_remove = [] | ||
| path, volume = args | ||
| for type, arg in listing.list_from_volume_trashdir(path, | ||
| volume): | ||
|
|
@@ -68,8 +75,15 @@ def run(self, argv, uid): | |
| elif type == 'trashed_file': | ||
| original_location, info_file = arg | ||
| if cmd.matches(original_location): | ||
| trashcan.delete_trash_info_and_backup_copy( | ||
| info_file) | ||
| files_to_remove.append(arg) | ||
| if files_to_remove: # skip asking the user if there is nothing to delete; avoids being stuck | ||
| user = User(prepare_output_message, RealInput(), parse_reply) | ||
| guard = Guard(user) | ||
| if guard.ask_the_user(is_input_interactive(), files_to_remove).ok_to_empty: | ||
| for file in files_to_remove: | ||
|
Comment on lines
+79
to
+83
|
||
| trashcan.delete_trash_info_and_backup_copy(file[1]) | ||
| else: | ||
| print('No files / directories to be removed in {}'.format(path)) | ||
|
Comment on lines
+79
to
+86
|
||
|
|
||
| def unable_to_parse_path(self, trashinfo): | ||
| self.report_error('{}: unable to parse \'Path\''.format(trashinfo)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This branch prints directly to stdout via
print(), bypassing theConsoleabstraction thatEmptyCmdwires up (and which is used elsewhere for output). This makes it harder to redirect/capture output consistently (e.g., whenEmptyCmdis used programmatically with a customout). Prefer emitting this message throughconsole.out(or add a dedicatedConsole.print_info()method) instead of usingprint().