diff --git a/GlobalConf.toml b/GlobalConf.toml index 1898a94..0646441 100644 --- a/GlobalConf.toml +++ b/GlobalConf.toml @@ -1,5 +1,5 @@ Title = "SaraSortd Config" -Version = "7.3" +Version = "7.4" SafeMode = 1 SilentMode = 0 SortTimer = 1 diff --git a/InputDirConf.toml b/InputDirConf.toml index fc6a19c..f29347e 100644 --- a/InputDirConf.toml +++ b/InputDirConf.toml @@ -1,5 +1,5 @@ Title = "Unset" -Version = "7.3" +Version = "7.4" ParentDir = "Unset" SortDirs = 0 diff --git a/OutputDirConf.toml b/OutputDirConf.toml index e240911..a32d84a 100644 --- a/OutputDirConf.toml +++ b/OutputDirConf.toml @@ -1,5 +1,5 @@ Title = "Unset" -Version = "7.3" +Version = "7.4" LastFile = "Unset" ParentDir = "Unset" ValidInputDirs = ["*"] diff --git a/README.md b/README.md index e27ab08..6856564 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ SaraSortd: a file and directory sorting daemon built with python. -(Version = "7.3") +(Version = "7.4") It's made by Sarah, hence the name. :3 @@ -58,7 +58,7 @@ Here's a step-by-step tutorial (in case you don't want to watch the video). ``` Title = "SaraSortd Config" # NOTE: Do not change the title. This is so that the program knows which config file is which. -Version = "7.3" # Just the version number for the config file. +Version = "7.4" # Just the version number for the config file. SafeMode = 1 # If SaraSortd should stop if an error with the config appears. 1 is stop, 0 is continue. @@ -67,6 +67,7 @@ SilentMode = 0 # If SaraSortd should write things it does, to the terminal. SortTimer = 3 # How many seconds it takes for SaraSortd to check input directories for new files to sort. DotFiles = 0 # If SaraSortd should sort files that begin with ".". This is mainly for linux users, since hidden files always have "." in front of them. +# Files that are still downloading are never sorted or even checked (since 7.4): anything ending in .part (Firefox), .crdownload (Chrome and other Chromium browsers) or .download (Safari), and a file next to its own unfinished download (like the empty "video.mp4" Firefox makes beside "video.mp4.part"). They're sorted as usual once the download finishes. Logging = 1 # If SaraSortd's logging system should be active. If this is 0, nothing will be logged into files. @@ -169,7 +170,7 @@ The output directory config references the SaraSortd config (GlobalConf.toml). T ``` Title = "Unset" # NOTE: Do not change the title. This is so that the program knows which config file is which. -Version = "7.3" # The version number of the config. +Version = "7.4" # The version number of the config. LastFile = "Unset" # The last file that was sorted to this directory. It gets automatically updated whenever a file gets sorted to this directory. @@ -225,7 +226,7 @@ Overwrite = 1 # Whether this specific file type can be overwritten by others of ``` Title = "Unset" # NOTE: Do not change the title. This is so that the program knows which config file is which. -Version = "7.3" +Version = "7.4" ParentDir = "Unset" # The name of this directory. It gets automatically updated when this config gets copied to an output directory. diff --git a/SaraSortd.py b/SaraSortd.py index d801bc7..9a77abe 100644 --- a/SaraSortd.py +++ b/SaraSortd.py @@ -6,7 +6,7 @@ import shutil import time import toml -# Version = "7.3" +# Version = "7.4" ConfPath = "./GlobalConf.toml" @@ -393,6 +393,20 @@ def FileInputValid(File, FilePath, ParentName): return False +# Files that are still downloading (since 7.4): Firefox's .part, Chromium's .crdownload and Safari's .download. +# SaraSortd never touches them, not even to check them against patterns. +PartialDownloadSuffixes = (".part", ".crdownload", ".download") + + +def IsPartialDownload(FilePath): + if os.path.basename(FilePath).lower().endswith(PartialDownloadSuffixes): + return True + + # A file next to its own unfinished download, E.G. the empty "video.mp4" Firefox makes beside + # "video.mp4.part" and fills in at the end. Moving it would break the download. + return any(os.path.exists(FilePath + Suffix) for Suffix in PartialDownloadSuffixes) + + def IsCatchAll(Pattern): # A pattern made of only "*" takes any file. return Pattern != "" and set(Pattern) == {"*"} @@ -632,7 +646,7 @@ def Main(): if len(GetConf("Unzip", OutDirConfPath) or []) >= 1: ZipTypes = GetConf("Unzip", OutDirConfPath) for OutputFile in os.listdir(OutputPath): - if OutputFile.startswith("."): + if OutputFile.startswith(".") or IsPartialDownload(f"{OutputPath}/{OutputFile}"): continue for ZipType in ZipTypes: @@ -662,6 +676,9 @@ def Main(): for FileName in os.listdir(InputPath): FilePath = f"{InputPath}/{FileName}" + if IsPartialDownload(FilePath): + continue + if os.path.isdir(FilePath) and InputDirConf.get("SortDirs", 0) == 0: continue