feat: owner review 2 phase 5a: workspace and projects with a local home (#14)
CI / Build and test (push) Successful in 9m43s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 27s
CI / PostgreSQL 16 integration (push) Failing after 8m41s
CI / PostgreSQL 17 integration (push) Successful in 12m37s
CI / Docker image (push) Successful in 56s
Release / Build, test and publish (push) Successful in 14m59s
Release / Server image (push) Successful in 1m51s

Edit opens a sequence as a project of a workspace folder outside the library. Projects have linear version histories kept as sidecars in .chronos/projects/, Main mirrors the sequence's settings, and sync merges setting by setting. Migration 0009, JobKind.WorkspaceCopy = 20, Settings › Workspace, and 241 new strings in 38 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #14.
This commit is contained in:
Alby96andClaude Opus 5.5 authored and Alby96 committed 2026-11-04 09:22:08 +01:00
1 parent efa87f68ce
commit 9b24cf74fc
370 files changed
+29237 -287

No files matched your search

@@ -2,6 +2,7 @@ using Chronos.Core.Archiving;
using Chronos.Core.Diagnostics;
using Chronos.Core.IO;
using Chronos.Core.Model;
using Chronos.Data.Projects;
using Chronos.Data.Repositories;
namespace Chronos.Data.Archiving;
@@ -37,11 +38,13 @@ public sealed class ArchiveIndexer
private readonly ChronosDatabase _db;
private readonly SequenceWriter _writer;
private readonly ProjectIndexer _projects;
internal ArchiveIndexer(ChronosDatabase db, SequenceWriter writer)
{
_db = db;
_writer = writer;
_projects = new ProjectIndexer(db);
}
/// <param name="resumeAfter">Last folder completed by an interrupted run (job checkpoint), or null.</param>
@@ -78,6 +81,8 @@ public sealed class ArchiveIndexer
{
var reconcile = mode == ScanMode.Full || (state is not null && state.Photos != folder.Photos);
var (id, bytes) = await IndexFolderAsync(archive, paths, folder, reconcile, snapshot, locations, cancellationToken).ConfigureAwait(false);
// A full scan or a rebuild takes the projects' sidecars back too (owner review 2, R8).
if (mode != ScanMode.Incremental) await ReconcileProjectsAsync(paths, id, cancellationToken).ConfigureAwait(false);
if (snapshotWriter is not null)
{
// Bytes go under the stamp they were read at (the listed one for the bytes indexed, else one taken before
@@ -339,6 +344,37 @@ public sealed class ArchiveIndexer
/// </summary>
private SequenceStatus Uncovered => _writer.Options.ImagesAfterScan ? CoveringStatus : SequenceStatus.None;
/// <summary>
/// The projects of a sequence brought in line with their sidecars (<see cref="ProjectIndexer"/>), under its lease, in the
/// folder the index has for it then, which must hold it (<see cref="SequenceFolders.Holds"/>: another sequence's projects
/// are never taken, and a folder another index moved away never marks the projects gone). Nothing for a sequence without
/// a projects folder (its Main is made when a project is first asked for). A failure is logged and leaves the folder
/// indexed: the next project operation on the sequence catches up again.
/// </summary>
private async Task ReconcileProjectsAsync(ArchivePaths paths, Guid sequenceId, CancellationToken cancellationToken)
{
if (await _db.Sequences.GetAsync(sequenceId, cancellationToken).ConfigureAwait(false) is not { } row
|| !Directory.Exists(paths.Sequence(row.Folder).ProjectsDirectory)) return;
try
{
await using (await _writer.LockAsync(paths, sequenceId, cancellationToken).ConfigureAwait(false))
{
var folder = await SequenceWriter.FolderAsync(_db, paths, row, cancellationToken).ConfigureAwait(false);
if (!SequenceFolders.Holds(folder, sequenceId) || !Directory.Exists(folder.ProjectsDirectory)) return;
await _projects.ReconcileAsync(folder, sequenceId, cancellationToken).ConfigureAwait(false);
}
}
catch (Exception ex) when (ex is IOException or InvalidDataException or UnauthorizedAccessException)
{
Log.Warning("projects", $"The projects of {row.Folder} could not be read back; the next project operation tries again", ex);
}
catch (DatabaseException ex)
{
// The index refused a project of this sequence: the scan goes on with the others, and the next project operation tries again.
Log.Warning("projects", $"The projects of {row.Folder} could not be indexed; the next project operation tries again", ex);
}
}
/// <summary>Indexes one folder; returns its sequence and the sidecar bytes when they were read and not rewritten since (for the snapshot).</summary>
private async Task<(Guid Id, byte[]? Bytes)> IndexFolderAsync(Archive archive, ArchivePaths paths, SequenceFolder folder, bool reconcile, IndexSnapshot? snapshot,
Locations locations, CancellationToken cancellationToken)
@@ -9,6 +9,7 @@ using Chronos.Core.Naming;
using Chronos.Data.Archiving.Jobs;
using Chronos.Data.Jobs;
using Chronos.Data.Processing;
using Chronos.Data.Projects;
using Chronos.Data.Repositories;
namespace Chronos.Data.Archiving;
@@ -44,6 +45,7 @@ public sealed class ArchiveService : IJobHandlerProvider
Trash = new SequenceTrash(db, _writer, Indexer);
FrameTrash = new FrameTrash(db, _writer, Indexer, Ingest, Trash);
Converter = new MassConverter(db, _writer, Ingest, FrameTrash, Trash, this);
Projects = new ProjectService(db, _writer);
var shared = Housekeeping.CleanupSteps.Shared(Trash);
CleanupSteps = [.. shared, .. _writer.Options.CleanupSteps.Where(s => !shared.Any(o => o.Name == s.Name))];
}
@@ -68,6 +70,15 @@ public sealed class ArchiveService : IJobHandlerProvider
/// <summary>Converts sequences to JPEG, TIFF-16 or linear DNG, replacing their frames or into new sequences (owner review 2, R7).</summary>
public MassConverter Converter { get; }
/// <summary>The projects of the sequences and their versions: this PC's archive as a project's home (owner review 2, R8).</summary>
public ProjectService Projects { get; }
/// <summary>The decoders of this engine's image passes (thumbnails, proxies).</summary>
public Core.Imaging.ImageDecoder Decoder => _writer.Options.Decoder;
/// <summary>How the host measures free space under a folder (<see cref="ArchiveServiceOptions.FreeSpace"/>); null: the folder's drive.</summary>
public Func<string, long?>? FreeSpace => _writer.Options.FreeSpace;
/// <summary>
/// The steps this host's <see cref="JobKind.Cleanup"/> jobs can run: the shared ones (<see cref="Housekeeping.CleanupSteps.Shared"/>),
/// then the host's (<see cref="ArchiveServiceOptions.CleanupSteps"/>). A schedule host lists their names.
@@ -1,7 +1,14 @@
using Chronos.Core.Archiving;
using Chronos.Core.Localization;
namespace Chronos.Data.Archiving;
/// <summary>
/// The folder the index has for a sequence does not hold it (<see cref="SequenceFolders.Holds"/>): another index of the
/// archive moved it away, maybe another sequence in; this index's next scan finds both. Nothing was written.
/// </summary>
public sealed class SequenceFolderMovedException() : IOException(Loc.L("Errors.Archive.FolderMoved"));
/// <summary>Whether a sequence is in the folder the index has for it, as writers that file into that folder ask.</summary>
public static class SequenceFolders
{
+20 -4
View File
@@ -90,14 +90,30 @@ internal sealed class SequenceWriter(ArchiveServiceOptions options)
public ArchiveServiceOptions Options => options;
/// <summary>Holds the sequence exclusively until disposed.</summary>
public async Task<IAsyncDisposable> LockAsync(ArchivePaths archive, Guid sequenceId, CancellationToken cancellationToken)
public Task<IAsyncDisposable> LockAsync(ArchivePaths archive, Guid sequenceId, CancellationToken cancellationToken) =>
LockAsync(archive, sequenceId, null, cancellationToken);
/// <summary>
/// Holds the sequence exclusively until disposed, waiting at most <paramref name="wait"/> for this process's other writers
/// and for the lease (the options' lease wait when null).
/// </summary>
/// <exception cref="LeaseUnavailableException">Another writer kept the sequence for longer than the wait.</exception>
public async Task<IAsyncDisposable> LockAsync(ArchivePaths archive, Guid sequenceId, TimeSpan? wait, CancellationToken cancellationToken)
{
var name = $"seq-{sequenceId:N}";
var gate = _gates.GetOrAdd(sequenceId, _ => new SemaphoreSlim(1, 1));
await gate.WaitAsync(cancellationToken).ConfigureAwait(false);
if (wait is { } limit)
{
if (!await gate.WaitAsync(limit, cancellationToken).ConfigureAwait(false)) throw new LeaseUnavailableException(name, null);
}
else
{
await gate.WaitAsync(cancellationToken).ConfigureAwait(false);
}
try
{
var lease = await LeaseFile.AcquireAsync(archive.LocksDirectory, $"seq-{sequenceId:N}", options.Owner, options.LeaseWait,
options.LeaseDuration, cancellationToken).ConfigureAwait(false);
var lease = await LeaseFile.AcquireAsync(archive.LocksDirectory, name, options.Owner, wait ?? options.LeaseWait, options.LeaseDuration,
cancellationToken).ConfigureAwait(false);
return new Held(gate, lease);
}
catch