feat: owner review 2 phase 4a: Reorganize sequences after import (#12)
CI / Build and test (push) Successful in 9m15s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 15m35s
CI / PostgreSQL 16 integration (push) Successful in 7m26s
CI / PostgreSQL 17 integration (push) Successful in 6m47s
CI / Docker image (push) Successful in 59s
Release / Server image (push) Successful in 1m24s
CI / Build and test (push) Successful in 9m15s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 6s
Release / Build, test and publish (push) Successful in 15m35s
CI / PostgreSQL 16 integration (push) Successful in 7m26s
CI / PostgreSQL 17 integration (push) Successful in 6m47s
CI / Docker image (push) Successful in 59s
Release / Server image (push) Successful in 1m24s
- Reorganize… on the web panel and the desktop: folder, file and title templates applied to existing sequences, with a dry run and an explicit Apply that runs as a job. - One naming rule (FrameNaming) for import, upload and Reorganize. - Crash-safe plan and file journals, held plans, stale-plan refusal; exports move with their folder. - Writers refuse a folder another program moved or gave to another sequence. - Server: POST /api/v1/archive/reorganize with a bounded plan cache; template rules. - Phase 3 docs and translations merged; strings in all 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 #12.
This commit is contained in:
1 parent
9aa818ed47
commit
7e4a3b481d
416 files changed
+15304
-1572
No files matched your search
@@ -177,12 +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. 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
|
||||
{
|
||||
@@ -222,9 +226,15 @@ public sealed class SyncService
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
else if (resolution == SyncResolution.SaveBoth && (saved = await SaveCopyAsync(local, cancellationToken).ConfigureAwait(false)) is null)
|
||||
{
|
||||
// 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
|
||||
{
|
||||
if (resolution == SyncResolution.SaveBoth) saved = await SaveCopyAsync(local, cancellationToken).ConfigureAwait(false);
|
||||
var theirs = SyncPayload.Of(dto, manifest!.SettingsJson);
|
||||
if (await ApplyLocallyAsync(local, theirs, Positions(remote, local, manifest), cancellationToken).ConfigureAwait(false) is { } applied)
|
||||
{
|
||||
@@ -232,9 +242,11 @@ 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;
|
||||
if (saved is not null) File.Delete(saved);
|
||||
moved = await FolderMovedAsync(local, cancellationToken).ConfigureAwait(false);
|
||||
if (saved is not null) await DeleteCopyAsync(local, saved, cancellationToken).ConfigureAwait(false);
|
||||
saved = null;
|
||||
}
|
||||
}
|
||||
@@ -252,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);
|
||||
@@ -721,8 +734,9 @@ public sealed class SyncService
|
||||
/// sequence's lease, which the editor's saves and the archive's frame commits take too, and only while the local copy
|
||||
/// is still at the settings version <paramref name="local"/> was read at. The settings' frame positions are moved to
|
||||
/// this copy's frames as they are under the lease (<paramref name="positions"/>). Null when an edit was saved on this
|
||||
/// PC since, or the frames of either copy could not be read as one state: nothing is written then. A payload the local
|
||||
/// copy already holds writes nothing, so it needs neither a writable archive nor the lease.
|
||||
/// PC since, the frames of either copy could not be read as one state, or the copy is not in the folder this index has
|
||||
/// (another index moved it): nothing is written then. A payload the local copy already holds writes nothing, so it
|
||||
/// needs neither a writable archive nor the lease.
|
||||
/// </summary>
|
||||
private async Task<Sequence?> ApplyLocallyAsync(Sequence local, SyncPayload payload, SyncPositions positions, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -734,12 +748,16 @@ public sealed class SyncService
|
||||
?? throw new InvalidDataException($"Archive {local.ArchiveId} is not indexed.");
|
||||
var paths = new ArchivePaths(archive.RootPath);
|
||||
ArchiveVolume.EnsureWritable(paths);
|
||||
var folder = paths.Sequence(local.Folder);
|
||||
await using (await _writer.LockAsync(paths, local.Id, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
// The frames cannot change under the lease: the positions are moved to them as they are now.
|
||||
if (await positions.ToLocalAsync(payload.SettingsJson, local.SettingsVersion, cancellationToken).ConfigureAwait(false) is not { } current) return null;
|
||||
var row = current.Local;
|
||||
// The folder too: a Reorganize moves it and its row under this lease. One another index moved is found by the next
|
||||
// scan; nothing is written until then, so the folder it left is not created again, nor written in when it holds
|
||||
// another sequence now.
|
||||
var folder = paths.Sequence(row.Folder);
|
||||
if (!SequenceFolders.Holds(folder, row.Id)) return null;
|
||||
payload = payload with { SettingsJson = current.SettingsJson };
|
||||
var metadata = !payload.SameMetadata(SyncPayload.Of(row));
|
||||
var settings = !SyncRules.SameSettings(payload.SettingsJson, row.SettingsJson);
|
||||
@@ -789,20 +807,70 @@ public sealed class SyncService
|
||||
|
||||
/// <summary>
|
||||
/// "Save both": this PC's project is kept next to <c>project.json</c> as <c>project.this-pc-<local time>.json</c>
|
||||
/// before the server's replaces it; returns that file.
|
||||
/// before the server's replaces it; returns that file. Written under the sequence's lease into its folder as the index
|
||||
/// has it then: a Reorganize may have moved it while the server was asked, and the folder it left is never created again.
|
||||
/// Null, with nothing written, when the sequence is not in that folder (another index moved it, and maybe another
|
||||
/// sequence into it; the next scan finds them, <see cref="SequenceFolders.Holds"/>).
|
||||
/// </summary>
|
||||
private async Task<string> SaveCopyAsync(Sequence local, CancellationToken cancellationToken)
|
||||
private async Task<string?> SaveCopyAsync(Sequence local, CancellationToken cancellationToken)
|
||||
{
|
||||
var archive = await _db.Archives.GetAsync(local.ArchiveId, cancellationToken).ConfigureAwait(false)
|
||||
?? throw new InvalidDataException($"Archive {local.ArchiveId} is not indexed.");
|
||||
var folder = new ArchivePaths(archive.RootPath).Sequence(local.Folder);
|
||||
Directory.CreateDirectory(folder.MetaDirectory);
|
||||
var path = Path.Combine(folder.MetaDirectory, SavedCopyName(DateTime.Now));
|
||||
AtomicFile.WriteAllText(path, SyncRules.NormalizeSettings(local.SettingsJson));
|
||||
var paths = new ArchivePaths(archive.RootPath);
|
||||
ArchiveVolume.EnsureWritable(paths);
|
||||
string path;
|
||||
await using (await _writer.LockAsync(paths, local.Id, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
var folder = await SequenceWriter.FolderAsync(_db, paths, local, cancellationToken).ConfigureAwait(false);
|
||||
if (!SequenceFolders.Holds(folder, local.Id)) return null;
|
||||
Directory.CreateDirectory(folder.MetaDirectory);
|
||||
path = Path.Combine(folder.MetaDirectory, SavedCopyName(DateTime.Now));
|
||||
AtomicFile.WriteAllText(path, SyncRules.NormalizeSettings(local.SettingsJson));
|
||||
}
|
||||
Log.Info(LogCategory, $"Settings of {local.DisplayTitle} kept as {path}");
|
||||
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 maybe another sequence into that folder), 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) && !SequenceFolders.Holds(paths.Sequence(row.Folder), row.Id);
|
||||
}
|
||||
|
||||
/// <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
|
||||
/// be reached (the folder gone or another sequence's now, the sequence busy, the archive offline) stays, as one more
|
||||
/// copy of this PC's version.
|
||||
/// </summary>
|
||||
private async Task DeleteCopyAsync(Sequence local, string saved, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var archive = await _db.Archives.GetAsync(local.ArchiveId, cancellationToken).ConfigureAwait(false)
|
||||
?? throw new InvalidDataException($"Archive {local.ArchiveId} is not indexed.");
|
||||
var paths = new ArchivePaths(archive.RootPath);
|
||||
await using (await _writer.LockAsync(paths, local.Id, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
var folder = await SequenceWriter.FolderAsync(_db, paths, local, cancellationToken).ConfigureAwait(false);
|
||||
if (SequenceFolders.Holds(folder, local.Id) && Directory.Exists(folder.MetaDirectory))
|
||||
File.Delete(Path.Combine(folder.MetaDirectory, Path.GetFileName(saved)));
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException)
|
||||
{
|
||||
Log.Warning(LogCategory, $"The copy {saved} of {local.DisplayTitle}'s settings could not be deleted", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The file name of a "Save both" copy kept at <paramref name="localTime"/>.</summary>
|
||||
public static string SavedCopyName(DateTime localTime) =>
|
||||
string.Create(CultureInfo.InvariantCulture, $"{SavedCopyPrefix}{localTime.ToString(SavedCopyTimeFormat, CultureInfo.InvariantCulture)}.json");
|
||||
|
||||
Reference in new issue
Block a user