Skip to content

Commit

Permalink
avoid sendfile bugs on 32bit machines:
Browse files Browse the repository at this point in the history
  • Loading branch information
9001 committed Jan 17, 2024
1 parent 3313503 commit b9d0c85
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
7 changes: 5 additions & 2 deletions copyparty/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
DEF_MTH,
IMPLICATIONS,
JINJA_VER,
PY_DESC,
PYFTPD_VER,
SQLITE_VER,
UNPLICATIONS,
align_tab,
ansi_re,
dedent,
min_ex,
py_desc,
pybin,
termsize,
wrap,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion copyparty/httpcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from .szip import StreamZip
from .util import (
APPLESAN_RE,
BITNESS,
HTTPCODE,
META_NOBOTS,
UTC,
Expand Down Expand Up @@ -2962,7 +2963,7 @@ def tx_file(self, req_path: str) -> bool:
use_sendfile = (
not self.tls #
and not self.args.no_sendfile
and hasattr(os, "sendfile")
and (BITNESS > 32 or file_sz < 0x7fffFFFF)
)

#
Expand Down
17 changes: 10 additions & 7 deletions copyparty/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ def sunpack(fmt: bytes, a: bytes) -> tuple[Any, ...]:
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]")


Expand Down Expand Up @@ -371,19 +377,14 @@ 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]

m = re.search(r"([0-9]+\.[0-9\.]+)", platform.version())
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
)


Expand Down Expand Up @@ -422,8 +423,10 @@ def _sqlite_ver() -> str:
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
)


Expand Down

0 comments on commit b9d0c85

Please sign in to comment.