From 18efd493dc0969f02a1819fb2fa680b025f94c4b Mon Sep 17 00:00:00 2001 From: laggardkernel Date: Mon, 27 May 2019 08:19:02 +0800 Subject: [PATCH 1/2] Parse full options for rm --- careful_rm.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/careful_rm.py b/careful_rm.py index c2227f3..4981add 100755 --- a/careful_rm.py +++ b/careful_rm.py @@ -621,6 +621,12 @@ def main(argv=None): tpath = argv[tindex] if len(argv) > tindex else os.curdir sys.stdout.write(get_trash(tpath)) return 0 + elif arg in ['-f', '--force']: + rec_args.append('-f') + shred_args.append('-f') + # TODO: interactive=WEHN + elif arg in ['-r', '-R', '--recursive']: + recursive = True elif arg == '--': # Everything after this is a file file_sep = '--' From a8037468662d2edb26f7c16fc9f734208ab2035b Mon Sep 17 00:00:00 2001 From: laggardkernel Date: Mon, 27 May 2019 08:38:32 +0800 Subject: [PATCH 2/2] Make -f work as expected Skip the prompt when -f, --force is used. --- careful_rm.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/careful_rm.py b/careful_rm.py index 4981add..ea5215f 100755 --- a/careful_rm.py +++ b/careful_rm.py @@ -485,7 +485,7 @@ def recycle_files(files, mv_flags, try_apple=True, verbose=False, dryrun=False): sys.stderr.write( 'Failed to recycle:\n{0}\n'.format(format_list(to_delete)) ) - if yesno('Attempt to fully delete with rm?', False): + if no_prompt or yesno('Attempt to fully delete with rm?', False): return to_delete return [] @@ -598,6 +598,7 @@ def main(argv=None): shred = False # Shred (destroy) files prior to deletion dryrun = False # Don't do anything, just print commands verbose = False # Print extra info + no_prompt = False # Skip prompt for confirmation recursive = False # Delete stuff in directories no_recycle = False # Force off recycling recycle = os.path.isfile(os.path.join(HOME, '.rm_recycle')) @@ -622,9 +623,10 @@ def main(argv=None): sys.stdout.write(get_trash(tpath)) return 0 elif arg in ['-f', '--force']: + no_prompt = True rec_args.append('-f') shred_args.append('-f') - # TODO: interactive=WEHN + # TODO: interactive=WHEN elif arg in ['-r', '-R', '--recursive']: recursive = True elif arg == '--': @@ -652,6 +654,7 @@ def main(argv=None): arg = arg.replace('s', '') shred = True if 'f' in arg: + no_prompt = True rec_args.append('-f') shred_args.append('-f') if 'i' in arg: @@ -772,21 +775,21 @@ def main(argv=None): else: msg += '\nThey contain no subfiles or directories' sys.stderr.write(msg + '\n') - if not yesno('Really delete?', False): + if not no_prompt and not yesno('Really delete?', False): return 1 sys.stderr.write('\n') # File handling if len(fls) >= CUTOFF: if len(fls) < MAX_LINE: - if not yesno('Delete the files {0}?'.format(fls), False): + if not no_prompt and not yesno('Delete the files {0}?'.format(fls), False): return 6 else: sys.stderr.write( 'Deleting the following {0} files:\n{1}\n' .format(len(fls), format_list(fls)) ) - if not yesno('Delete?', False): + if not no_prompt and not yesno('Delete?', False): return 10 sys.stderr.write('\n') @@ -816,7 +819,7 @@ def main(argv=None): 'The following cannot be recycled and will be deleted:\n{0}\n' .format(format_list(oth)) ) - if yesno('Delete?', False): + if no_prompt or yesno('Delete?', False): if call(sh.split('rm -- {0}'.format(' '.join(oth)))) == 0: sys.stderr.write('Done\n') else: @@ -855,7 +858,7 @@ def main(argv=None): ) ) msg = 'Continue with deletion anyway (data may not be scrubbed)?' - if not yesno(msg, False): + if not no_prompt and not yesno(msg, False): return 13 sys.stderr.write('\n')