Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
Watch folders on macOS and Linux wait for a paused copy to finish
KnifeLemon91a3115b81fc
diff --git a/src/Filee.Core/Watching/FolderWatcher.cs b/src/Filee.Core/Watching/FolderWatcher.csindex 6d6c420e..2ef23c4d 100644--- a/src/Filee.Core/Watching/FolderWatcher.cs+++ b/src/Filee.Core/Watching/FolderWatcher.cs@@ -1,6 +1,7 @@// Watches one folder (WatchRule) and converts files that arrive in it. Used by the tray app (Settings → Watch folders)// and by "filee watch". A file is converted only once it is complete: it must keep the same size and time for-// SettleTime and open without sharing, so downloads and copies still in progress are left alone. Temporary files,+// SettleTime and open without sharing (on Windows; macOS and Linux don't lock files being written, so there only+// the longer wait and Finder's copy-in-progress date count), so downloads and copies still in progress are left alone. Temporary files,// the output folder and the originals folder are never picked up, so converted files can't loop back in.using System.Collections.Concurrent;@@ -18,8 +19,15 @@ public sealed class FolderWatcher : IAsyncDisposable/// <summary>Converts a batch of complete files and returns the finished job (null when it could not start).</summary>public delegate Task<ConversionJob?> ConvertFiles(IReadOnlyList<string> files, CancellationToken cancellationToken);- /// <summary>Default time a file must stay unchanged before it is converted.</summary>- public static readonly TimeSpan DefaultSettleTime = TimeSpan.FromSeconds(2);+ /// <summary>+ /// Default time a file must stay unchanged before it is converted. Longer on macOS and Linux: there a file+ /// still being written can be opened exclusively all the same, so only the wait tells a paused copy from a+ /// finished one.+ /// </summary>+ public static readonly TimeSpan DefaultSettleTime = TimeSpan.FromSeconds(OperatingSystem.IsWindows() ? 2 : 5);++ /// <summary>The creation date Finder gives a file while it is still copying it (24 January 1984).</summary>+ private static readonly DateTime FinderCopyInProgress = new(1984, 1, 24);private static readonly HashSet<string> TemporaryExtensions = new(StringComparer.OrdinalIgnoreCase){@@ -134,7 +142,7 @@ public sealed class FolderWatcher : IAsyncDisposablecontinue;}_pending[path] = current;- if (now - current.StableSince < _settleTime || !CanOpenExclusively(path))+ if (now - current.StableSince < _settleTime || !CanOpenExclusively(path) || IsBeingCopiedByFinder(path))continue;_pending.TryRemove(path, out _);// A file that was converted before (same size and time) is not converted again.@@ -225,6 +233,20 @@ public sealed class FolderWatcher : IAsyncDisposable}/// <summary>A writer still holding the file (download, copy) makes an exclusive open fail.</summary>+ private static bool IsBeingCopiedByFinder(string path)+ {+ if (!OperatingSystem.IsMacOS())+ return false;+ try+ {+ return File.GetCreationTime(path).Date == FinderCopyInProgress;+ }+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)+ {+ return true;+ }+ }+private static bool CanOpenExclusively(string path){try