fix(archive): a case-only target that is the sequence's own folder is kept; stored templates never fail other edits

Reorganize refused a case-only folder target whenever a folder of that exact
name was on disk. On a case-insensitive file system that folder can be the
sequence's own, when the disk spells it as the template does and the index
does not (renamed in Explorer, or an outer level a change of case left as it
was), so the plan gave a needless " (n)" folder. RenamePlanner.Kept now
refuses only when both exact names exist, the condition MassRenamer.TargetTaken
and MoveFolder already use.

ArchiveSettings.Problem held both templates to the template rules on every
UpdateSettingsAsync, so an archive.json saved before the rules made every
desktop Settings > Archive edit fail. A template the file already holds is now
only checked for being usable; a template the edit gives, and both templates
of a new archive, meet every rule. A broken rule throws TemplateRuleException
(an ArgumentException naming the field), and the desktop toast shows that
rule's sentence instead of "Something went wrong".

Also corrects comments that ignored RenameBlock.Unreadable (the whole
sequence stays as it is) and the ARCHITECTURE Naming row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit ac7a0c36df83b6d43651caf0225c530466242c97)
This commit is contained in:
Alby96 committed 2026-10-27 19:16:27 +01:00
1 parent 8127373fd5
commit 0377040a19
13 files changed
+193 -31

No files matched your search

+4 -1
View File
@@ -27,7 +27,10 @@ public enum RenameBlock
Unreadable,
}
/// <summary>Frames of a sequence that keep their names, and why.</summary>
/// <summary>
/// Frames of a sequence that keep their names, and why; or, for <see cref="RenameBlock.Unreadable"/> (0 frames), why the
/// whole sequence stays as it is.
/// </summary>
public sealed record RenameBlocked(RenameBlock Reason, int Frames);
/// <summary>
+14 -9
View File
@@ -91,8 +91,8 @@ public sealed record RenameTemplates(string? Folder = null, string? File = null,
/// <c>titleTemplate</c>): blank, not valid (<see cref="PathTemplate.IsValid"/>), with a format a sample cannot be written
/// with (<c>{date:%}</c>), expanding to nothing, or, for a folder or file template, breaking a rule of the archive's
/// templates (<see cref="TemplateRules"/>: a folder scans never enter; a slash, a lost extension or names that would
/// repeat); null when every one given can. The archive settings' templates are checked alike
/// (<c>ArchiveSettings.Problem</c>).
/// repeat); null when every one given can. The archive settings' templates are checked alike, except for the rules a
/// template <c>archive.json</c> already holds breaks (<c>ArchiveSettings.Problem</c>).
/// </summary>
public string? Problem() => Check()?.Field;
@@ -259,7 +259,8 @@ public static class RenamePlanner
/// <param name="nested">The archive's other sequences inside a subject's folder, with their titles.</param>
/// <param name="existsExactly">Whether a folder of exactly that name, in every level's case, is on disk
/// (<see cref="ExistsExactly"/>): on a case-sensitive file system <c>Trip (2)</c> beside a sequence at <c>trip (2)</c> is
/// another folder, which a change of case could never move onto. Null when no folder but the sequences' own counts.</param>
/// another folder, which a change of case could never move onto; on a case-insensitive one only the sequence's own
/// folder is found, under one of the two names. Null when no folder but the sequences' own counts.</param>
/// <exception cref="NestedRenameException">A target lies inside a sequence's folder, or inside another target.</exception>
public static RenamePlan Plan(Guid archiveId, IReadOnlyList<RenameSubject> subjects, string? folderTemplate, string? titleTemplate,
IEnumerable<string> occupied, Func<string, bool> existsOnDisk, IReadOnlyList<RenameSubject>? nested = null, string? fileTemplate = null,
@@ -504,11 +505,12 @@ public static class RenamePlanner
/// <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, when another folder holds that name exactly (a sequence's, or any on a case-sensitive file system:
/// <paramref name="existsExactly"/>), which the change of case could never move onto, or when this plan already gave it
/// to another sequence (<paramref name="given"/>, whatever its case: <c>trip (2)</c> and <c>TRIP (2)</c> both keep
/// <c>Trip (2)</c> otherwise). 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.
/// neither, when another folder holds that name exactly (a sequence's, or one on disk beside the sequence's own folder,
/// on a case-sensitive file system: <paramref name="existsExactly"/> finds both names), which the change of case could
/// never move onto, or when this plan already gave it to another sequence (<paramref name="given"/>, whatever its case:
/// <c>trip (2)</c> and <c>TRIP (2)</c> both keep <c>Trip (2)</c> otherwise). 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, IReadOnlySet<string> given, Func<string, bool> existsExactly)
{
@@ -518,7 +520,10 @@ public static class RenamePlanner
// "(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) || given.Contains(same)) return null;
if (same.Equals(current, StringComparison.Ordinal)) return same;
return occupied.Any(o => o.Equals(same, StringComparison.Ordinal)) || existsExactly(same) ? null : same;
// The new name on disk is another folder only while the sequence's own is there under the index's name too, as
// MoveFolder throws: on a case-insensitive file system the disk may spell the sequence's own folder as the template
// does (renamed in Explorer, or an outer level a change of case left as it was), and that folder is no other.
return occupied.Any(o => o.Equals(same, StringComparison.Ordinal)) || (existsExactly(same) && existsExactly(current)) ? null : same;
}
private static string Unique(string folder, HashSet<string> claimed, Func<string, bool> existsOnDisk)