fix(archive): stable Reorganize folders, settle trash restores first, retranslate Reorganize
Integrating owner review 2 phase 4a (R7) onto the reviewed phase 3 code. - RenamePlanner: a sequence already at its expanded folder, or at the " (n)" of it that filing or an earlier Reorganize gave it, keeps that folder (in the template's case, unless another sequence holds that exact name). The planner seeded its claimed folders with the sequence's own, so "2026-09-28 (2)" was planned to "(3)" and back to "(2)" by the next run; a second Reorganize with the same templates now plans nothing. - MassRenamer: each step settles what a crash or a busy trash entry left in its sequences (SequenceWriter.ReadLocked) and waits, as a sequence deletion does, while a restore from the trash is not settled (FrameTrash.EnsureSettled), before its folder or any file name changes: that restore's journal names files by the names they had. Trash records keep restoring after a Reorganize: into the sequence where it is now, under the record's own name made free (_2) with its companion following. - Jobs.Kind.Move and Admin.Job.Kind.Move now mean "Reorganize": their old "Move archive" translations are removed from the 36 other cultures so they are translated again. - Tests: a second run plans nothing (planner and archive), companions found alike by the trash and Reorganize whatever their case, a photo deleted before a Reorganize comes back beside the new names, a Reorganize waits for a busy restore and settles it first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ad72501f11
commit
950524929c
78 files changed
+183
-75
No files matched your search
@@ -113,7 +113,9 @@ public sealed class MassRenamer
|
||||
/// a sequence the plan does not take along, or the photos of a sequence whose files it renames changed; nothing of that
|
||||
/// step was changed (a step found stale only once its folder moved keeps its folder and title, and its journal has the
|
||||
/// next open complete the rest).</exception>
|
||||
/// <exception cref="IOException">A file could not be renamed (open elsewhere); the step's files went back to their names.</exception>
|
||||
/// <exception cref="IOException">A file could not be renamed (open elsewhere); the step's files went back to their names. Or
|
||||
/// (<see cref="LeaseUnavailableException"/>) a sequence is busy, or holds a restore from the trash whose entry is busy and
|
||||
/// not settled yet; nothing of that step changed.</exception>
|
||||
public Task<RenameResult> ApplyAsync(Archive archive, RenamePlan plan, IProgress<int>? progress = null, CancellationToken cancellationToken = default) =>
|
||||
ApplyAsync(archive, plan, null, progress is null ? null : n =>
|
||||
{
|
||||
@@ -296,6 +298,7 @@ public sealed class MassRenamer
|
||||
result.Dropped.AddRange(follow.Select(c => c.SequenceId));
|
||||
return;
|
||||
}
|
||||
foreach (var s in follow.Prepend(step)) Settle(paths, s);
|
||||
RenamePlanner.MoveFolder(paths, step);
|
||||
// Moved with their carrier: only their sidecars and index rows follow, and the names of their files.
|
||||
foreach (var s in follow.Prepend(step))
|
||||
@@ -312,6 +315,23 @@ public sealed class MassRenamer
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Settles, under the step's leases and before anything of it moves, what a crash or a busy trash entry left in the
|
||||
/// sequence, as every writer does (<see cref="SequenceWriter.ReadLocked"/>): an interrupted rename of its files, photo
|
||||
/// deletion, restore from the trash or ingest. A restore whose trash entry is busy is not settled yet, and the step
|
||||
/// waits for it (<see cref="FrameTrash.EnsureSettled"/>) as a deletion of the sequence does: its journal names the
|
||||
/// files it moved by the names they had, so neither the folder nor those names change under it.
|
||||
/// </summary>
|
||||
/// <exception cref="LeaseUnavailableException">A restore from the trash into the sequence is not settled; nothing of the step changed.</exception>
|
||||
private static void Settle(ArchivePaths paths, RenameStep step)
|
||||
{
|
||||
// Where the sequence is now: its folder moves first, so a resumed step may find it at its new place already.
|
||||
var sequence = paths.Sequence(step.FromFolder);
|
||||
if (step.MovesFolder && !File.Exists(sequence.ManifestPath)) sequence = paths.Sequence(step.ToFolder);
|
||||
SequenceWriter.ReadLocked(sequence, step.SequenceId);
|
||||
FrameTrash.EnsureSettled(sequence);
|
||||
}
|
||||
|
||||
/// <summary>The index still has the step's sequence where the plan says (or where it already took it); otherwise stale.</summary>
|
||||
/// <exception cref="StaleRenamePlanException">Not resuming, and the sequence moved or vanished since the plan was made.</exception>
|
||||
private async Task<bool> StandsAsync(RenameStep step, bool resuming, CancellationToken cancellationToken)
|
||||
|
||||
Reference in new issue
Block a user