fix(archive): Reorganize never plans a move onto a folder of the exact name, keeps long names' extensions, says why a template is refused
Second fix round of owner review 2, phase 4a (planner findings).
- A sequence keeps a folder that differs from its own in case only while no
other folder holds that exact name (RenamePlanner.ExistsExactly, every level
compared exactly). On a case-sensitive file system a stray "Trip (2)" beside
the sequence at "trip (2)" no longer gives a case-only step that MoveFolder
refuses at every archive open: the plan gives "Trip", and a plan whose
target appeared since is refused under the step's leases before anything
moves (or dropped when it resumes). A change of case in an outer level no
longer looks like two folders on Windows.
- A file name longer than 200 characters is shortened before the ".{ext}" the
template ends with, never through it, so a long title never strips the
photo's extension.
- The archive engine's own settings check applies the template rules the
server and the desktop apply (a folder scans skip, a lost extension, names
that repeat), so archive.json can no longer take such a template.
- The server's invalid_template answer names the rule after the field
("fileTemplate:extension") with the desktop's sentence as its message; both
admin panels show it on the field.
- FrameNaming keeps only the naming overloads production uses.
- Comments about Unreadable say the whole sequence stays as it is.
- Tests pin filing against Reorganize: an upload without a capture time, a
card's second session with {session}, a duplicate skipped mid-session, and a
whole folder of two cameras named with the first one's camera.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 50fe59aec1e180daa1733bcb951892a79dceba6c)
This commit is contained in:
1 parent
9e1f109b58
commit
765f0ad36b
20 files changed
+446
-141
No files matched your search
@@ -175,17 +175,21 @@ public sealed class AdminTests(TestContext context)
|
||||
|
||||
using (var bad = await admin.PutAsJsonAsync("/api/v1/archive/settings", archive with { FolderTemplate = "{year/{date" }, ProtocolJson.Default.ArchiveSettingsDto))
|
||||
Assert.Equal("folderTemplate", (await bad.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_template")).Details);
|
||||
// Templates that would hide sequences from scans, drop extensions or repeat names: refused as Reorganize refuses them.
|
||||
foreach (var (refused, field) in new[]
|
||||
// Templates that would hide sequences from scans, drop extensions or repeat names: refused as Reorganize refuses them,
|
||||
// with the rule after the field and the message saying why, as the desktop does.
|
||||
foreach (var (refused, details, rule) in new[]
|
||||
{
|
||||
(archive with { FolderTemplate = "Originals/{year}" }, "folderTemplate"),
|
||||
(archive with { FileTemplate = "{n}{ext}" }, "fileTemplate"),
|
||||
(archive with { FileTemplate = "{date}" }, "fileTemplate"),
|
||||
(archive with { FileTemplate = " " }, "fileTemplate"),
|
||||
(archive with { FolderTemplate = "Originals/{year}" }, "folderTemplate:reserved_folder", "ReservedFolder"),
|
||||
(archive with { FileTemplate = "{n}{ext}" }, "fileTemplate:extension", "Extension"),
|
||||
(archive with { FileTemplate = "{date}" }, "fileTemplate:not_unique", "NotUnique"),
|
||||
(archive with { FileTemplate = " " }, "fileTemplate", (string?)null),
|
||||
})
|
||||
{
|
||||
using var response = await admin.PutAsJsonAsync("/api/v1/archive/settings", refused, ProtocolJson.Default.ArchiveSettingsDto);
|
||||
Assert.Equal(field, (await response.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_template")).Details);
|
||||
var error = await response.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_template");
|
||||
Assert.Equal(details, error.Details);
|
||||
Assert.Equal(Chronos.Core.Localization.Loc.Get(rule is null ? "Server.Error.InvalidTemplate" : "Errors.Template." + rule,
|
||||
System.Globalization.CultureInfo.GetCultureInfo("en")), error.Message);
|
||||
}
|
||||
using (var good = await admin.PutAsJsonAsync("/api/v1/archive/settings", archive with { Name = "Studio", ProxyLongEdge = 2560 }, ProtocolJson.Default.ArchiveSettingsDto))
|
||||
{
|
||||
|
||||
@@ -147,17 +147,21 @@ public sealed class ReorganizeTests(TestContext context)
|
||||
}
|
||||
using (var template = await admin.PostAsJsonAsync(Url, valid with { FileTemplate = "{nope}" }, ProtocolJson.Default.ReorganizeRequest))
|
||||
Assert.Equal("fileTemplate", (await template.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_template")).Details);
|
||||
// The desktop's rules: no lost extension, names that tell the photos apart, no folder scans skip.
|
||||
foreach (var (bad, field) in new[]
|
||||
// The desktop's rules: no lost extension, names that tell the photos apart, no folder scans skip; each named after the
|
||||
// field, with the desktop's sentence.
|
||||
foreach (var (bad, details, rule) in new[]
|
||||
{
|
||||
(valid with { FileTemplate = "{n}{ext}" }, "fileTemplate"),
|
||||
(valid with { FileTemplate = "{title}" }, "fileTemplate"),
|
||||
(valid with { FolderTemplate = "Exports/{title}" }, "folderTemplate"),
|
||||
(valid with { FolderTemplate = ".hidden/{date}" }, "folderTemplate"),
|
||||
(valid with { FileTemplate = "{n}{ext}" }, "fileTemplate:extension", "Extension"),
|
||||
(valid with { FileTemplate = "{title}" }, "fileTemplate:not_unique", "NotUnique"),
|
||||
(valid with { FileTemplate = "{year}/{n}" }, "fileTemplate:file_separator", "FileSeparator"),
|
||||
(valid with { FolderTemplate = "Exports/{title}" }, "folderTemplate:reserved_folder", "ReservedFolder"),
|
||||
(valid with { FolderTemplate = ".hidden/{date}" }, "folderTemplate:reserved_folder", "ReservedFolder"),
|
||||
})
|
||||
{
|
||||
using var refused = await admin.PostAsJsonAsync(Url, bad, ProtocolJson.Default.ReorganizeRequest);
|
||||
Assert.Equal(field, (await refused.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_template")).Details);
|
||||
var error = await refused.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_template");
|
||||
Assert.Equal(details, error.Details);
|
||||
Assert.Equal(Chronos.Core.Localization.Loc.Get("Errors.Template." + rule, System.Globalization.CultureInfo.GetCultureInfo("en")), error.Message);
|
||||
}
|
||||
using (var blank = await admin.PostAsJsonAsync(Url, valid with { FolderTemplate = " " }, ProtocolJson.Default.ReorganizeRequest))
|
||||
Assert.Equal("folderTemplate", (await blank.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_template")).Details);
|
||||
|
||||
@@ -126,6 +126,13 @@ public sealed partial class AdminReorganizeTests(TestContext context)
|
||||
Assert.Equal("fileTemplate", error.Details);
|
||||
Assert.Equal(Loc.Get("Server.Error.InvalidTemplate", CultureInfo.GetCultureInfo("it")), error.Message);
|
||||
}
|
||||
// One that breaks a rule says why: the dialog shows the sentence on that field.
|
||||
using (var lost = await browser.SendAsync(HttpMethod.Post, Url, Json("""{"all":true,"fileTemplate":"{n}{ext}","dryRun":true}""")))
|
||||
{
|
||||
var error = await lost.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_template");
|
||||
Assert.Equal("fileTemplate:extension", error.Details);
|
||||
Assert.Equal(Loc.Get("Errors.Template.Extension", CultureInfo.GetCultureInfo("it")), error.Message);
|
||||
}
|
||||
// A plan that no longer matches is refused with the one there is now: the dialog plans again.
|
||||
using (var stale = await browser.SendAsync(HttpMethod.Post, Url, Body($"\"dryRun\":false,\"fingerprint\":\"{new string('0', 64)}\"")))
|
||||
Assert.Equal(fingerprint, (await stale.ExpectErrorAsync(HttpStatusCode.Conflict, "plan_changed")).Details);
|
||||
|
||||
Reference in new issue
Block a user