mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-24 15:16:41 +00:00
tahoe_get: don't create the output file on error. Closes #121.
This commit is contained in:
parent
499add09e6
commit
931ab76588
@ -18,27 +18,23 @@ def get(options):
|
|||||||
if path:
|
if path:
|
||||||
url += "/" + escape_path(path)
|
url += "/" + escape_path(path)
|
||||||
|
|
||||||
if to_file:
|
|
||||||
outf = open(to_file, "wb")
|
|
||||||
close_outf = True
|
|
||||||
else:
|
|
||||||
outf = stdout
|
|
||||||
close_outf = False
|
|
||||||
|
|
||||||
resp = do_http("GET", url)
|
resp = do_http("GET", url)
|
||||||
if resp.status in (200, 201,):
|
if resp.status in (200, 201,):
|
||||||
|
if to_file:
|
||||||
|
outf = open(to_file, "wb")
|
||||||
|
else:
|
||||||
|
outf = stdout
|
||||||
while True:
|
while True:
|
||||||
data = resp.read(4096)
|
data = resp.read(4096)
|
||||||
if not data:
|
if not data:
|
||||||
break
|
break
|
||||||
outf.write(data)
|
outf.write(data)
|
||||||
|
if to_file:
|
||||||
|
outf.close()
|
||||||
rc = 0
|
rc = 0
|
||||||
else:
|
else:
|
||||||
print >>stderr, "Error, got %s %s" % (resp.status, resp.reason)
|
print >>stderr, "Error, got %s %s" % (resp.status, resp.reason)
|
||||||
print >>stderr, resp.read()
|
print >>stderr, resp.read()
|
||||||
rc = 1
|
rc = 1
|
||||||
|
|
||||||
if close_outf:
|
|
||||||
outf.close()
|
|
||||||
|
|
||||||
return rc
|
return rc
|
||||||
|
Loading…
Reference in New Issue
Block a user