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
@@ -42,7 +42,7 @@ Dependencies point one way: `Core` ← `Core.Windows`, `Data`, `Protocol` ← `S
|
||||
| `Video` (+ `Mp4`, `Avi`, `Bitstream`, `Yuv`, `Managed`) | `IVideoEncoderProvider`, MP4 muxer and inspector, AVI-MJPEG, NV12/P010, managed encoders (MJPEG-AVI, GIF, APNG, image sequences) |
|
||||
| `Archiving` | Archive layout and paths, sidecars (`sequence.json`, `project.json`), scanner, index snapshot, leases, thumbnail packs, verify, adopt, rename plans (`RenamePlanner`: folder, title and file templates, `RenameTemplates`, the plan's fingerprint, which pins every file rename by its digest and not the frames version; `FileRenames`: a sequence's new file names; `FileRenameJournal`: two-phase renames through temporary names, `.chronos/rename-files.json`, a recovery safe to run again from wherever it stopped, a new name taken meanwhile sending that photo and its companions back together to their old names or a free `_2`, those that took their new names already with them; `FrameCompanions`: the XMP files that follow a photo, one rule for the trash and Reorganize, matched whatever their case and each folder listed once by `FrameCompanions.Index`) |
|
||||
| `Import` | Card scan, session detection, import plan, hash-verified copy, card eraser (re-hash before delete) |
|
||||
| `Naming` | Folder/file templates and tokens (folder levels scans skip escaped with `_`; `ExpandText` for titles); `FrameNaming` (the naming context and unique file name of a frame, shared by import, upload and Reorganize: the sequence's camera and lens, the first frame for folders; `UniqueNames`: `_2`, `_3`… in linear time); `TemplateRules` (what every place a template is typed or sent refuses, the archive engine's settings included: a folder scans skip, a lost extension, names that repeat; a long file name is shortened before its `.{ext}`) |
|
||||
| `Naming` | Folder/file templates and tokens (folder levels scans skip escaped with `_`; `ExpandText` for titles; `ExpandFile` shortens a long file name before its `.{ext}`); `FrameNaming` (the naming context and unique file name of a frame, shared by import, upload and Reorganize: the sequence's camera and lens, the first frame for folders; `UniqueNames`: `_2`, `_3`… in linear time); `TemplateRules` (what every place a template is typed or sent refuses, the archive engine's new or changed templates included: a folder scans skip, a lost extension, names that repeat) |
|
||||
| `Model` | Domain entities and enums (§5) shared by Data, Server and clients |
|
||||
| `Packaging` | TPK1 installer payload writer/reader, staged install transaction |
|
||||
| `Diagnostics` | `Log` (never throws: a line its sink cannot write is dropped), `FileLogSink` with `LogFileOptions` (level, daily or hourly files, numbered parts past a size, pruning by age and by the total size, never the file being written), synthetic sequences, `SecretScrubber`, `DiagnosticsArchive` (scrubbed diagnostics zip) |
|
||||
|
||||
@@ -166,7 +166,7 @@
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<!-- Photos that keep their names, each line with why. -->
|
||||
<!-- Photos that keep their names, each line with why; or why the whole sequence stays as it is. -->
|
||||
<ItemsControl ItemsSource="{Binding Kept}" Focusable="False" Visibility="{Binding HasKept, Converter={StaticResource BoolToVisibility}}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
|
||||
@@ -20,7 +20,8 @@ public sealed record ReorganizeLine(string Label, string From, string To, bool I
|
||||
|
||||
/// <summary>
|
||||
/// One sequence of the Reorganize dry run: its name, what concerns it as a whole (it follows its folder, how many of its
|
||||
/// files get a new name), its changes (the first renamed files as samples) and the photos that keep their names, with why.
|
||||
/// files get a new name), its changes (the first renamed files as samples) and the photos that keep their names, with why,
|
||||
/// or why the whole sequence stays as it is.
|
||||
/// </summary>
|
||||
/// <param name="IsNamePath">The sequence has no title: <paramref name="Name"/> is its folder, read left to right.</param>
|
||||
public sealed record ReorganizeRow(Guid SequenceId, string Name, bool IsNamePath, string Note, IReadOnlyList<ReorganizeLine> Lines, IReadOnlyList<string> Kept)
|
||||
@@ -70,7 +71,10 @@ public static class ReorganizePlans
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>The rows of a plan, in the order it applies them; a step that changes nothing lists why photos keep their names.</summary>
|
||||
/// <summary>
|
||||
/// The rows of a plan, in the order it applies them; a step that changes nothing lists why photos keep their names, or
|
||||
/// why the whole sequence stays as it is.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<ReorganizeRow> Rows(RenamePlan plan) => [.. plan.Steps.Where(s => s.Changes || s.Blocked.Count > 0).Select(Row)];
|
||||
|
||||
public static ReorganizeRow Row(RenameStep step)
|
||||
|
||||
@@ -42,6 +42,8 @@ public static class ErrorText
|
||||
{
|
||||
LeaseUnavailableException or ArchiveOfflineException or NewerFormatException or ImportSourceUnavailableException
|
||||
or CopyVerificationException or StaleRenamePlanException or SyncConflictChangedException => ex.Message,
|
||||
// A template an archive refused (Settings › Archive, or this PC's templates for a new archive): the rule it breaks.
|
||||
TemplateRuleException rule => Loc.L("Errors.Template." + rule.Rule),
|
||||
// The server words its errors in the client's language (Accept-Language).
|
||||
ChronosApiException api when FromServer(api.Error) => api.Error.Message,
|
||||
// Any other reply (a reverse proxy's 502 page while the server restarts, its 413 for a large body, a bare 500) holds
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Text.Json;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.Import;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Naming;
|
||||
using Chronos.Data.Archiving.Jobs;
|
||||
@@ -104,13 +105,14 @@ public sealed class ArchiveService : IJobHandlerProvider
|
||||
/// becomes the folder's name; a longer one than <see cref="ArchiveSettings.MaxNameLength"/> is shortened.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">The folder already is an archive (open it instead).</exception>
|
||||
/// <exception cref="ArgumentException">A template or policy is invalid (<see cref="ArgumentException.ParamName"/> names it).</exception>
|
||||
/// <exception cref="ArgumentException">A template or policy is invalid (<see cref="ArgumentException.ParamName"/> names it;
|
||||
/// <see cref="TemplateRuleException"/> for a template that breaks a rule).</exception>
|
||||
public async Task<Archive> CreateAsync(string root, ArchiveSettings settings, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
var paths = new ArchivePaths(root);
|
||||
settings = WithUsableName(settings, paths);
|
||||
if (settings.Problem() is { } field) throw new ArgumentException($"The archive setting {field} is invalid.", field);
|
||||
settings.Validate();
|
||||
if (File.Exists(paths.ManifestPath)) throw new InvalidOperationException($"{paths.Root} already is a Chronos archive.");
|
||||
Directory.CreateDirectory(paths.MetaDirectory);
|
||||
var manifest = new ArchiveManifest
|
||||
@@ -211,9 +213,12 @@ public sealed class ArchiveService : IJobHandlerProvider
|
||||
/// a client sharing the archive never undo each other's change; the file is replaced atomically. Folders and files
|
||||
/// already in the archive keep their names: templates and policies apply to the next imports, proxies and thumbnails.
|
||||
/// A blank or overlong name in the file (archives made at a drive root, or before names were checked) is made usable
|
||||
/// as <see cref="CreateAsync(string, ArchiveSettings, CancellationToken)"/> does, instead of failing every edit.
|
||||
/// as <see cref="CreateAsync(string, ArchiveSettings, CancellationToken)"/> does, instead of failing every edit. Likewise
|
||||
/// a template the file holds that breaks a rule of the archive's templates (saved before the rules existed) stays as it
|
||||
/// is through an edit of anything else: only a template the edit gives is held to them (<see cref="ArchiveSettings.Problem"/>).
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentException">An edited setting is invalid (<see cref="ArgumentException.ParamName"/> names it).</exception>
|
||||
/// <exception cref="ArgumentException">An edited setting is invalid (<see cref="ArgumentException.ParamName"/> names it;
|
||||
/// <see cref="TemplateRuleException"/> for a template that breaks a rule).</exception>
|
||||
/// <exception cref="ArchiveOfflineException">The archive is offline or read-only.</exception>
|
||||
/// <exception cref="LeaseUnavailableException">Another process kept the archive's settings busy.</exception>
|
||||
public async Task<Archive> UpdateSettingsAsync(Guid archiveId, Func<ArchiveSettings, ArchiveSettings> edit, CancellationToken cancellationToken = default)
|
||||
@@ -230,7 +235,8 @@ public sealed class ArchiveService : IJobHandlerProvider
|
||||
if (current.Id != archive.Id) throw new InvalidDataException($"{paths.ManifestPath} belongs to archive {current.Id}, not {archive.Id}.");
|
||||
// The name read is made usable before the edit sees it; a name the edit sets is checked as given.
|
||||
var settings = edit(WithUsableName(ArchiveSettings.Of(current), paths));
|
||||
if (settings.Problem() is { } field) throw new ArgumentException($"The archive setting {field} is invalid.", field);
|
||||
// A template the file already holds stays as it is, rules or not: only one the edit gives is held to them.
|
||||
settings.Validate(current.LayoutTemplates);
|
||||
var manifest = current with
|
||||
{
|
||||
Name = settings.Name.Trim(),
|
||||
@@ -536,21 +542,60 @@ public sealed record ArchiveSettings(string Name, LayoutTemplates Templates, Pro
|
||||
|
||||
/// <summary>
|
||||
/// The first invalid field by its API name (<c>name</c>, <c>folderTemplate</c>, <c>fileTemplate</c>,
|
||||
/// <c>proxyLongEdge</c>, <c>thumbnailLongEdge</c>); null when every field is valid. The templates are held to the rules
|
||||
/// they meet wherever they are typed (<see cref="RenameTemplates.Problem"/>, <see cref="TemplateRules"/>): besides
|
||||
/// parsing, a folder template may not write a level scans never enter, and a file template must keep the photo's
|
||||
/// extension, tell a session's photos apart and hold no slash.
|
||||
/// <c>proxyLongEdge</c>, <c>thumbnailLongEdge</c>); null when every field is valid. A template has to be usable
|
||||
/// (<see cref="RenameTemplates.Check"/>), and one given anew is held to the rules it meets wherever it is typed
|
||||
/// (<see cref="TemplateRules"/>): a folder template may not write a level scans never enter, and a file template must
|
||||
/// keep the photo's extension, tell a session's photos apart and hold no slash.
|
||||
/// </summary>
|
||||
public string? Problem()
|
||||
/// <param name="stored">The templates archive.json holds before an edit: one the edit leaves as it is, saved before the
|
||||
/// rules existed (0.1.0-rc.5 and earlier), never fails an edit of another setting. Null holds both to every rule (a new
|
||||
/// archive).</param>
|
||||
public string? Problem(LayoutTemplates? stored = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Name) || Name.Trim().Length > MaxNameLength) return "name";
|
||||
if (string.IsNullOrWhiteSpace(Templates.Folder)) return "folderTemplate";
|
||||
if (string.IsNullOrWhiteSpace(Templates.File)) return "fileTemplate";
|
||||
if (new RenameTemplates(Templates.Folder, Templates.File).Problem() is { } template) return template;
|
||||
if (CheckTemplates(stored) is { } template) return template.Field;
|
||||
if (!ProxyPolicy.IsValidLongEdge(Proxies.LongEdge) || Proxies.Quality is < 1 or > 100) return "proxyLongEdge";
|
||||
if (!ThumbnailPolicy.IsValidLongEdge(Thumbnails.LongEdge) || Thumbnails.Quality is < 1 or > 100) return "thumbnailLongEdge";
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The first template that cannot be used (<see cref="Problem"/>), with the rule it breaks
|
||||
/// (<see cref="TemplateProblem.Rule"/>); null when both can. A rule broken by a template <paramref name="stored"/>
|
||||
/// already holds does not count.
|
||||
/// </summary>
|
||||
public TemplateProblem? CheckTemplates(LayoutTemplates? stored = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Templates.Folder)) return new TemplateProblem("folderTemplate", null);
|
||||
if (string.IsNullOrWhiteSpace(Templates.File)) return new TemplateProblem("fileTemplate", null);
|
||||
static TemplateProblem? Given(RenameTemplates template, bool kept) => template.Check() is { } problem && (problem.Rule is null || !kept) ? problem : null;
|
||||
return Given(new RenameTemplates(Folder: Templates.Folder), Templates.Folder == stored?.Folder)
|
||||
?? Given(new RenameTemplates(File: Templates.File), Templates.File == stored?.File);
|
||||
}
|
||||
|
||||
/// <summary>Refuses these settings when a field is invalid (<see cref="Problem"/>).</summary>
|
||||
/// <exception cref="TemplateRuleException">A template breaks a rule of the archive's templates.</exception>
|
||||
/// <exception cref="ArgumentException">Another field is invalid (<see cref="ArgumentException.ParamName"/> names it).</exception>
|
||||
internal void Validate(LayoutTemplates? stored = null)
|
||||
{
|
||||
if (Problem(stored) is not { } field) return;
|
||||
if (CheckTemplates(stored) is { Rule: { } rule } template && template.Field == field) throw new TemplateRuleException(field, rule);
|
||||
throw new ArgumentException($"The archive setting {field} is invalid.", field);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An archive setting's template breaks a rule of the archive's templates (<see cref="TemplateRules"/>): the message says
|
||||
/// which in one sentence (<c>Errors.Template.<Rule></c>, in the language of the moment it was refused), and
|
||||
/// <see cref="ParamName"/> names the template by its API name (<c>folderTemplate</c>, <c>fileTemplate</c>).
|
||||
/// </summary>
|
||||
public sealed class TemplateRuleException(string field, string rule) : ArgumentException(Loc.L("Errors.Template." + rule))
|
||||
{
|
||||
// Not the base's: its message would end in "(Parameter '…')".
|
||||
public override string? ParamName { get; } = field;
|
||||
|
||||
/// <summary>The rule broken (<see cref="TemplateProblem.Rule"/>).</summary>
|
||||
public string Rule { get; } = rule;
|
||||
}
|
||||
|
||||
/// <summary>Builds the archive jobs; enqueue with <see cref="EnqueueAsync"/>.</summary>
|
||||
|
||||
@@ -116,7 +116,8 @@ public sealed record ReorganizeStepDto(Guid SequenceId, string FromFolder, strin
|
||||
int FramesVersion, int FileChanges, IReadOnlyList<ReorganizeFileDto> FileSamples, IReadOnlyList<ReorganizeBlockedDto> Blocked);
|
||||
|
||||
/// <summary>
|
||||
/// The dry run of a Reorganize: its steps, the sequences that change (carried ones included), the photos renamed, the photos
|
||||
/// that keep their names, and the fingerprint the change sends back.
|
||||
/// The dry run of a Reorganize: its steps (those that change nothing list only what stays as it is), the sequences that
|
||||
/// change (carried ones included), the photos renamed, the photos that keep their names (a sequence that stays as it is
|
||||
/// whole, <c>unreadable</c>, counts none), and the fingerprint the change sends back.
|
||||
/// </summary>
|
||||
public sealed record ReorganizePlanDto(IReadOnlyList<ReorganizeStepDto> Steps, int Sequences, int Files, int Kept, string Fingerprint);
|
||||
@@ -255,7 +255,10 @@ export function openReorganize({ api, target, names = new Map(), templates = nul
|
||||
shownText.textContent = t("Admin.Library.Shown", formatNumber(Math.min(shown, steps.length)), formatNumber(steps.length));
|
||||
}
|
||||
|
||||
/** One step: the sequence's title, its folder and its renamed files, before and after, with the photos that keep their names. */
|
||||
/**
|
||||
* One step: the sequence's title, its folder and its renamed files, before and after, with the photos that keep their
|
||||
* names, or why the whole sequence stays as it is.
|
||||
*/
|
||||
function rowHtml(s) {
|
||||
const fromTitle = s.fromTitle ?? null;
|
||||
const toTitle = s.toTitle ?? null;
|
||||
|
||||
@@ -132,7 +132,8 @@ public static class ArchiveEndpoints
|
||||
/// <summary>
|
||||
/// Reorganize: folder, file and title templates applied to <c>sequenceIds</c> or, with <c>all</c>, to every sequence of the
|
||||
/// archive (BRIEF §12.5). With <c>dryRun</c> the plan, nothing touched: per sequence its folder and title before and after,
|
||||
/// the photos renamed with the first of them, and the photos that keep their names and why. Otherwise the request carries
|
||||
/// the photos renamed with the first of them, and the photos that keep their names and why, or why the whole sequence
|
||||
/// stays as it is. Otherwise the request carries
|
||||
/// that plan's fingerprint and the server queues a <c>move</c> job (202) that applies exactly that plan, refused when the
|
||||
/// archive changed before it ran. 400 <c>bad_request</c> (details <c>sequenceIds</c>: neither or both of them, none, or
|
||||
/// more than <see cref="LibraryEndpoints.MaxBulkIds"/>; <c>templates</c>: none; <c>fingerprint</c>), 400
|
||||
|
||||
@@ -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