Skip to content

armgit / Filee

Public Imported from GitHub
0

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.

Fix job queue busy counter, progress dilution, and watch folder cache limits

gtxPrime0afcc1ed5442
diff --git a/src/Filee.Core/Conversion/ConversionJob.cs b/src/Filee.Core/Conversion/ConversionJob.cs
index fcd1f06c..f14c218e 100644
--- a/src/Filee.Core/Conversion/ConversionJob.cs
+++ b/src/Filee.Core/Conversion/ConversionJob.cs
@@ -66,8 +66,18 @@ public sealed class ConversionJob
public IReadOnlyList<FileResult> Files { get; }
public JobState State { get; internal set; } = JobState.Queued;
- /// <summary>Overall progress 0..1.</summary>
- public double Progress => Files.Count == 0 ? 1 : Files.Average(f => f.Progress);
+ /// <summary>Overall progress 0..1: counts completed files as full and sums partial progress of running ones,
+ /// so files still waiting at 0 don't dilute the displayed percentage.</summary>
+ public double Progress
+ {
+ get
+ {
+ if (Files.Count == 0) return 1;
+ var done = Files.Count(f => f.State is FileState.Done or FileState.Skipped or FileState.Failed or FileState.Cancelled);
+ var partialSum = Files.Where(f => f.State == FileState.Running).Sum(f => f.Progress);
+ return (done + partialSum) / Files.Count;
+ }
+ }
/// <summary>Every file written by the job.</summary>
public IEnumerable<string> Outputs => Files.SelectMany(f => f.Outputs);
diff --git a/src/Filee.Core/Conversion/JobQueue.cs b/src/Filee.Core/Conversion/JobQueue.cs
index 7230fb5a..7d866c70 100644
--- a/src/Filee.Core/Conversion/JobQueue.cs
+++ b/src/Filee.Core/Conversion/JobQueue.cs
@@ -514,6 +514,9 @@ public sealed class JobQueue : IAsyncDisposable
{
await foreach (var job in _channel.Reader.ReadAllAsync())
{
+ // NOTE: _busy was incremented by Enqueue before the job was written to the channel.
+ // Do NOT call RunAsync here — it has its own increment/decrement for external callers
+ // (tests, CLI). Calling it would double-increment and triple-decrement _busy.
try
{
if (job.CancellationToken.IsCancellationRequested)
@@ -523,7 +526,7 @@ public sealed class JobQueue : IAsyncDisposable
JobFinished?.Invoke(this, job);
continue;
}
- await RunAsync(job);
+ await RunJobAsync(job);
}
finally
{
diff --git a/src/Filee.Core/Watching/FileNameFilter.cs b/src/Filee.Core/Watching/FileNameFilter.cs
index f91f9275..bdd032ea 100644
--- a/src/Filee.Core/Watching/FileNameFilter.cs
+++ b/src/Filee.Core/Watching/FileNameFilter.cs
@@ -60,6 +60,8 @@ public sealed class FileNameFilter
{
if (patterns is null || patterns.Count == 0)
return All;
+ if (Cache.Count > 256)
+ Cache.Clear();
return Cache.GetOrAdd(string.Join('\n', patterns), _ =>
{
var regexes = new List<Regex>();
diff --git a/src/Filee.Core/Watching/FolderWatcher.cs b/src/Filee.Core/Watching/FolderWatcher.cs
index 86149b4c..6c6df318 100644
--- a/src/Filee.Core/Watching/FolderWatcher.cs
+++ b/src/Filee.Core/Watching/FolderWatcher.cs
@@ -146,6 +146,8 @@ public sealed class FolderWatcher : IAsyncDisposable
continue;
_pending.TryRemove(path, out _);
// A file that was converted before (same size and time) is not converted again.
+ if (_handled.Count > 10_000)
+ _handled.Clear();
if (_handled.Add(current.Key(path)))
ready.Add(path);
}
@@ -230,9 +232,23 @@ public sealed class FolderWatcher : IAsyncDisposable
Directory.CreateDirectory(Path.GetDirectoryName(target)!);
var name = Path.GetFileNameWithoutExtension(target);
var extension = Path.GetExtension(target);
- for (var n = 2; File.Exists(target); n++)
- target = Path.Combine(Path.GetDirectoryName(target)!, $"{name} ({n}){extension}");
- File.Move(source, target);
+ for (var n = 2; ; n++)
+ {
+ if (File.Exists(target))
+ {
+ target = Path.Combine(Path.GetDirectoryName(target)!, $"{name} ({n}){extension}");
+ continue;
+ }
+ try
+ {
+ File.Move(source, target);
+ break;
+ }
+ catch (IOException) when (File.Exists(target) && n < 100)
+ {
+ target = Path.Combine(Path.GetDirectoryName(target)!, $"{name} ({n}){extension}");
+ }
+ }
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{