From 6c472241d128fd95e6e96645f68cc35946406f91 Mon Sep 17 00:00:00 2001 From: SRHTNIN Date: Fri, 9 Oct 2026 10:52:58 +0200 Subject: [PATCH] Tester: files still downloading are skipped, like SaraSortd 7.4 Co-Authored-By: Claude Opus 5.5 --- Sortd.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Sortd.py b/Sortd.py index 05e786f..b50d2fe 100644 --- a/Sortd.py +++ b/Sortd.py @@ -59,6 +59,17 @@ def GetConf(Parameter: str, Data: dict) -> Any: return None +PartialDownloadSuffixes = (".part", ".crdownload", ".download") + + +def IsPartialDownload(FilePath: str) -> bool: + """SaraSortd 7.4's IsPartialDownload: still downloading (Firefox, Chromium, + Safari), or a file next to its own unfinished download.""" + if os.path.basename(FilePath).lower().endswith(PartialDownloadSuffixes): + return True + return any(os.path.exists(FilePath + Suffix) for Suffix in PartialDownloadSuffixes) + + def IsCatchAll(Pattern: str) -> bool: """SaraSortd 7.3's IsCatchAll: a pattern of only "*" takes any file, so it's a fallback.""" return Pattern != "" and set(Pattern) == {"*"} @@ -740,6 +751,9 @@ class Setup: """Follows Main() and DecideNewPath() for one file, without touching anything (NextNum/NextChar aren't incremented).""" Steps: list[str] = [] + if IsPartialDownload(f"{InputPath}/{FileName}"): + return SimulationResult(["It's still downloading (.part, .crdownload or .download), so SaraSortd leaves it " + "alone until the download finishes."], None, "Skipped") if FileName.startswith(".") and self.Data.get("DotFiles", 0) == 0: return SimulationResult(["Dot files are skipped (DotFiles = 0)."], None, "Skipped") InConf = self.LoadDirConf(InputPath, "In") @@ -887,9 +901,12 @@ class Setup: else: Found.append(("Error", f"{OutputPath}: [[Files]] #{Position + 1} has no {Missing}; SaraSortd will crash on it.")) if Daemon and not VersionAtLeast(Daemon, (7, 3)): - Found.append(("Warning", f"SaraSort shows how SaraSortd 7.3 sorts, and SaraSortd {Daemon} differs: a catch-all (\"*\") " - "output listed first takes every file, nested %Name%s don't resolve, and ! & @ ~ ^ in " - "paths get swapped. Update SaraSortd to 7.3.")) + Found.append(("Warning", f"SaraSort shows how SaraSortd 7.4 sorts, and SaraSortd {Daemon} differs: a catch-all (\"*\") " + "output listed first takes every file, nested %Name%s don't resolve, ! & @ ~ ^ in " + "paths get swapped, and files still downloading get sorted. Update SaraSortd to 7.4.")) + elif Daemon and not VersionAtLeast(Daemon, (7, 4)): + Found.append(("Warning", f"SaraSortd {Daemon} sorts files that are still downloading (.part, .crdownload, " + ".download). Update SaraSortd to 7.4.")) Central = self.CentralFolder() if (Central or self.Data.get("DirConfs")) and Daemon and not VersionAtLeast(Daemon, (7, 2)): Found.append(("Error", f"Directory configs are kept outside their directories (DirConfDir / [DirConfs]), "