From 261236e30272d3dfde4188c27ce90ed98f48d386 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 18 May 2025 21:34:38 +0000 Subject: [PATCH] st_mtime can be -11644473600 on win64 fat16 vhd --- bin/u2c.py | 2 +- copyparty/httpcli.py | 8 ++++---- copyparty/tftpd.py | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bin/u2c.py b/bin/u2c.py index 11ab733d..4d6a4d1b 100755 --- a/bin/u2c.py +++ b/bin/u2c.py @@ -1289,7 +1289,7 @@ class Ctl(object): if self.ar.jw: print("%s %s" % (wark, vp)) else: - zd = datetime.datetime.fromtimestamp(file.lmod, UTC) + zd = datetime.datetime.fromtimestamp(max(0, file.lmod), UTC) dt = "%04d-%02d-%02d %02d:%02d:%02d" % ( zd.year, zd.month, diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 3f444260..c33985a9 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -1412,7 +1412,7 @@ class HttpCli(object): desc = "%s - %s" % (tag_a, tag_t) if tag_t and tag_a else (tag_t or tag_a) desc = html_escape(desc, True, True) if desc else title mime = html_escape(guess_mime(title)) - lmod = formatdate(i["ts"]) + lmod = formatdate(max(0, i["ts"])) zsa = (iurl, iurl, title, desc, lmod, iurl, mime, i["sz"]) zs = ( """\ @@ -1569,7 +1569,7 @@ class HttpCli(object): for x in fgen: rp = vjoin(vtop, x["vp"]) st: os.stat_result = x["st"] - mtime = st.st_mtime + mtime = max(0, st.st_mtime) if stat.S_ISLNK(st.st_mode): try: st = bos.stat(os.path.join(tap, x["vp"])) @@ -3978,7 +3978,7 @@ class HttpCli(object): if ptop is not None: assert job and ap_data # type: ignore # !rm sz = job["size"] - file_ts = job["lmod"] + file_ts = max(0, job["lmod"]) editions["plain"] = (ap_data, sz) break @@ -6120,7 +6120,7 @@ class HttpCli(object): margin = "-" sz = inf.st_size - zd = datetime.fromtimestamp(linf.st_mtime, UTC) + zd = datetime.fromtimestamp(max(0, linf.st_mtime), UTC) dt = "%04d-%02d-%02d %02d:%02d:%02d" % ( zd.year, zd.month, diff --git a/copyparty/tftpd.py b/copyparty/tftpd.py index 1ed2b6f4..d8e06755 100644 --- a/copyparty/tftpd.py +++ b/copyparty/tftpd.py @@ -284,6 +284,7 @@ class Tftpd(object): if not ptn or not ptn.match(fn.lower()): return None + tsdt = datetime.fromtimestamp vn, rem = self.asrv.vfs.get(vpath, "*", True, False) fsroot, vfs_ls, vfs_virt = vn.ls( rem, @@ -296,7 +297,7 @@ class Tftpd(object): dirs1 = [(v.st_mtime, v.st_size, k + "/") for k, v in vfs_ls if k in dnames] fils1 = [(v.st_mtime, v.st_size, k) for k, v in vfs_ls if k not in dnames] real1 = dirs1 + fils1 - realt = [(datetime.fromtimestamp(mt, UTC), sz, fn) for mt, sz, fn in real1] + realt = [(tsdt(max(0, mt), UTC), sz, fn) for mt, sz, fn in real1] reals = [ ( "%04d-%02d-%02d %02d:%02d:%02d"