feat: owner review 2 phase 4b: mass conversion after import #13
No files matched your search
@@ -154,7 +154,8 @@ exports a server files, exports a sync fetches, editor saves, sync applies and "
|
||||
sequence is. The image passes hold the thumbnail lease, which a Reorganize takes too: the thumbnail pass for all of it,
|
||||
the proxy pass a batch at a time (a quarter of the lease wait), reading the folder and sidecar again for each batch. A
|
||||
folder another index moved is found by this index's next scan, which moves the row, its frames and its exports' paths
|
||||
(`ArchiveIndexer.RebaseRendersAsync`; an export whose file is still at the old place keeps its path); until then these
|
||||
(`ArchiveIndexer.RebaseRendersAsync`; an export, a file or an image-sequence folder, still at the old place keeps its
|
||||
path, unless the old folder is another sequence's now); until then these
|
||||
writers, a render job as it starts and a proxy pass at each batch refuse when they find the folder gone, and a deep
|
||||
analysis that loses it records nothing. A render whose folder another index moves while it runs is not stopped: its
|
||||
output can land in a folder created again at the old place, where its row keeps finding it.
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
<data name="Server.Error.Failed" xml:space="preserve"><value>The connection failed; the log has the details.</value><comment>long</comment></data>
|
||||
<data name="Server.Error.FolderInUse" xml:space="preserve"><value>A file of the sequence is open in another program; close it and try again.</value><comment>long</comment></data>
|
||||
<data name="Server.Error.FolderMissing" xml:space="preserve"><value>Its folder is no longer on disk; nothing is left to move to the trash.</value><comment>long</comment></data>
|
||||
<data name="Server.Error.FolderMoved" xml:space="preserve"><value>The folder of this sequence is not where the server's index has it; try again after its next scan.</value><comment>long</comment></data>
|
||||
<data name="Server.Error.Forbidden" xml:space="preserve"><value>Your account cannot do this.</value><comment>long</comment></data>
|
||||
<data name="Server.Error.FramesConflict" xml:space="preserve"><value>The photos of the sequence changed on the server; reload it and apply your edit again.</value><comment>long</comment></data>
|
||||
<data name="Server.Error.HashMismatch" xml:space="preserve"><value>The file arrived damaged; upload it again.</value><comment>long</comment></data>
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
<data name="Server.Error.Failed" xml:space="preserve"><value>La connessione non è riuscita; i dettagli sono nel log.</value></data>
|
||||
<data name="Server.Error.FolderInUse" xml:space="preserve"><value>Un file della sequenza è aperto in un altro programma; chiudilo e riprova.</value></data>
|
||||
<data name="Server.Error.FolderMissing" xml:space="preserve"><value>La sua cartella non è più sul disco; non resta nulla da spostare nel cestino.</value></data>
|
||||
<data name="Server.Error.FolderMoved" xml:space="preserve"><value>La cartella di questa sequenza non è dove la indica l'indice del server; riprova dopo la sua prossima scansione.</value></data>
|
||||
<data name="Server.Error.Forbidden" xml:space="preserve"><value>Il tuo account non può farlo.</value></data>
|
||||
<data name="Server.Error.FramesConflict" xml:space="preserve"><value>Le foto della sequenza sono cambiate sul server; ricaricala e riapplica la modifica.</value></data>
|
||||
<data name="Server.Error.HashMismatch" xml:space="preserve"><value>Il file è arrivato danneggiato; caricalo di nuovo.</value></data>
|
||||
|
||||
@@ -61,7 +61,8 @@ public sealed class ReorganizeTemplate : ObservableObject
|
||||
/// Reorganize (owner review 2, R7; BRIEF §7.1, §12.5): new folder, file and title templates applied to sequences already in
|
||||
/// the archive — a set, or every sequence. Each template has its switch and starts from the archive's settings; the dry run
|
||||
/// (the engine's plan, nothing changes on disk) follows the typing and lists each sequence that changes with its new
|
||||
/// folder, title and first file names, and the photos that keep their names with why. Apply queues the Reorganize job of
|
||||
/// folder, title and first file names, and the photos that keep their names with why, or why the whole sequence stays as
|
||||
/// it is (a sidecar that cannot be read). Apply queues the Reorganize job of
|
||||
/// exactly that plan (<see cref="ArchiveJobs.Reorganize"/>): resumable, paused and followed in Jobs, refused when the
|
||||
/// archive changed after the dry run.
|
||||
/// </summary>
|
||||
|
||||
@@ -260,7 +260,8 @@ public static class RenamePlanner
|
||||
/// <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; 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>
|
||||
/// folder can be found, under at most one of the two names (under neither when the disk spells it another way, such as
|
||||
/// <c>TRIP (2)</c>). 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,
|
||||
|
||||
@@ -187,25 +187,34 @@ public sealed class ArchiveIndexer
|
||||
|
||||
/// <summary>
|
||||
/// The render rows of the archive that follow a sequence's folder from <paramref name="from"/> to <paramref name="to"/>,
|
||||
/// in the caller's transaction (<see cref="Repositories.RenderRepository.RebaseFolderAsync"/>). A file is at its old path
|
||||
/// still when it is there and the new path is not the same file (on a file system that ignores case it is, when only the
|
||||
/// case changed). The sequence's own exports inside the folder follow unless their file is at the old path still and not
|
||||
/// at the new one: written there after the move by a writer that read the old folder, which created it again, so the row
|
||||
/// keeps naming where the file is. Another sequence's export follows only when its file moved with the folder (at its new
|
||||
/// path and no longer at the old one). An export missing from both places follows if it is the sequence's own.
|
||||
/// in the caller's transaction (<see cref="Repositories.RenderRepository.RebaseFolderAsync"/>). An export is a file, or
|
||||
/// a folder for an image sequence. It is at its old path still when it is there, the new path is not the same one (on a
|
||||
/// file system that ignores case it is, when only the case changed) and the old folder holds no other sequence now. The
|
||||
/// sequence's own exports inside the folder follow unless they are at the old path still and not at the new one:
|
||||
/// written there after the move by a writer that read the old folder, which created it again, so the row keeps naming
|
||||
/// where the export is. Another sequence's export follows only when it moved with the folder (at its new path and no
|
||||
/// longer at the old one). An export missing from both places follows if it is the sequence's own, and so does one whose
|
||||
/// old path is another sequence's: a sequence that moved into the old folder since brought an export of that name.
|
||||
/// </summary>
|
||||
internal static Task<int> RebaseRendersAsync(ChronosRepositories tx, Archive archive, Guid sequenceId, string from, string to,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var paths = new ArchivePaths(archive.RootPath);
|
||||
// Read once, and only for an export found at its old path.
|
||||
bool? taken = null;
|
||||
return tx.Renders.RebaseFolderAsync(archive.Id, sequenceId, from, to, (before, after, own) =>
|
||||
{
|
||||
var moved = File.Exists(paths.FromRelative(after));
|
||||
var behind = !string.Equals(before, after, StringComparison.OrdinalIgnoreCase) && File.Exists(paths.FromRelative(before));
|
||||
var moved = Path.Exists(paths.FromRelative(after));
|
||||
var behind = !string.Equals(before, after, StringComparison.OrdinalIgnoreCase) && Path.Exists(paths.FromRelative(before))
|
||||
&& !(taken ??= TakenByAnother(paths.Sequence(from), sequenceId));
|
||||
return own ? moved || !behind : moved && !behind;
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>Whether <paramref name="folder"/> is another sequence's now: its sidecar names another id.</summary>
|
||||
private static bool TakenByAnother(SequencePaths folder, Guid sequenceId) =>
|
||||
File.Exists(folder.ManifestPath) && SequenceTrash.SidecarId(folder.ManifestPath) is { } id && id != sequenceId;
|
||||
|
||||
/// <summary>
|
||||
/// Remembers the current stamps of a folder whose sidecar and index were just updated together, so the next
|
||||
/// incremental scan does not re-read what is already indexed.
|
||||
|
||||
@@ -511,7 +511,7 @@ public sealed partial class SequenceTrash
|
||||
/// The id a sidecar names, from its head (the id is written second), so checking a 35 MB sidecar does not parse it;
|
||||
/// the whole file is read only when the head does not hold the id. Null when the file is unreadable.
|
||||
/// </summary>
|
||||
private static Guid? SidecarId(string path)
|
||||
internal static Guid? SidecarId(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -52,7 +52,9 @@ public sealed class RenderRepository
|
||||
/// <paramref name="follows"/> the folder takes the new path: the caller tells the sequence's own exports there (which
|
||||
/// follow unless their file stayed behind) from an export of another sequence saved inside it through the Export
|
||||
/// folder picker (which follows only when its file moved with the folder: a sequence that took the old folder since, by
|
||||
/// a later Reorganize another index made, keeps its own). Outputs elsewhere (absolute paths, other folders) stay as they are.
|
||||
/// a later Reorganize another index made, keeps its own). An export of the sequence whose path an export of another
|
||||
/// sequence names follows without asking: that path is the other sequence's now, which brought an export of that name
|
||||
/// into the old folder. Outputs elsewhere (absolute paths, other folders) stay as they are.
|
||||
/// </summary>
|
||||
/// <param name="follows">Whether the render at the first archive-relative path follows to the second one; the third
|
||||
/// argument says whether it is one of the sequence's own.</param>
|
||||
@@ -73,7 +75,9 @@ public sealed class RenderRepository
|
||||
foreach (var (id, owner, path) in under)
|
||||
{
|
||||
var to = newFolder.Length == 0 ? path[prefix.Length..] : newFolder + path[oldFolder.Length..];
|
||||
if (!follows(path, to, owner == sequenceId)) continue;
|
||||
var own = owner == sequenceId;
|
||||
var taken = own && under.Any(o => o.SequenceId != sequenceId && string.Equals(o.Path, path, StringComparison.Ordinal));
|
||||
if (!taken && !follows(path, to, own)) continue;
|
||||
rebased += await _db.ExecuteAsync("UPDATE renders SET output_path = $2 WHERE id = $1", [id, to], cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
return rebased;
|
||||
|
||||
@@ -177,14 +177,16 @@ public sealed class SyncService
|
||||
/// <summary>
|
||||
/// Settles a conflict as the user chose (BRIEF §12.7), against the versions the user was shown: when either side
|
||||
/// changed again since, nothing is written, the sequence is compared again and <see cref="SyncConflictChangedException"/>
|
||||
/// is thrown, as it is when <see cref="SyncResolution.SaveBoth"/> cannot keep this PC's version first (the folder is not
|
||||
/// where the index has it). Returns the file this PC's settings were saved to for <see cref="SyncResolution.SaveBoth"/>,
|
||||
/// else null.
|
||||
/// is thrown, as it is when <see cref="SyncResolution.SaveBoth"/> cannot keep this PC's version first or the server's
|
||||
/// version cannot be written because the folder is not where the index has it (another index moved it; its message then
|
||||
/// says to try again after the next scan). Returns the file this PC's settings were saved to for
|
||||
/// <see cref="SyncResolution.SaveBoth"/>, else null.
|
||||
/// </summary>
|
||||
public async Task<string?> ResolveAsync(ISyncRemote remote, Guid remoteId, SyncResolution resolution, CancellationToken cancellationToken)
|
||||
{
|
||||
string? saved = null;
|
||||
var changed = false;
|
||||
var moved = false;
|
||||
await _gate.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
@@ -229,6 +231,7 @@ public sealed class SyncService
|
||||
// This PC's version could not be kept (another index moved the folder): the server's does not replace it,
|
||||
// even where this index's scan finds the folder before the server's version would be written.
|
||||
changed = true;
|
||||
moved = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -239,8 +242,10 @@ public sealed class SyncService
|
||||
}
|
||||
else
|
||||
{
|
||||
// Edited on this PC since it was read: the copy of a version the user did not choose to keep goes.
|
||||
// Edited on this PC since it was read, or the folder moved by another index: the copy of a version the
|
||||
// user did not choose to keep goes.
|
||||
changed = true;
|
||||
moved = await FolderMovedAsync(local, cancellationToken).ConfigureAwait(false);
|
||||
if (saved is not null) await DeleteCopyAsync(local, saved, cancellationToken).ConfigureAwait(false);
|
||||
saved = null;
|
||||
}
|
||||
@@ -259,7 +264,8 @@ public sealed class SyncService
|
||||
if (changed)
|
||||
{
|
||||
await RefreshSequencesAsync(remote, [remoteId], CompareOnly, cancellationToken).ConfigureAwait(false);
|
||||
throw new SyncConflictChangedException(Loc.L("Errors.Sync.ChangedAgain"));
|
||||
// Choosing again changes nothing while the folder is not where the index has it: the next scan finds it.
|
||||
throw new SyncConflictChangedException(Loc.L(moved ? "Errors.Archive.FolderMoved" : "Errors.Sync.ChangedAgain"));
|
||||
}
|
||||
await StoreStatesAsync(remote.Server, null, cancellationToken).ConfigureAwait(false);
|
||||
Changed?.Invoke(remote.Server);
|
||||
@@ -823,6 +829,19 @@ public sealed class SyncService
|
||||
return path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the sequence is not in the folder the index has for it now, on an archive that is there: another index moved
|
||||
/// it, and this index's next scan finds it. Read without the lease, to tell why a resolution wrote nothing.
|
||||
/// </summary>
|
||||
private async Task<bool> FolderMovedAsync(Sequence local, CancellationToken cancellationToken)
|
||||
{
|
||||
if (await _db.Sequences.GetAsync(local.Id, cancellationToken).ConfigureAwait(false) is not { } row
|
||||
|| await _db.Archives.GetAsync(row.ArchiveId, cancellationToken).ConfigureAwait(false) is not { } archive)
|
||||
return false;
|
||||
var paths = new ArchivePaths(archive.RootPath);
|
||||
return Directory.Exists(paths.Root) && !Directory.Exists(paths.Sequence(row.Folder).Folder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a "Save both" copy of a version the user did not keep from the sequence's folder as the index has it now: a
|
||||
/// Reorganize may have moved the folder, the copy with it, since the copy was written. Best effort: a copy that cannot
|
||||
|
||||
@@ -58,8 +58,9 @@ public sealed record RenderJobParameters(string PresetName, string PresetJson, s
|
||||
|
||||
/// <summary>
|
||||
/// <c>POST /api/v1/nodes/{id}/jobs/{jobId}/result</c>: the finished output a node is about to upload in chunks. A
|
||||
/// <c>result/complete</c> that cannot file it for now answers 503 <c>sequence_busy</c> or <c>archive_offline</c>; the
|
||||
/// upload and the job stay the node's, to be completed again.
|
||||
/// <c>result/complete</c> that cannot file it for now answers 503 <c>sequence_busy</c>, <c>archive_offline</c> or
|
||||
/// <c>folder_moved</c> (another index moved the sequence's folder; the server's next scan finds it); the upload and the
|
||||
/// job stay the node's, to be completed again.
|
||||
/// </summary>
|
||||
public sealed record RenderResultRequest(
|
||||
string FileName,
|
||||
|
||||
@@ -44,7 +44,8 @@ public sealed record CardImportReport(Guid ImportId, string Card, string State,
|
||||
/// server already has that id it answers 200 with <see cref="StartUploadResponse.AlreadyExists"/>. Chunks go to
|
||||
/// <c>/uploads/{uploadId}/chunks/{n}</c>; <c>POST /sequences/{id}/renders/{uploadId}/complete</c> verifies the SHA-256
|
||||
/// and files the render under the sequence's exports. A completion that cannot file it for now answers 503
|
||||
/// <c>sequence_busy</c> or <c>archive_offline</c> and keeps the upload, to be completed again.
|
||||
/// <c>sequence_busy</c>, <c>archive_offline</c> or <c>folder_moved</c> (another index moved the sequence's folder; the
|
||||
/// server's next scan finds it) and keeps the upload, to be completed again.
|
||||
/// </summary>
|
||||
public sealed record RenderUploadRequest(
|
||||
Guid RenderId,
|
||||
|
||||
@@ -72,11 +72,12 @@ public static class ArchiveEndpoints
|
||||
/// Writes the name, templates and proxy policy into the archive's <c>archive.json</c> through the archive engine (so a
|
||||
/// restart and the proxy jobs see them), then into the index. 400 <c>bad_request</c> (details <c>name</c>,
|
||||
/// <c>proxyLongEdge</c>), 400 <c>invalid_template</c> (<see cref="InvalidTemplate"/>: <c>folderTemplate</c> or
|
||||
/// <c>fileTemplate</c>, with the rule it breaks); 503 <c>archive_offline</c> while the archive cannot be
|
||||
/// written; 409 <c>archive_busy</c> while another process holds its settings; 409 <c>archive_manifest</c> when its
|
||||
/// archive.json is damaged, written by a newer Chronos or of another archive; 409 <c>archive_policy</c> when it holds a
|
||||
/// thumbnail or proxy setting this API cannot set and Chronos cannot use (details: <c>thumbnailPolicy</c> or
|
||||
/// <c>proxyPolicy</c>, the property to correct in the file). Nothing is written.
|
||||
/// <c>fileTemplate</c>, with the rule it breaks; only a template the request changes is held to the rules, so one
|
||||
/// archive.json holds from before them never fails a save of the other fields); 503 <c>archive_offline</c> while the
|
||||
/// archive cannot be written; 409 <c>archive_busy</c> while another process holds its settings; 409
|
||||
/// <c>archive_manifest</c> when its archive.json is damaged, written by a newer Chronos or of another archive; 409
|
||||
/// <c>archive_policy</c> when it holds a thumbnail or proxy setting this API cannot set and Chronos cannot use (details:
|
||||
/// <c>thumbnailPolicy</c> or <c>proxyPolicy</c>, the property to correct in the file). Nothing is written.
|
||||
/// </summary>
|
||||
private static async Task<IResult> UpdateAsync(HttpContext context, Caller caller, ArchiveSettingsDto request, ChronosDatabase db, ServerArchive archive,
|
||||
[FromServices] ArchiveService? archives, AuditLog audit)
|
||||
@@ -85,8 +86,12 @@ public static class ArchiveEndpoints
|
||||
if (string.IsNullOrEmpty(name) || name.Length > ArchiveSettings.MaxNameLength) return ApiErrors.BadRequest(context, "bad_request", "name");
|
||||
if (string.IsNullOrWhiteSpace(request.FolderTemplate)) return ApiErrors.BadRequest(context, "invalid_template", "folderTemplate");
|
||||
if (string.IsNullOrWhiteSpace(request.FileTemplate)) return ApiErrors.BadRequest(context, "invalid_template", "fileTemplate");
|
||||
// The rules Reorganize checks: a folder scans never enter, a lost extension or names that repeat are refused alike.
|
||||
if (new RenameTemplates(request.FolderTemplate, request.FileTemplate).Check() is { } problem) return InvalidTemplate(context, problem);
|
||||
// The rules Reorganize checks (a folder scans never enter, a lost extension or names that repeat) hold a template the
|
||||
// request changes, as the engine does: one archive.json holds already, saved before them, never fails another save.
|
||||
var templates = new LayoutTemplates { Folder = request.FolderTemplate, File = request.FileTemplate };
|
||||
var stored = new LayoutTemplates { Folder = archive.Current.FolderTemplate, File = archive.Current.FileTemplate };
|
||||
if (new ArchiveSettings(name, templates, new ProxyPolicy(), new ThumbnailPolicy()).CheckTemplates(stored) is { } problem)
|
||||
return InvalidTemplate(context, problem);
|
||||
if (!ProxyPolicy.IsValidLongEdge(request.ProxyLongEdge)) return ApiErrors.BadRequest(context, "bad_request", "proxyLongEdge");
|
||||
|
||||
var engine = archives ?? new ArchiveService(db, new ArchiveServiceOptions { Owner = ArchiveModule.Owner });
|
||||
@@ -108,6 +113,11 @@ public static class ArchiveEndpoints
|
||||
{
|
||||
return ApiErrors.Conflict(context, "archive_manifest");
|
||||
}
|
||||
catch (TemplateRuleException ex)
|
||||
{
|
||||
// archive.json held other templates than the index (a desktop's edit since): the request's breaks a rule for it.
|
||||
return InvalidTemplate(context, new TemplateProblem(ex.ParamName!, ex.Rule));
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
// The request's fields were checked above: what fails is a value read from archive.json (a thumbnail size, or a
|
||||
|
||||
@@ -181,7 +181,7 @@ public sealed class RenderNodeService(
|
||||
{
|
||||
render = sequence is null ? null : await renders.CommitAsync(sequence, staged, output, node.ClientName, cancellationToken);
|
||||
}
|
||||
catch (Exception ex) when (ex is LeaseUnavailableException or ArchiveOfflineException)
|
||||
catch (Exception ex) when (ex is LeaseUnavailableException or ArchiveOfflineException or FolderMovedException)
|
||||
{
|
||||
// The node keeps the job and completes again.
|
||||
return await uploads.ReceiveAgainAsync<RenderDto>(upload, staged, ex);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Chronos.Core.IO;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data;
|
||||
using Chronos.Data.Archiving;
|
||||
@@ -16,21 +17,24 @@ public sealed class RenderStore(ChronosDatabase db, ServerArchive archive, TimeP
|
||||
/// Moves <paramref name="stagedFile"/> (on the archive volume) to <c><sequence folder>/exports/</c>, never
|
||||
/// replacing an existing export, and inserts the render row, both under the sequence's lease with its folder as the
|
||||
/// index has it then: a Reorganize may have moved it since <paramref name="sequence"/> was read, and moves the row's
|
||||
/// path along when it moves it later. Null when the sequence left the index, has no folder in the archive yet or is not
|
||||
/// in the folder the index has (another index moved it); nothing is moved then.
|
||||
/// path along when it moves it later. Null when the sequence left the index or has no folder in the archive yet; nothing
|
||||
/// is moved then.
|
||||
/// </summary>
|
||||
/// <exception cref="FolderMovedException">The sequence is not in the folder the index has (another index moved it):
|
||||
/// nothing is moved, and the filing can be done again once this index's next scan found the folder.</exception>
|
||||
public Task<Render?> CommitAsync(Sequence sequence, string stagedFile, RenderResultRequest output, string producedBy, CancellationToken cancellationToken) =>
|
||||
CommitAsync(sequence, stagedFile, output, producedBy, Guid.CreateVersion7(), cancellationToken);
|
||||
|
||||
/// <summary>As above, keeping <paramref name="id"/>: a render a client sends keeps the id it has on that client.</summary>
|
||||
/// <exception cref="FolderMovedException">The sequence is not in the folder the index has.</exception>
|
||||
public Task<Render?> CommitAsync(Sequence sequence, string stagedFile, RenderResultRequest output, string producedBy, Guid id,
|
||||
CancellationToken cancellationToken) =>
|
||||
_archives.UnderLeaseAsync(sequence, async row =>
|
||||
{
|
||||
// A folder another index moved is found by this index's next scan; until then nothing is filed, so it is not created again.
|
||||
if (row is null || string.IsNullOrEmpty(row.Folder) || ArchivePathGuard.Resolve(archive.Root, row.Folder.TrimEnd('/') + "/exports") is not { } exports
|
||||
|| !Directory.Exists(Path.GetDirectoryName(exports)))
|
||||
if (row is null || string.IsNullOrEmpty(row.Folder) || ArchivePathGuard.Resolve(archive.Root, row.Folder.TrimEnd('/') + "/exports") is not { } exports)
|
||||
return null;
|
||||
// A folder another index moved is found by this index's next scan; until then nothing is filed, so it is not created again.
|
||||
if (!Directory.Exists(Path.GetDirectoryName(exports))) throw new FolderMovedException();
|
||||
Directory.CreateDirectory(exports);
|
||||
var target = Unique(exports, output.FileName);
|
||||
File.Move(stagedFile, target);
|
||||
@@ -62,3 +66,9 @@ public sealed class RenderStore(ChronosDatabase db, ServerArchive archive, TimeP
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A sequence is not in the folder the index has (another index of the archive moved it): nothing was filed into it, and
|
||||
/// this index's next scan finds the folder, after which the filing can be done again.
|
||||
/// </summary>
|
||||
public sealed class FolderMovedException() : IOException(Loc.L("Errors.Archive.FolderMoved"));
|
||||
@@ -95,7 +95,7 @@ public sealed class RenderUploads(
|
||||
render = sequence is null ? null : await renders.CommitAsync(sequence, staged, result, output.ProducedBy ?? caller.ClientName ?? caller.User.Username,
|
||||
output.RenderId, cancellationToken);
|
||||
}
|
||||
catch (Exception ex) when (ex is LeaseUnavailableException or ArchiveOfflineException)
|
||||
catch (Exception ex) when (ex is LeaseUnavailableException or ArchiveOfflineException or FolderMovedException)
|
||||
{
|
||||
return await uploads.ReceiveAgainAsync<RenderDto>(upload, staged, ex);
|
||||
}
|
||||
|
||||
@@ -306,9 +306,10 @@ public sealed class UploadService(
|
||||
|
||||
/// <summary>
|
||||
/// A verified upload whose filing was refused before anything moved, for a reason that passes: its sequence held by
|
||||
/// another writer past the lease wait (503 <c>sequence_busy</c>), or the archive offline or read-only (503
|
||||
/// <c>archive_offline</c>). The staged copy goes and the upload receives again with its part file, so the client
|
||||
/// completes it again, as it does after any 503.
|
||||
/// another writer past the lease wait (503 <c>sequence_busy</c>), the archive offline or read-only (503
|
||||
/// <c>archive_offline</c>), or the sequence's folder not where the index has it until this index's next scan (503
|
||||
/// <c>folder_moved</c>, <see cref="FolderMovedException"/>). The staged copy goes and the upload receives again with its
|
||||
/// part file, so the client completes it again, as it does after any 503.
|
||||
/// </summary>
|
||||
public async Task<Outcome<T>> ReceiveAgainAsync<T>(Upload upload, string staged, Exception refusal)
|
||||
{
|
||||
@@ -316,7 +317,12 @@ public sealed class UploadService(
|
||||
logger.LogWarning("Upload {Upload} ({File}) not filed for now: {Reason}", upload.Id, upload.FileName, refusal.Message);
|
||||
UploadStore.TryDelete(staged);
|
||||
await db.Uploads.TryTransitionAsync(upload.Id, UploadState.Committing, UploadState.Receiving, cancellationToken: CancellationToken.None);
|
||||
return Fail<T>(503, refusal is ArchiveOfflineException ? "archive_offline" : "sequence_busy");
|
||||
return Fail<T>(503, refusal switch
|
||||
{
|
||||
ArchiveOfflineException => "archive_offline",
|
||||
FolderMovedException => "folder_moved",
|
||||
_ => "sequence_busy",
|
||||
});
|
||||
}
|
||||
|
||||
private async Task FailAsync(Upload upload)
|
||||
|
||||
@@ -328,6 +328,62 @@ public sealed class MassRenameTests(TestContext context)
|
||||
foreach (var path in expected[..2]) Assert.FileExists(fx.Paths.FromRelative(path));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnImageSequenceExportIsAFolderThatFollowsAsAFileDoes()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var ids = await PopulateAsync(fx);
|
||||
// Image-sequence exports: of "inbox/a" in its folder, and of "inbox/b" saved in the exports of "inbox/a".
|
||||
List<Guid> renders =
|
||||
[
|
||||
await RenderAsync(fx, ids[0], "inbox/a/exports/A frames", frames: true),
|
||||
await RenderAsync(fx, ids[1], "inbox/a/exports/B frames", frames: true),
|
||||
];
|
||||
var (server, archive) = await fx.OtherWriterAsync();
|
||||
|
||||
// The other index moves "inbox/a"; a writer here that read the folder before files one where it was, creating it again.
|
||||
var plan = await server.PlanRenameAsync(archive.Id, [ids[0]], "moved/{date}", null, fx.Ct);
|
||||
await server.ApplyRenameAsync(plan, null, fx.Ct);
|
||||
renders.Add(await RenderAsync(fx, ids[0], "inbox/a/exports/Late frames", frames: true));
|
||||
|
||||
// Each folder follows, or stays, as a file would: both that moved with the folder, not the one written where it was.
|
||||
await fx.ScanAsync();
|
||||
string[] expected = ["moved/2026-09-28/exports/A frames", "moved/2026-09-28/exports/B frames", "inbox/a/exports/Late frames"];
|
||||
Assert.SequenceEqual(expected, await OutputsAsync(fx, renders));
|
||||
foreach (var path in expected) Assert.FileExists(Path.Combine(fx.Paths.FromRelative(path), "000001.png"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnExportNeverNamesTheOneAnotherSequenceBroughtIntoItsOldFolder()
|
||||
{
|
||||
// The new folder is scanned after "inbox/a", then before it.
|
||||
foreach (var template in new[] { "moved/{date}", "done/{date}" })
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var ids = await PopulateAsync(fx);
|
||||
// The export of "inbox/a" is gone; "inbox/c" has one of the same name.
|
||||
List<Guid> renders =
|
||||
[
|
||||
await RenderAsync(fx, ids[0], "inbox/a/exports/Clip.mp4", write: false),
|
||||
await RenderAsync(fx, ids[2], "inbox/c/exports/Clip.mp4"),
|
||||
];
|
||||
var (server, archive) = await fx.OtherWriterAsync();
|
||||
|
||||
// The other index moves "inbox/a", then "inbox/c" into the folder it left, its export along.
|
||||
var first = await server.PlanRenameAsync(archive.Id, [ids[0]], template, null, fx.Ct);
|
||||
await server.ApplyRenameAsync(first, null, fx.Ct);
|
||||
await server.ApplyRenameAsync(await server.PlanRenameAsync(archive.Id, [ids[2]], "inbox/a", null, fx.Ct), null, fx.Ct);
|
||||
|
||||
// The first sequence's row follows its folder, missing there too, and never names the other one's file.
|
||||
await fx.ScanAsync();
|
||||
string[] expected = [first.Steps.Single().ToFolder + "/exports/Clip.mp4", "inbox/a/exports/Clip.mp4"];
|
||||
Assert.SequenceEqual(expected, await OutputsAsync(fx, renders), template);
|
||||
Assert.FileExists(fx.Paths.FromRelative(expected[1]));
|
||||
Assert.Equal(0, (await fx.ScanAsync()).Indexed);
|
||||
Assert.SequenceEqual(expected, await OutputsAsync(fx, renders), template);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task APhotoDeletionWhoseFolderMovedWhileItWaitedForTheLeaseIsRefused()
|
||||
{
|
||||
@@ -439,12 +495,16 @@ public sealed class MassRenameTests(TestContext context)
|
||||
Assert.False(Directory.Exists(fx.Paths.FromRelative("inbox/a")), "the folder it left is not created again");
|
||||
}
|
||||
|
||||
/// <summary>A render row of <paramref name="sequenceId"/> at <paramref name="output"/> (archive-relative or absolute), with its file unless told otherwise.</summary>
|
||||
private static async Task<Guid> RenderAsync(ArchiveFixture fx, Guid sequenceId, string output, bool write = true)
|
||||
/// <summary>
|
||||
/// A render row of <paramref name="sequenceId"/> at <paramref name="output"/> (archive-relative or absolute), with its
|
||||
/// file unless told otherwise; with <paramref name="frames"/> an image sequence's export, a folder of frames.
|
||||
/// </summary>
|
||||
private static async Task<Guid> RenderAsync(ArchiveFixture fx, Guid sequenceId, string output, bool write = true, bool frames = false)
|
||||
{
|
||||
if (write)
|
||||
{
|
||||
var file = Path.IsPathRooted(output) ? output : fx.Paths.FromRelative(output);
|
||||
if (frames) file = Path.Combine(file, "000001.png");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(file)!);
|
||||
await File.WriteAllBytesAsync(file, [1, 2, 3], fx.Ct);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data.Archiving;
|
||||
@@ -485,7 +486,8 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
moved = plan.Steps.Single().ToFolder;
|
||||
};
|
||||
f.Remote.OnceBeforeFrames = () => f.Archive.ScanAsync();
|
||||
await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.SaveBoth, f.Ct));
|
||||
var refused = await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.SaveBoth, f.Ct));
|
||||
Assert.Equal(Loc.L("Errors.Archive.FolderMoved"), refused.Message, "the user hears to try again after the next scan");
|
||||
// The server's frames were not read for a version that is not taken: the scan comes now.
|
||||
f.Remote.OnceBeforeFrames = null;
|
||||
await f.Archive.ScanAsync();
|
||||
@@ -518,8 +520,9 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
var plan = await other.PlanRenameAsync(archive.Id, [local.Id], "moved/{title}", null, f.Ct);
|
||||
await other.ApplyRenameAsync(plan, null, f.Ct);
|
||||
};
|
||||
await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.TakeServer, f.Ct));
|
||||
var refused = await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.TakeServer, f.Ct));
|
||||
Assert.Null(f.Remote.OnceBeforeManifest, "the folder moved during the resolution");
|
||||
Assert.Equal(Loc.L("Errors.Archive.FolderMoved"), refused.Message, "the user hears to try again after the next scan");
|
||||
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.SettingsJson), "nothing applied");
|
||||
Assert.False(Directory.Exists(left), "the folder it left is not created again");
|
||||
@@ -565,7 +568,8 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
var later = SyncFixture.Window41.Replace("41", "45", StringComparison.Ordinal);
|
||||
await f.EditLocalSettingsAsync(local.Id, later);
|
||||
|
||||
await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.TakeServer, f.Ct));
|
||||
var refused = await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(f.Remote, remote.Id, SyncResolution.TakeServer, f.Ct));
|
||||
Assert.Equal(Loc.L("Errors.Sync.ChangedAgain"), refused.Message);
|
||||
|
||||
Assert.True(SyncRules.SameSettings(later, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.SettingsJson), "this PC's later edit is kept");
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, remote.SettingsJson));
|
||||
|
||||
@@ -266,4 +266,54 @@ public sealed class AdminTests(TestContext context)
|
||||
}
|
||||
await File.WriteAllBytesAsync(path, saved, context.Cancellation);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TemplatesSavedBeforeTheRulesNeverFailASaveOfTheOtherFields()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context, services: Chronos.Server.Storage.ArchiveModule.Register);
|
||||
var admin = await server.AdminAsync();
|
||||
// An archive.json of 0.1.0-rc.5 or earlier: both templates break a rule new templates are held to.
|
||||
var path = new Chronos.Core.Archiving.ArchivePaths(server.Options.ArchivePath).ManifestPath;
|
||||
var manifest = Chronos.Core.Archiving.ManifestStore.ReadArchive(path);
|
||||
Chronos.Core.Archiving.ManifestStore.WriteArchive(path, manifest with
|
||||
{
|
||||
LayoutTemplates = new Chronos.Core.Archiving.LayoutTemplates { Folder = "exports/{date}", File = "{date}" },
|
||||
});
|
||||
using var read = await admin.GetAsync("/api/v1/archive/settings");
|
||||
var archive = await read.ReadAsync(ProtocolJson.Default.ArchiveSettingsDto);
|
||||
Assert.Equal(("exports/{date}", "{date}"), (archive.FolderTemplate, archive.FileTemplate));
|
||||
|
||||
// The form sends every field with each save: the name and the proxies change, the templates stay as they are.
|
||||
using (var put = await admin.PutAsJsonAsync("/api/v1/archive/settings", archive with { Name = "Studio", ProxyLongEdge = 2560 }, ProtocolJson.Default.ArchiveSettingsDto))
|
||||
{
|
||||
var saved = await put.ReadAsync(ProtocolJson.Default.ArchiveSettingsDto);
|
||||
Assert.Equal(("Studio", "exports/{date}", "{date}", 2560), (saved.Name, saved.FolderTemplate, saved.FileTemplate, saved.ProxyLongEdge));
|
||||
}
|
||||
archive = archive with { Name = "Studio", ProxyLongEdge = 2560 };
|
||||
|
||||
// A template given anew is held to every rule; each one is fixed alone.
|
||||
using (var refused = await admin.PutAsJsonAsync("/api/v1/archive/settings", archive with { FileTemplate = "{n}{ext}" }, ProtocolJson.Default.ArchiveSettingsDto))
|
||||
Assert.Equal("fileTemplate:extension", (await refused.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_template")).Details);
|
||||
using (var folder = await admin.PutAsJsonAsync("/api/v1/archive/settings", archive with { FolderTemplate = "{year}/{date}" }, ProtocolJson.Default.ArchiveSettingsDto))
|
||||
{
|
||||
var saved = await folder.ReadAsync(ProtocolJson.Default.ArchiveSettingsDto);
|
||||
Assert.Equal(("{year}/{date}", "{date}"), (saved.FolderTemplate, saved.FileTemplate));
|
||||
}
|
||||
archive = archive with { FolderTemplate = "{year}/{date}" };
|
||||
|
||||
// A desktop fixed the file template in archive.json since the form was read: the old one the form still sends is no
|
||||
// longer the file's, so it is held to the rules and the save says which one it breaks.
|
||||
Chronos.Core.Archiving.ManifestStore.WriteArchive(path, Chronos.Core.Archiving.ManifestStore.ReadArchive(path) with
|
||||
{
|
||||
LayoutTemplates = new Chronos.Core.Archiving.LayoutTemplates { Folder = "{year}/{date}", File = "{date}_{n:0000}" },
|
||||
});
|
||||
var before = await File.ReadAllBytesAsync(path, context.Cancellation);
|
||||
using (var stale = await admin.PutAsJsonAsync("/api/v1/archive/settings", archive with { ProxyLongEdge = 1280 }, ProtocolJson.Default.ArchiveSettingsDto))
|
||||
{
|
||||
var error = await stale.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_template");
|
||||
Assert.Equal(("fileTemplate:not_unique", Chronos.Core.Localization.Loc.Get("Errors.Template.NotUnique", System.Globalization.CultureInfo.GetCultureInfo("en"))),
|
||||
(error.Details, error.Message));
|
||||
}
|
||||
Assert.SequenceEqual(before, await File.ReadAllBytesAsync(path, context.Cancellation));
|
||||
}
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public sealed class ReorganizeTests(TestContext context)
|
||||
var video = Uploads.Photo(4096, 30);
|
||||
var staged = Path.Combine(context.CreateTempDirectory("staged"), "render.mp4");
|
||||
await File.WriteAllBytesAsync(staged, video);
|
||||
Assert.Null(await server.Services.GetRequiredService<RenderStore>().CommitAsync(sequence, staged,
|
||||
await Assert.ThrowsAsync<FolderMovedException>(() => server.Services.GetRequiredService<RenderStore>().CommitAsync(sequence, staged,
|
||||
new RenderResultRequest("Roof - 4K.mp4", video.Length, Uploads.Sha(video), "4K HEVC", "hevc", 3840, 2160, 25, 4), "studio-pc", CancellationToken.None));
|
||||
|
||||
Assert.FileExists(staged);
|
||||
|
||||
@@ -190,6 +190,20 @@ public sealed class RenderNodeTests(TestContext context)
|
||||
{
|
||||
File.Move(paths.ManifestPath + ".away", paths.ManifestPath);
|
||||
}
|
||||
// A desktop sharing the archive moved the sequence's folder: this server's index has it at the old place until its
|
||||
// next scan, and nothing is filed there meanwhile.
|
||||
var folder = (await server.Database.Sequences.GetAsync(frame.SequenceId))!.Folder;
|
||||
var left = paths.FromRelative(folder);
|
||||
Directory.Move(left, paths.FromRelative(folder + " moved"));
|
||||
await RefusedAsync("folder_moved");
|
||||
Assert.False(Directory.Exists(left), "the folder it left is not created again");
|
||||
// The next scan finds it where it is now (moved here as a scan moves it: this composition writes no sidecars), and the
|
||||
// renders are filed there.
|
||||
await using (var tx = await server.Database.BeginAsync(context.Cancellation))
|
||||
{
|
||||
await tx.Sequences.RelocateAsync(frame.SequenceId, folder + " moved", null, context.Cancellation);
|
||||
await tx.CommitAsync(context.Cancellation);
|
||||
}
|
||||
|
||||
foreach (var complete in completions)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user