From 8837c8f8221aff2ee599204dcb16266d53439547 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 12 Jul 2021 00:47:22 +0200 Subject: [PATCH] print zip/tar errors to log --- copyparty/httpcli.py | 2 +- copyparty/star.py | 6 ++++-- copyparty/sutil.py | 2 +- copyparty/szip.py | 7 ++++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index cc7a83cc..883c359c 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -1313,7 +1313,7 @@ class HttpCli(object): fgen = vn.zipgen(rem, items, self.uname, dots, not self.args.no_scandir) # for f in fgen: print(repr({k: f[k] for k in ["vp", "ap"]})) - bgen = packer(fgen, utf8="utf" in uarg, pre_crc="crc" in uarg) + bgen = packer(self.log, fgen, utf8="utf" in uarg, pre_crc="crc" in uarg) bsent = 0 for buf in bgen.gen(): if not buf: diff --git a/copyparty/star.py b/copyparty/star.py index 1903052d..b164cab0 100644 --- a/copyparty/star.py +++ b/copyparty/star.py @@ -33,10 +33,11 @@ class QFile(object): class StreamTar(object): """construct in-memory tar file from the given path""" - def __init__(self, fgen, **kwargs): + def __init__(self, log, fgen, **kwargs): self.ci = 0 self.co = 0 self.qfile = QFile() + self.log = log self.fgen = fgen self.errf = None @@ -91,7 +92,8 @@ class StreamTar(object): errors.append([f["vp"], repr(ex)]) if errors: - self.errf = errdesc(errors) + self.errf, txt = errdesc(errors) + self.log("\n".join(([repr(self.errf)] + txt[1:]))) self.ser(self.errf) self.tar.close() diff --git a/copyparty/sutil.py b/copyparty/sutil.py index 3c47420d..1bc24854 100644 --- a/copyparty/sutil.py +++ b/copyparty/sutil.py @@ -25,4 +25,4 @@ def errdesc(errors): "vp": "archive-errors-{}.txt".format(dt), "ap": tf_path, "st": os.stat(tf_path), - } + }, report diff --git a/copyparty/szip.py b/copyparty/szip.py index b4a7afdb..61d68ba2 100644 --- a/copyparty/szip.py +++ b/copyparty/szip.py @@ -183,7 +183,8 @@ def gen_ecdr64_loc(ecdr64_pos): class StreamZip(object): - def __init__(self, fgen, utf8=False, pre_crc=False): + def __init__(self, log, fgen, utf8=False, pre_crc=False): + self.log = log self.fgen = fgen self.utf8 = utf8 self.pre_crc = pre_crc @@ -246,8 +247,8 @@ class StreamZip(object): errors.append([f["vp"], repr(ex)]) if errors: - errf = errdesc(errors) - print(repr(errf)) + errf, txt = errdesc(errors) + self.log("\n".join(([repr(errf)] + txt[1:]))) for x in self.ser(errf): yield x