From f37187a041d269f67c1df66b401c29da5677b9f9 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 13 Jul 2024 01:09:19 +0200 Subject: [PATCH] fix bugs detected by pyright but not pylance: * race-the-beam broke in v1.13.3 (i'm good at this) * wrong logger type in certgen --- copyparty/cert.py | 18 +++++++++++------- copyparty/httpcli.py | 11 ++++++++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/copyparty/cert.py b/copyparty/cert.py index 8aff3609..1923edfc 100644 --- a/copyparty/cert.py +++ b/copyparty/cert.py @@ -12,7 +12,7 @@ from .util import Netdev, runcmd, wrename, wunlink HAVE_CFSSL = True if True: # pylint: disable=using-constant-test - from .util import RootLogger + from .util import NamedLogger, RootLogger if ANYWIN: @@ -83,6 +83,8 @@ def _read_crt(args, fn): def _gen_ca(log: "RootLogger", args): + nlog: "NamedLogger" = lambda msg, c=0: log("cert-gen-ca", msg, c) + expiry = _read_crt(args, "ca.pem")[0] if time.time() + args.crt_cdays * 60 * 60 * 24 * 0.1 < expiry: return @@ -113,16 +115,18 @@ def _gen_ca(log: "RootLogger", args): bname = os.path.join(args.crt_dir, "ca") try: - wunlink(log, bname + ".key", VF) + wunlink(nlog, bname + ".key", VF) except: pass - wrename(log, bname + "-key.pem", bname + ".key", VF) - wunlink(log, bname + ".csr", VF) + wrename(nlog, bname + "-key.pem", bname + ".key", VF) + wunlink(nlog, bname + ".csr", VF) log("cert", "new ca OK", 2) def _gen_srv(log: "RootLogger", args, netdevs: dict[str, Netdev]): + nlog: "NamedLogger" = lambda msg, c=0: log("cert-gen-srv", msg, c) + names = args.crt_ns.split(",") if args.crt_ns else [] if not args.crt_exact: for n in names[:]: @@ -196,11 +200,11 @@ def _gen_srv(log: "RootLogger", args, netdevs: dict[str, Netdev]): bname = os.path.join(args.crt_dir, "srv") try: - wunlink(log, bname + ".key", VF) + wunlink(nlog, bname + ".key", VF) except: pass - wrename(log, bname + "-key.pem", bname + ".key", VF) - wunlink(log, bname + ".csr", VF) + wrename(nlog, bname + "-key.pem", bname + ".key", VF) + wunlink(nlog, bname + ".csr", VF) with open(os.path.join(args.crt_dir, "ca.pem"), "rb") as f: ca = f.read() diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 4a663c04..010c86ff 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -3421,7 +3421,16 @@ class HttpCli(object): if lower < upper and not broken: with open(req_path, "rb") as f: - remains = sendfile_py(self.log, lower, upper, f, self.s, wr_sz, wr_slp) + remains = sendfile_py( + self.log, + lower, + upper, + f, + self.s, + wr_sz, + wr_slp, + not self.args.no_poll, + ) spd = self._spd((upper - lower) - remains) if self.do_log: