diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 6d70b248..cb5396e1 100755 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -594,6 +594,7 @@ def run_argparse(argv: list[str], formatter: Any, retry: bool) -> argparse.Names ap2.add_argument("--sparse", metavar="MiB", type=int, default=4, help="windows-only: minimum size of incoming uploads through up2k before they are made into sparse files") ap2.add_argument("--turbo", metavar="LVL", type=int, default=0, help="configure turbo-mode in up2k client; 0 = off and warn if enabled, 1 = off, 2 = on, 3 = on and disable datecheck") ap2.add_argument("--u2sort", metavar="TXT", type=u, default="s", help="upload order; s=smallest-first, n=alphabetical, fs=force-s, fn=force-n -- alphabetical is a bit slower on fiber/LAN but makes it easier to eyeball if everything went fine") + ap2.add_argument("--write-uplog", action="store_true", help="write POST reports to textfiles in working-directory") ap2 = ap.add_argument_group('network options') ap2.add_argument("-i", metavar="IP", type=u, default="0.0.0.0", help="ip to bind (comma-sep.)") diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index b70a2d94..d9014576 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -1421,12 +1421,16 @@ class HttpCli(object): vspd = self._spd(sz_total, False) self.log("{} {}".format(vspd, msg)) - if not nullwrite: - log_fn = "up.{:.6f}.txt".format(t0) - with open(log_fn, "wb") as f: - ft = "{}:{}".format(self.ip, self.addr[1]) - ft = "{}\n{}\n{}\n".format(ft, msg.rstrip(), errmsg) - f.write(ft.encode("utf-8")) + suf = "" + if not nullwrite and self.args.write_uplog: + try: + log_fn = "up.{:.6f}.txt".format(t0) + with open(log_fn, "wb") as f: + ft = "{}:{}".format(self.ip, self.addr[1]) + ft = "{}\n{}\n{}\n".format(ft, msg.rstrip(), errmsg) + f.write(ft.encode("utf-8")) + except Exception as ex: + suf = "\nfailed to write the upload report: {}".format(ex) sc = 400 if errmsg else 200 if "j" in self.uparam: @@ -1435,7 +1439,7 @@ class HttpCli(object): else: self.redirect( self.vpath, - msg=msg, + msg=msg + suf, flavor="return to", click=False, status=sc,