receive-file: add --output-file to override local output filename
This commit is contained in:
parent
5fd85fd884
commit
84aa7ff248
|
@ -44,15 +44,18 @@ def receive_file(so):
|
||||||
print("Receiving %d bytes for '%s' (%s).." % (filesize, filename,
|
print("Receiving %d bytes for '%s' (%s).." % (filesize, filename,
|
||||||
transit_receiver.describe()))
|
transit_receiver.describe()))
|
||||||
|
|
||||||
# only write to the current directory, and never overwrite anything
|
target = so["output-file"]
|
||||||
here = os.path.abspath(os.getcwd())
|
if not target:
|
||||||
target = os.path.abspath(os.path.join(here, filename))
|
# allow the sender to specify the filename, but only write to the
|
||||||
if os.path.dirname(target) != here:
|
# current directory, and never overwrite anything
|
||||||
print("Error: suggested filename (%s) would be outside current directory"
|
here = os.path.abspath(os.getcwd())
|
||||||
% (filename,))
|
target = os.path.abspath(os.path.join(here, filename))
|
||||||
record_pipe.send_record("bad filename\n")
|
if os.path.dirname(target) != here:
|
||||||
record_pipe.close()
|
print("Error: suggested filename (%s) would be outside current directory"
|
||||||
return 1
|
% (filename,))
|
||||||
|
record_pipe.send_record("bad filename\n")
|
||||||
|
record_pipe.close()
|
||||||
|
return 1
|
||||||
if os.path.exists(target):
|
if os.path.exists(target):
|
||||||
print("Error: refusing to overwrite existing file %s" % (filename,))
|
print("Error: refusing to overwrite existing file %s" % (filename,))
|
||||||
record_pipe.send_record("file already exists\n")
|
record_pipe.send_record("file already exists\n")
|
||||||
|
@ -79,7 +82,7 @@ def receive_file(so):
|
||||||
|
|
||||||
os.rename(tmp, target)
|
os.rename(tmp, target)
|
||||||
|
|
||||||
print("Received file written to %s" % filename)
|
print("Received file written to %s" % target)
|
||||||
record_pipe.send_record("ok\n")
|
record_pipe.send_record("ok\n")
|
||||||
record_pipe.close()
|
record_pipe.close()
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -17,6 +17,9 @@ class SendFileOptions(usage.Options):
|
||||||
synopsis = "FILENAME"
|
synopsis = "FILENAME"
|
||||||
|
|
||||||
class ReceiveFileOptions(usage.Options):
|
class ReceiveFileOptions(usage.Options):
|
||||||
|
optParameters = [
|
||||||
|
["output-file", "o", None, "File to create"],
|
||||||
|
]
|
||||||
def parseArgs(self, code=None):
|
def parseArgs(self, code=None):
|
||||||
self["code"] = code
|
self["code"] = code
|
||||||
synopsis = "[CODE]"
|
synopsis = "[CODE]"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user