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:
1 parent
8127373fd5
commit
0377040a19
13 files changed
+193
-31
No files matched your search
@@ -2,6 +2,7 @@ using System.Text.Json.Nodes;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Codecs.Jpeg;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Metadata;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Archiving;
|
||||
@@ -115,6 +116,37 @@ public sealed class ArchiveSettingsTests(TestContext context)
|
||||
Assert.Equal(before, await File.ReadAllTextAsync(fx.Paths.ManifestPath, fx.Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TemplatesSavedBeforeTheRulesNeverFailAnEditOfAnotherSetting()
|
||||
{
|
||||
await using var fx = await ArchiveFixture.CreateAsync(context);
|
||||
// An archive.json of 0.1.0-rc.5 or earlier: both templates break a rule new templates are held to.
|
||||
var manifest = ManifestStore.ReadArchive(fx.Paths.ManifestPath);
|
||||
ManifestStore.WriteArchive(fx.Paths.ManifestPath, manifest with { LayoutTemplates = new LayoutTemplates { Folder = "exports/{date}", File = "{title}" } });
|
||||
|
||||
// The desktop saves one row at a time: each edit keeps the templates it does not change.
|
||||
var proxies = await fx.Service.UpdateSettingsAsync(fx.Archive.Id, s => s with { Proxies = s.Proxies with { LongEdge = 2560 } }, fx.Ct);
|
||||
Assert.Equal(("exports/{date}", "{title}", 2560), (proxies.FolderTemplate, proxies.FileTemplate, proxies.ProxyLongEdge));
|
||||
await fx.Service.UpdateSettingsAsync(fx.Archive.Id, s => s with { Name = "Studio" }, fx.Ct);
|
||||
var folder = await fx.Service.UpdateSettingsAsync(fx.Archive.Id, s => s with { Templates = s.Templates with { Folder = "{year}/{date}" } }, fx.Ct);
|
||||
Assert.Equal(("{year}/{date}", "{title}"), (folder.FolderTemplate, folder.FileTemplate));
|
||||
|
||||
// A template given anew is held to every rule, and the refusal says which.
|
||||
var before = await File.ReadAllTextAsync(fx.Paths.ManifestPath, fx.Ct);
|
||||
var refused = await Assert.ThrowsAsync<TemplateRuleException>(() =>
|
||||
fx.Service.UpdateSettingsAsync(fx.Archive.Id, s => s with { Templates = s.Templates with { File = "{n}{ext}" } }, fx.Ct));
|
||||
Assert.Equal(("fileTemplate", "Extension", Loc.L("Errors.Template.Extension")), (refused.ParamName, refused.Rule, refused.Message));
|
||||
Assert.Equal(before, await File.ReadAllTextAsync(fx.Paths.ManifestPath, fx.Ct));
|
||||
|
||||
var file = await fx.Service.UpdateSettingsAsync(fx.Archive.Id, s => s with { Templates = s.Templates with { File = "{date}_{n:0000}" } }, fx.Ct);
|
||||
Assert.Equal(("Studio", "{year}/{date}", "{date}_{n:0000}", 2560), (file.Name, file.FolderTemplate, file.FileTemplate, file.ProxyLongEdge));
|
||||
|
||||
// A new archive has nothing to keep: its templates meet every rule.
|
||||
var created = await Assert.ThrowsAsync<TemplateRuleException>(() => fx.Service.CreateAsync(context.CreateTempDirectory("other"), "Other",
|
||||
new LayoutTemplates { Folder = "exports/{date}", File = "{date}_{n:0000}" }, null, fx.Ct));
|
||||
Assert.Equal(("folderTemplate", "ReservedFolder"), (created.ParamName, created.Rule));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnOfflineArchiveIsNotChangedAndItsIndexSettingsAreShown()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user