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,9 +2,11 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Shell;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Protocol.Client;
|
||||
using Chronos.Testing;
|
||||
@@ -60,4 +62,15 @@ public sealed class ErrorTextTests
|
||||
Assert.Equal("Something went wrong.", ErrorText.For(new IOException(@"Access to the path 'D:\Archive' is denied.")));
|
||||
Assert.Equal(@"The archive D:\Shoots is read-only.", ErrorText.For(new ArchiveOfflineException(@"D:\Shoots", ArchiveAvailability.ReadOnly)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ATemplateAnArchiveRefusesSaysTheRuleItBreaks()
|
||||
{
|
||||
// A new archive with this PC's templates, one saved before the rules existed: the toast says what to change.
|
||||
var refused = new TemplateRuleException("fileTemplate", "NotUnique");
|
||||
const string Sentence = "Names would repeat: add the frame number, the time or the original name.";
|
||||
Assert.Equal(Sentence, ErrorText.For(refused));
|
||||
Assert.Equal(Sentence, ArchiveActions.Cause(refused));
|
||||
Assert.Equal("Something went wrong.", ArchiveActions.Cause(new ArgumentException("The archive setting name is invalid.", "name")));
|
||||
}
|
||||
}
|
||||
@@ -429,6 +429,59 @@ public sealed class ReorganizeTests(TestContext context)
|
||||
Assert.Equal("a", File.ReadAllText(Path.Combine(archive.FromRelative("Trip/day"), "a.txt")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AFolderTheDiskSpellsAsTheTemplateDoesIsTheSequencesOwn()
|
||||
{
|
||||
// A case-insensitive file system: the index has "trip (2)" and "Trip/day", the disk spells them "Trip (2)" (renamed in
|
||||
// Explorer since the last scan) and "trip/day" (an outer level a change of case left as it was). The folders found
|
||||
// under the template's exact names are the sequences' own: a change of case is all the plan makes, never " (n)".
|
||||
var disk = new HashSet<string>(["Trip", "Trip (2)", "trip", "trip/day"], StringComparer.Ordinal);
|
||||
bool OnDisk(string f) => disk.Contains(f, StringComparer.OrdinalIgnoreCase);
|
||||
var renamed = new RenameSubject(Guid.NewGuid(), "trip (2)", "Trip", Start, null, null, null);
|
||||
var plan = RenamePlanner.Plan(Guid.NewGuid(), [renamed], "{title}", null, ["trip (2)", "Trip"], OnDisk, existsExactly: disk.Contains);
|
||||
Assert.Equal("Trip (2)", plan.Steps.Single().ToFolder);
|
||||
var outer = new RenameSubject(Guid.NewGuid(), "Trip/day", "day", Start, null, null, null);
|
||||
plan = RenamePlanner.Plan(Guid.NewGuid(), [outer], "trip/day", null, ["Trip/day"], OnDisk, existsExactly: disk.Contains);
|
||||
Assert.Equal("trip/day", plan.Steps.Single().ToFolder);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ACaseOnlyTargetOnDiskIsRefusedOnlyBesideTheSequencesOwnFolder()
|
||||
{
|
||||
var archive = new ArchivePaths(context.CreateTempDirectory("archive"));
|
||||
foreach (var folder in (string[])["Trip", "Trip (2)", "walk/day"])
|
||||
{
|
||||
Directory.CreateDirectory(archive.FromRelative(folder));
|
||||
File.WriteAllText(Path.Combine(archive.FromRelative(folder), "a.txt"), folder);
|
||||
}
|
||||
// The index has "trip (2)" and "Walk/day": on a case-sensitive file system those are folders of their own beside the
|
||||
// ones the template names.
|
||||
var caseSensitive = !Directory.Exists(archive.FromRelative("trip (2)"));
|
||||
if (caseSensitive)
|
||||
{
|
||||
Directory.CreateDirectory(archive.FromRelative("trip (2)"));
|
||||
Directory.CreateDirectory(archive.FromRelative("Walk/day"));
|
||||
}
|
||||
bool OnDisk(string f) => Directory.Exists(archive.FromRelative(f));
|
||||
bool Exactly(string f) => RenamePlanner.ExistsExactly(archive, f);
|
||||
var renamed = new RenameSubject(Guid.NewGuid(), "trip (2)", "Trip", Start, null, null, null);
|
||||
var outer = new RenameSubject(Guid.NewGuid(), "Walk/day", "day", Start, null, null, null);
|
||||
var first = RenamePlanner.Plan(Guid.NewGuid(), [renamed], "{title}", null, ["trip (2)", "Trip", "Walk/day"], OnDisk, existsExactly: Exactly).Steps.Single();
|
||||
var second = RenamePlanner.Plan(Guid.NewGuid(), [outer], "walk/day", null, ["trip (2)", "Trip", "Walk/day"], OnDisk, existsExactly: Exactly).Steps.Single();
|
||||
if (caseSensitive)
|
||||
{
|
||||
Assert.Equal(("Trip (3)", "walk/day (2)"), (first.ToFolder, second.ToFolder));
|
||||
return;
|
||||
}
|
||||
// Case-insensitive: each sequence keeps its own folder, which is already as the template spells it, so applying the
|
||||
// steps (twice, as a resumed plan does) moves nothing and loses nothing.
|
||||
Assert.Equal(("Trip (2)", "walk/day"), (first.ToFolder, second.ToFolder));
|
||||
foreach (var step in (RenameStep[])[first, second, first, second]) RenamePlanner.MoveFolder(archive, step);
|
||||
Assert.SequenceEqual(["Trip", "Trip (2)", "walk"], Directory.EnumerateDirectories(archive.Root).Select(Path.GetFileName).Order(StringComparer.Ordinal));
|
||||
Assert.Equal("Trip (2)", File.ReadAllText(Path.Combine(archive.FromRelative("Trip (2)"), "a.txt")));
|
||||
Assert.Equal("walk/day", File.ReadAllText(Path.Combine(archive.FromRelative("walk/day"), "a.txt")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhotosOfALongTitleKeepTheirExtension()
|
||||
{
|
||||
|
||||
@@ -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