From 7936f15f27dad0c24d856a56c3a7e278413b8b52 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 25 May 2021 01:34:06 -0700 Subject: [PATCH] Don't let output file be one of the input files. --- bitwise_or.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bitwise_or.py b/bitwise_or.py index 79a109b..a629b71 100644 --- a/bitwise_or.py +++ b/bitwise_or.py @@ -31,13 +31,15 @@ def bitwise_or_argparse(args): log.fatal('Need at least two input files.') return 1 - handles = [file.open('rb') for file in files] - output = pathclass.Path(args.output) if output.is_dir: log.fatal('Output path "%s" is a directory.', args.output) return 1 + if any(output == file for file in files): + log.fatal('Output cannot be one of the inputs.') + return 1 + if not output.exists: pass elif args.overwrite: @@ -45,6 +47,7 @@ def bitwise_or_argparse(args): elif not interactive.getpermission(f'Overwrite "{output.absolute_path}"?'): return 1 + handles = [file.open('rb') for file in files] output_handle = output.open('wb') while True: chunk = 0