From aa3a9719619de36b06abab5582b112343b2849f5 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 17 Jan 2024 23:32:37 +0000 Subject: [PATCH] windows: safeguard against parallel deletes st_ino is valid for NTFS on python3, good enough --- copyparty/util.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/copyparty/util.py b/copyparty/util.py index 6fd009e8..546f63ce 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -2092,9 +2092,13 @@ def wunlink(log: "NamedLogger", abspath: str, flags: dict[str, Any]) -> bool: if chill < 0.001: chill = 0.1 + ino = 0 t0 = now = time.time() for attempt in range(90210): try: + if ino and os.stat(bpath).st_ino != ino: + log("inode changed; aborting delete") + return False os.unlink(bpath) if attempt: now = time.time() @@ -2108,6 +2112,8 @@ def wunlink(log: "NamedLogger", abspath: str, flags: dict[str, Any]) -> bool: if now - t0 > maxtime or attempt == 90209: raise if not attempt: + if not PY2: + ino = os.stat(bpath).st_ino t = "delete failed (err.%d); retrying for %d sec: %s" log(t % (ex.errno, maxtime + 0.99, abspath))