From b9d0c8536bf4caf9f719bcd1c1221effc95180d2 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 17 Jan 2024 20:56:44 +0000 Subject: [PATCH] avoid sendfile bugs on 32bit machines: https://github.com/python/cpython/issues/114077 --- copyparty/__main__.py | 7 +++++-- copyparty/httpcli.py | 3 ++- copyparty/util.py | 17 ++++++++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 9fb52f23..698fcbd4 100755 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -43,6 +43,7 @@ from .util import ( DEF_MTH, IMPLICATIONS, JINJA_VER, + PY_DESC, PYFTPD_VER, SQLITE_VER, UNPLICATIONS, @@ -50,7 +51,6 @@ from .util import ( ansi_re, dedent, min_ex, - py_desc, pybin, termsize, wrap, @@ -1380,7 +1380,7 @@ def main(argv: Optional[list[str]] = None) -> None: S_VERSION, CODENAME, S_BUILD_DT, - py_desc().replace("[", "\033[90m["), + PY_DESC.replace("[", "\033[90m["), SQLITE_VER, JINJA_VER, PYFTPD_VER, @@ -1545,6 +1545,9 @@ def main(argv: Optional[list[str]] = None) -> None: if sys.version_info < (3, 6): al.no_scandir = True + if not hasattr(os, "sendfile"): + al.no_sendfile = True + # signal.signal(signal.SIGINT, sighandler) SvcHub(al, dal, argv, "".join(printed)).run() diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index f55ef186..95631136 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -38,6 +38,7 @@ from .sutil import StreamArc, gfilter from .szip import StreamZip from .util import ( APPLESAN_RE, + BITNESS, HTTPCODE, META_NOBOTS, UTC, @@ -2962,7 +2963,7 @@ class HttpCli(object): use_sendfile = ( not self.tls # and not self.args.no_sendfile - and hasattr(os, "sendfile") + and (BITNESS > 32 or file_sz < 0x7fffFFFF) ) # diff --git a/copyparty/util.py b/copyparty/util.py index 4c9e8fc4..6fd009e8 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -167,6 +167,12 @@ except: return struct.unpack(fmt.decode("ascii"), a) +try: + BITNESS = struct.calcsize(b"P") * 8 +except: + BITNESS = struct.calcsize("P") * 8 + + ansi_re = re.compile("\033\\[[^mK]*[mK]") @@ -371,11 +377,6 @@ def py_desc() -> str: if ofs > 0: py_ver = py_ver[:ofs] - try: - bitness = struct.calcsize(b"P") * 8 - except: - bitness = struct.calcsize("P") * 8 - host_os = platform.system() compiler = platform.python_compiler().split("http")[0] @@ -383,7 +384,7 @@ def py_desc() -> str: os_ver = m.group(1) if m else "" return "{:>9} v{} on {}{} {} [{}]".format( - interp, py_ver, host_os, bitness, os_ver, compiler + interp, py_ver, host_os, BITNESS, os_ver, compiler ) @@ -422,8 +423,10 @@ except: PYFTPD_VER = "(None)" +PY_DESC = py_desc() + VERSIONS = "copyparty v{} ({})\n{}\n sqlite v{} | jinja v{} | pyftpd v{}".format( - S_VERSION, S_BUILD_DT, py_desc(), SQLITE_VER, JINJA_VER, PYFTPD_VER + S_VERSION, S_BUILD_DT, PY_DESC, SQLITE_VER, JINJA_VER, PYFTPD_VER )