fix: keep pre-rule templates through web settings saves; retry render filing after another index moved the folder
The web panel's archive settings save checked both request templates against every template rule before the engine ran, so an archive.json saved before the rules made every save fail, even of the name or proxy size. Only a template that differs from the stored one is now held to the rules, as ArchiveService already does, and a TemplateRuleException from the engine (archive.json changed since the form was read) answers invalid_template with its rule instead of archive_policy. Exports follow a moved folder correctly in two more cases. Image-sequence exports are folders, so the rebase now tests Path.Exists instead of File.Exists. An export left at the old path no longer pins a sequence's row when that path now belongs to another sequence (its sidecar holds the old folder, or its render row names the path); the row follows to the new path, so it never names another sequence's file. RenderStore throws FolderMovedException when the sequence is not in the folder the index has. That is transient until this index's next scan, so client render uploads and render-node results now answer 503 folder_moved, keep the part file and the node's job, instead of failing them for good with a wrong reason. Save both and Take server refused because the folder moved now say Errors.Archive.FolderMoved (try again after the next scan) instead of the "changed again, choose again" sentence, which repeated until a scan. Doc wording: the ReorganizeDialogViewModel summary covers a sequence kept whole, and RenamePlanner.Plan's existsExactly says the own folder is found under at most one of the two names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit d898798657197d48f4e19b7f776003eb2fc441b5)
This commit is contained in:
1 parent
d0da224de5
commit
964b996af2
21 files changed
+239
-46
No files matched your search
@@ -187,25 +187,34 @@ public sealed class ArchiveIndexer
|
||||
|
||||
/// <summary>
|
||||
/// The render rows of the archive that follow a sequence's folder from <paramref name="from"/> to <paramref name="to"/>,
|
||||
/// in the caller's transaction (<see cref="Repositories.RenderRepository.RebaseFolderAsync"/>). A file is at its old path
|
||||
/// still when it is there and the new path is not the same file (on a file system that ignores case it is, when only the
|
||||
/// case changed). The sequence's own exports inside the folder follow unless their file is at the old path still and not
|
||||
/// at the new one: written there after the move by a writer that read the old folder, which created it again, so the row
|
||||
/// keeps naming where the file is. Another sequence's export follows only when its file moved with the folder (at its new
|
||||
/// path and no longer at the old one). An export missing from both places follows if it is the sequence's own.
|
||||
/// in the caller's transaction (<see cref="Repositories.RenderRepository.RebaseFolderAsync"/>). An export is a file, or
|
||||
/// a folder for an image sequence. It is at its old path still when it is there, the new path is not the same one (on a
|
||||
/// file system that ignores case it is, when only the case changed) and the old folder holds no other sequence now. The
|
||||
/// sequence's own exports inside the folder follow unless they are at the old path still and not at the new one:
|
||||
/// written there after the move by a writer that read the old folder, which created it again, so the row keeps naming
|
||||
/// where the export is. Another sequence's export follows only when it moved with the folder (at its new path and no
|
||||
/// longer at the old one). An export missing from both places follows if it is the sequence's own, and so does one whose
|
||||
/// old path is another sequence's: a sequence that moved into the old folder since brought an export of that name.
|
||||
/// </summary>
|
||||
internal static Task<int> RebaseRendersAsync(ChronosRepositories tx, Archive archive, Guid sequenceId, string from, string to,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var paths = new ArchivePaths(archive.RootPath);
|
||||
// Read once, and only for an export found at its old path.
|
||||
bool? taken = null;
|
||||
return tx.Renders.RebaseFolderAsync(archive.Id, sequenceId, from, to, (before, after, own) =>
|
||||
{
|
||||
var moved = File.Exists(paths.FromRelative(after));
|
||||
var behind = !string.Equals(before, after, StringComparison.OrdinalIgnoreCase) && File.Exists(paths.FromRelative(before));
|
||||
var moved = Path.Exists(paths.FromRelative(after));
|
||||
var behind = !string.Equals(before, after, StringComparison.OrdinalIgnoreCase) && Path.Exists(paths.FromRelative(before))
|
||||
&& !(taken ??= TakenByAnother(paths.Sequence(from), sequenceId));
|
||||
return own ? moved || !behind : moved && !behind;
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>Whether <paramref name="folder"/> is another sequence's now: its sidecar names another id.</summary>
|
||||
private static bool TakenByAnother(SequencePaths folder, Guid sequenceId) =>
|
||||
File.Exists(folder.ManifestPath) && SequenceTrash.SidecarId(folder.ManifestPath) is { } id && id != sequenceId;
|
||||
|
||||
/// <summary>
|
||||
/// Remembers the current stamps of a folder whose sidecar and index were just updated together, so the next
|
||||
/// incremental scan does not re-read what is already indexed.
|
||||
|
||||
@@ -511,7 +511,7 @@ public sealed partial class SequenceTrash
|
||||
/// The id a sidecar names, from its head (the id is written second), so checking a 35 MB sidecar does not parse it;
|
||||
/// the whole file is read only when the head does not hold the id. Null when the file is unreadable.
|
||||
/// </summary>
|
||||
private static Guid? SidecarId(string path)
|
||||
internal static Guid? SidecarId(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -52,7 +52,9 @@ public sealed class RenderRepository
|
||||
/// <paramref name="follows"/> the folder takes the new path: the caller tells the sequence's own exports there (which
|
||||
/// follow unless their file stayed behind) from an export of another sequence saved inside it through the Export
|
||||
/// folder picker (which follows only when its file moved with the folder: a sequence that took the old folder since, by
|
||||
/// a later Reorganize another index made, keeps its own). Outputs elsewhere (absolute paths, other folders) stay as they are.
|
||||
/// a later Reorganize another index made, keeps its own). An export of the sequence whose path an export of another
|
||||
/// sequence names follows without asking: that path is the other sequence's now, which brought an export of that name
|
||||
/// into the old folder. Outputs elsewhere (absolute paths, other folders) stay as they are.
|
||||
/// </summary>
|
||||
/// <param name="follows">Whether the render at the first archive-relative path follows to the second one; the third
|
||||
/// argument says whether it is one of the sequence's own.</param>
|
||||
@@ -73,7 +75,9 @@ public sealed class RenderRepository
|
||||
foreach (var (id, owner, path) in under)
|
||||
{
|
||||
var to = newFolder.Length == 0 ? path[prefix.Length..] : newFolder + path[oldFolder.Length..];
|
||||
if (!follows(path, to, owner == sequenceId)) continue;
|
||||
var own = owner == sequenceId;
|
||||
var taken = own && under.Any(o => o.SequenceId != sequenceId && string.Equals(o.Path, path, StringComparison.Ordinal));
|
||||
if (!taken && !follows(path, to, own)) continue;
|
||||
rebased += await _db.ExecuteAsync("UPDATE renders SET output_path = $2 WHERE id = $1", [id, to], cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
return rebased;
|
||||
|
||||
@@ -177,14 +177,16 @@ public sealed class SyncService
|
||||
/// <summary>
|
||||
/// Settles a conflict as the user chose (BRIEF §12.7), against the versions the user was shown: when either side
|
||||
/// changed again since, nothing is written, the sequence is compared again and <see cref="SyncConflictChangedException"/>
|
||||
/// is thrown, as it is when <see cref="SyncResolution.SaveBoth"/> cannot keep this PC's version first (the folder is not
|
||||
/// where the index has it). Returns the file this PC's settings were saved to for <see cref="SyncResolution.SaveBoth"/>,
|
||||
/// else null.
|
||||
/// is thrown, as it is when <see cref="SyncResolution.SaveBoth"/> cannot keep this PC's version first or the server's
|
||||
/// version cannot be written because the folder is not where the index has it (another index moved it; its message then
|
||||
/// says to try again after the next scan). Returns the file this PC's settings were saved to for
|
||||
/// <see cref="SyncResolution.SaveBoth"/>, else null.
|
||||
/// </summary>
|
||||
public async Task<string?> ResolveAsync(ISyncRemote remote, Guid remoteId, SyncResolution resolution, CancellationToken cancellationToken)
|
||||
{
|
||||
string? saved = null;
|
||||
var changed = false;
|
||||
var moved = false;
|
||||
await _gate.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
@@ -229,6 +231,7 @@ public sealed class SyncService
|
||||
// This PC's version could not be kept (another index moved the folder): the server's does not replace it,
|
||||
// even where this index's scan finds the folder before the server's version would be written.
|
||||
changed = true;
|
||||
moved = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -239,8 +242,10 @@ public sealed class SyncService
|
||||
}
|
||||
else
|
||||
{
|
||||
// Edited on this PC since it was read: the copy of a version the user did not choose to keep goes.
|
||||
// Edited on this PC since it was read, or the folder moved by another index: the copy of a version the
|
||||
// user did not choose to keep goes.
|
||||
changed = true;
|
||||
moved = await FolderMovedAsync(local, cancellationToken).ConfigureAwait(false);
|
||||
if (saved is not null) await DeleteCopyAsync(local, saved, cancellationToken).ConfigureAwait(false);
|
||||
saved = null;
|
||||
}
|
||||
@@ -259,7 +264,8 @@ public sealed class SyncService
|
||||
if (changed)
|
||||
{
|
||||
await RefreshSequencesAsync(remote, [remoteId], CompareOnly, cancellationToken).ConfigureAwait(false);
|
||||
throw new SyncConflictChangedException(Loc.L("Errors.Sync.ChangedAgain"));
|
||||
// Choosing again changes nothing while the folder is not where the index has it: the next scan finds it.
|
||||
throw new SyncConflictChangedException(Loc.L(moved ? "Errors.Archive.FolderMoved" : "Errors.Sync.ChangedAgain"));
|
||||
}
|
||||
await StoreStatesAsync(remote.Server, null, cancellationToken).ConfigureAwait(false);
|
||||
Changed?.Invoke(remote.Server);
|
||||
@@ -823,6 +829,19 @@ public sealed class SyncService
|
||||
return path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the sequence is not in the folder the index has for it now, on an archive that is there: another index moved
|
||||
/// it, and this index's next scan finds it. Read without the lease, to tell why a resolution wrote nothing.
|
||||
/// </summary>
|
||||
private async Task<bool> FolderMovedAsync(Sequence local, CancellationToken cancellationToken)
|
||||
{
|
||||
if (await _db.Sequences.GetAsync(local.Id, cancellationToken).ConfigureAwait(false) is not { } row
|
||||
|| await _db.Archives.GetAsync(row.ArchiveId, cancellationToken).ConfigureAwait(false) is not { } archive)
|
||||
return false;
|
||||
var paths = new ArchivePaths(archive.RootPath);
|
||||
return Directory.Exists(paths.Root) && !Directory.Exists(paths.Sequence(row.Folder).Folder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a "Save both" copy of a version the user did not keep from the sequence's folder as the index has it now: a
|
||||
/// Reorganize may have moved the folder, the copy with it, since the copy was written. Best effort: a copy that cannot
|
||||
|
||||
Reference in new issue
Block a user