Files
Chronos/src/Titano.Data/Processing/OutputNames.cs
T
Claude c7ca1ef463 fix(processing): concurrent renders keep their own names; analysis status under the lock; server announces changes
A render reserves the output name it picks, so the same preset queued twice
no longer overwrites one output with the other; render rows take ids from
their job and entry, so a resumed job recognises only its own outputs and
never deletes another render's file. A light pass records its status under
the sequence lock and cannot clear a deep pass's. Renders and Auto value
changes made by the server engine publish sequenceChanged events.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-02 23:16:23 +00:00

56 lines
1.9 KiB
C#

using System.Collections.Concurrent;
namespace Titano.Data.Processing;
/// <summary>
/// The output paths the renders of this process are writing. Encoders write to a hidden temporary file and rename it over
/// the output when they finish, so two renders that picked the same free name (the same preset queued twice) would
/// overwrite each other: a render reserves each name it picks until it ends.
/// </summary>
internal sealed class OutputNames : IDisposable
{
private static readonly ConcurrentDictionary<string, byte> Writing = new(StringComparer.OrdinalIgnoreCase);
private readonly List<string> _mine = [];
/// <summary>A path from <paramref name="pick"/>, given the test for paths other renders are writing, reserved for this render.</summary>
public string Reserve(Func<Func<string, bool>, string> pick)
{
while (true)
{
var path = pick(p => Writing.ContainsKey(Key(p)));
// Another render may have taken the same name since: pick again.
if (TryReserve(path)) return path;
}
}
/// <summary>Reserves <paramref name="path"/> for this render; false when another render is writing it.</summary>
public bool TryReserve(string path)
{
var key = Key(path);
if (!Writing.TryAdd(key, 0)) return false;
lock (_mine) _mine.Add(key);
return true;
}
/// <summary>Gives back a path this render reserved, so it can be picked again.</summary>
public void Release(string path)
{
var key = Key(path);
lock (_mine)
{
if (_mine.Remove(key)) Writing.TryRemove(key, out _);
}
}
public void Dispose()
{
lock (_mine)
{
foreach (var key in _mine) Writing.TryRemove(key, out _);
_mine.Clear();
}
}
private static string Key(string path) => Path.GetFullPath(path);
}