From: Brian Warner Date: Sun, 27 Dec 2009 22:04:04 +0000 (-0500) Subject: tahoe_get: don't create the output file on error. Closes #121. X-Git-Tag: trac-4200~60 X-Git-Url: https://git.rkrishnan.org/pf/content/en/htmlfontify-example.html?a=commitdiff_plain;h=931ab76588dab2610e1b0c7fb7473274c5e0690e;p=tahoe-lafs%2Ftahoe-lafs.git tahoe_get: don't create the output file on error. Closes #121. --- diff --git a/src/allmydata/scripts/tahoe_get.py b/src/allmydata/scripts/tahoe_get.py index 927b210e..abcd927c 100644 --- a/src/allmydata/scripts/tahoe_get.py +++ b/src/allmydata/scripts/tahoe_get.py @@ -18,27 +18,23 @@ def get(options): if 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) if resp.status in (200, 201,): + if to_file: + outf = open(to_file, "wb") + else: + outf = stdout while True: data = resp.read(4096) if not data: break outf.write(data) + if to_file: + outf.close() rc = 0 else: print >>stderr, "Error, got %s %s" % (resp.status, resp.reason) print >>stderr, resp.read() rc = 1 - if close_outf: - outf.close() - return rc