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
@@ -212,7 +212,7 @@ public static class RenamePlanner
|
||||
if (folder is not null && s.Folder.Length > 0 && Blank(folder.ExpandFolder(context with { Title = newTitle })) is { } expanded
|
||||
&& !expanded.Equals(s.Folder, StringComparison.Ordinal))
|
||||
{
|
||||
newFolder = expanded.Equals(s.Folder, StringComparison.OrdinalIgnoreCase) ? expanded : Unique(expanded, claimed, existsOnDisk);
|
||||
newFolder = Kept(s.Folder, expanded, taken) ?? Unique(expanded, claimed, existsOnDisk);
|
||||
claimed.Add(newFolder);
|
||||
}
|
||||
var step = new RenameStep(s.SequenceId, s.Folder, newFolder, s.Title, newTitle);
|
||||
@@ -299,6 +299,26 @@ public static class RenamePlanner
|
||||
|
||||
private static string? Blank(string value) => string.IsNullOrWhiteSpace(value) ? null : value;
|
||||
|
||||
/// <summary>
|
||||
/// The folder a sequence keeps (in the template's case) when it already is <paramref name="expanded"/>, or the
|
||||
/// <c>" (n)"</c> of it that filing or an earlier Reorganize gave it beside another sequence of that name; null when it is
|
||||
/// neither, or when another sequence holds that name exactly (a case-sensitive file system). Without it a sequence at
|
||||
/// <c>2026-09-28 (2)</c> would be planned to <c>(3)</c>, its own folder being taken, and back to <c>(2)</c> by the
|
||||
/// next Reorganize.
|
||||
/// </summary>
|
||||
private static string? Kept(string current, string expanded, IReadOnlyList<string> occupied)
|
||||
{
|
||||
string? same = null;
|
||||
if (current.Equals(expanded, StringComparison.OrdinalIgnoreCase)) same = expanded;
|
||||
else if (current.Length > expanded.Length + 3 && current.StartsWith(expanded + " (", StringComparison.OrdinalIgnoreCase) && current[^1] == ')'
|
||||
&& int.TryParse(current.AsSpan(expanded.Length + 2, current.Length - expanded.Length - 3), NumberStyles.None, CultureInfo.InvariantCulture,
|
||||
out var n) && n >= 2)
|
||||
same = string.Create(CultureInfo.InvariantCulture, $"{expanded} ({n})");
|
||||
// "(02)" is not a number Unique gives: that folder moves to a name of its own.
|
||||
if (same is null || !same.Equals(current, StringComparison.OrdinalIgnoreCase)) return null;
|
||||
return same.Equals(current, StringComparison.Ordinal) || !occupied.Any(o => o.Equals(same, StringComparison.Ordinal)) ? same : null;
|
||||
}
|
||||
|
||||
private static string Unique(string folder, HashSet<string> claimed, Func<string, bool> existsOnDisk)
|
||||
{
|
||||
var candidate = folder;
|
||||
|
||||
Reference in new issue
Block a user