From 883cacf9038b6f06efbc34e43184cd75a70bc742 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 25 Mar 2015 16:31:35 -0700 Subject: [PATCH] wormhole receive-file: add --overwrite --- src/wormhole/scripts/cmd_receive_file.py | 2 +- src/wormhole/scripts/runner.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wormhole/scripts/cmd_receive_file.py b/src/wormhole/scripts/cmd_receive_file.py index cacc5df..68a485d 100644 --- a/src/wormhole/scripts/cmd_receive_file.py +++ b/src/wormhole/scripts/cmd_receive_file.py @@ -65,7 +65,7 @@ def receive_file(args): record_pipe.send_record("bad filename\n") record_pipe.close() return 1 - if os.path.exists(target): + if os.path.exists(target) and not args.overwrite: print("Error: refusing to overwrite existing file %s" % (filename,)) record_pipe.send_record("file already exists\n") record_pipe.close() diff --git a/src/wormhole/scripts/runner.py b/src/wormhole/scripts/runner.py index 0bfa39d..d38cb22 100644 --- a/src/wormhole/scripts/runner.py +++ b/src/wormhole/scripts/runner.py @@ -52,6 +52,12 @@ p.add_argument("-o", "--output-file", default=None, metavar="FILENAME", The file to create, overriding the filename suggested by the sender"""), ) +p.add_argument("--overwrite", action="store_true", + help=dedent("""\ + Allow the output file to be overwritten. By default, if the + output file already exists, the program will refuse to + overwrite it."""), + ) p.add_argument("code", nargs="?", default=None, metavar="[CODE]", help=dedent("""\ The magic-wormhole code, from the sender. If omitted, the