fix(copies): close the fifth verification round of owner review 6
The metered hold now records the jobs it paused in the index and forgets any job the user pauses, resumes, retries or cancels, so it never resumes a pause of the user's and still resumes its own after a restart. Drop... reports why its dry run is blocked instead of asking first, and dropping the version Main uses lets Main use the version that stays, with its hero and keyframes. That version reads "In Main". Merges: - A re-plan no longer hashes the other's photos again. - A resumed merge verifies photos flagged damaged while it waited. - A merge is blocked while the other's folder holds photos the index has not read; this is checked again under the lease before the trash. - Choose each offers Keep both, Kept and Other, and blocks until every differing photo is chosen. - Classes are named by role. The Compare dialog: - Its headings stay over their columns. - The Projects part scrolls. - Every confirmation line carries its own prefix, and a merge's facts carry none. - A server card in a match offers Compare... alone. The Italian strings follow the glossary. Finding 9 (a local drop counting 0 photos) is not reproduced; a test now keeps the count at 2. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2c06e7ac2b
commit
bf7701d279
159 files changed
+1759
-126
No files matched your search
@@ -518,10 +518,12 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
|
||||
var drop = await _db.Sequences.GetAsync(journal.DropId, _ct).ConfigureAwait(false) ?? throw Changed(_dropTitle);
|
||||
if (drop.FramesVersion != journal.DropFramesVersion) throw Changed(_dropTitle);
|
||||
EnsureDropReadable(drop);
|
||||
await EnsureFolderReadAsync(drop).ConfigureAwait(false);
|
||||
var keepFrames = await ProcessingFrames.ListAsync(_db, journal.KeepId, _ct).ConfigureAwait(false);
|
||||
var dropFrames = (await ProcessingFrames.ListAsync(_db, journal.DropId, _ct).ConfigureAwait(false))
|
||||
.Where(f => (f.Flags & CopySides.UnusableFlags) == 0).ToList();
|
||||
var total = keepFrames.Count + dropFrames.Count;
|
||||
var allDrop = await ProcessingFrames.ListAsync(_db, journal.DropId, _ct).ConfigureAwait(false);
|
||||
var dropFrames = allDrop.Where(f => (f.Flags & CopySides.UnusableFlags) == 0).ToList();
|
||||
var flagged = allDrop.Where(f => (f.Flags & CopySides.UnusableFlags) != 0).ToList();
|
||||
var total = keepFrames.Count + dropFrames.Count + flagged.Count;
|
||||
var done = 0;
|
||||
|
||||
// What the kept sequence holds now, hashed again.
|
||||
@@ -583,10 +585,96 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
|
||||
foreach (var sha in failed.Select(f => f.Sha256).Distinct(StringComparer.Ordinal))
|
||||
if (!journal.SettledElsewhere.Contains(sha)) journal.SettledElsewhere.Add(sha);
|
||||
}
|
||||
await VerifyFlaggedAsync(flagged, held, done, total).ConfigureAwait(false);
|
||||
journal.VerifiedDropFramesVersion = drop.FramesVersion;
|
||||
Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The plan's damaged-photo rule again (design §5d; owner Q2): a frame of the other a verify flagged Corrupt, or Missing
|
||||
/// although its file is back, changes no frames version, so one flagged since the plan was never listed. Each such
|
||||
/// frame whose file is there is hashed now (its recorded hash says nothing of it) and must be held by the kept
|
||||
/// sequence (hashed again above), be a last copy the plan listed, or be held by another sequence of this index.
|
||||
/// Otherwise, or when the file cannot be read, the merge stops and is planned again, where the plan shows the block.
|
||||
/// </summary>
|
||||
private async Task VerifyFlaggedAsync(IReadOnlyList<Frame> flagged, Dictionary<string, Guid> held, int done, int total)
|
||||
{
|
||||
var elsewhere = new List<(Guid FrameId, string Sha256)>();
|
||||
foreach (var frame in flagged)
|
||||
{
|
||||
_ct.ThrowIfCancellationRequested();
|
||||
await context.ReportAsync(Done(), Total, new JobDetail(JobStep.Verify, frame.FileName, ++done, total)).ConfigureAwait(false);
|
||||
var path = _dropPaths.FromRelative(frame.RelativePath);
|
||||
if (!File.Exists(path)) continue;
|
||||
string? sha;
|
||||
try
|
||||
{
|
||||
sha = await HashAsync(path).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
ForgetJournal();
|
||||
throw new InvalidOperationException(Loc.L("Errors.Copies.DamagedPhotos", _dropTitle), ex);
|
||||
}
|
||||
if (sha is null) continue;
|
||||
if (!journal.FlaggedVerified.Contains(frame.Id)) journal.FlaggedVerified.Add(frame.Id);
|
||||
if (held.TryGetValue(sha, out var keepFrame))
|
||||
{
|
||||
journal.Verified[frame.Id] = new MergeVerified(sha, keepFrame);
|
||||
continue;
|
||||
}
|
||||
if (journal.Absent.Contains(sha))
|
||||
{
|
||||
if (!journal.Settled.Contains(frame.Id)) journal.Settled.Add(frame.Id);
|
||||
continue;
|
||||
}
|
||||
elsewhere.Add((frame.Id, sha));
|
||||
}
|
||||
if (elsewhere.Count == 0) return;
|
||||
var others = await new CopySides(_db).HeldElsewhereAsync([.. elsewhere.Select(f => f.Sha256)], [journal.DropId, journal.KeepId], _ct)
|
||||
.ConfigureAwait(false);
|
||||
if (elsewhere.Any(f => !others.Contains(f.Sha256)))
|
||||
{
|
||||
ForgetJournal();
|
||||
throw new InvalidOperationException(Loc.L("Errors.Copies.DamagedPhotos", _dropTitle));
|
||||
}
|
||||
foreach (var (frameId, sha) in elsewhere)
|
||||
{
|
||||
if (!journal.Settled.Contains(frameId)) journal.Settled.Add(frameId);
|
||||
if (!journal.SettledElsewhere.Contains(sha)) journal.SettledElsewhere.Add(sha);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The other's folder is as this index last read it (<see cref="SequenceMerger.FolderChangedAsync"/>): photos copied in
|
||||
/// by hand or filed by another index sharing the archive would otherwise go to the trash unread. Asked at the verify
|
||||
/// and before the links stage, which rewrites the other's sidecar without recording the folder's stamps.
|
||||
/// </summary>
|
||||
private async Task EnsureFolderReadAsync(Sequence drop)
|
||||
{
|
||||
if (!await owner.Merger.FolderChangedAsync(_dropArchive, _dropPaths, drop, _ct).ConfigureAwait(false)) return;
|
||||
ForgetJournal();
|
||||
throw new InvalidOperationException(Loc.L("Errors.Copies.FolderChanged", _dropTitle));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// At the trash, under the other's lease (after the links stage rewrote its sidecar): no photo was copied in or removed
|
||||
/// since this index last read its folder, and its sidecar's frames are still those the verify read.
|
||||
/// </summary>
|
||||
private async Task<bool> FolderStillReadAsync(SequencePaths folder, CancellationToken ct)
|
||||
{
|
||||
if (await owner.Archives.Indexer.PhotosChangedAsync(_dropArchive, folder, ct).ConfigureAwait(false)) return false;
|
||||
if (!File.Exists(folder.ManifestPath)) return true;
|
||||
try
|
||||
{
|
||||
return ManifestStore.ReadSequence(folder.ManifestPath).Versions.Frames == journal.VerifiedDropFramesVersion;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or System.Text.Json.JsonException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<string?> HashAsync(string path)
|
||||
{
|
||||
try
|
||||
@@ -759,7 +847,7 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
|
||||
if (journal.LinksUndo is null)
|
||||
{
|
||||
// Nothing of the other is touched while a check before the trash can still abandon the merge.
|
||||
await CheckTrashAsync(drop).ConfigureAwait(false);
|
||||
await CheckTrashAsync(drop, beforeLinks: true).ConfigureAwait(false);
|
||||
await using (await owner.Archives.Writer.LockAsync(keepPaths, journal.KeepId, _ct).ConfigureAwait(false))
|
||||
await PlanTrashAsync().ConfigureAwait(false);
|
||||
journal.LinksUndo = new MergeLinksUndo(KeysOf(keepPaths, keep), KeysOf(_dropPaths, drop), _dropArchive.Id,
|
||||
@@ -822,7 +910,7 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
|
||||
/// unsent workspace work, no work saved into the other since the plan, the other at the frames version the verify read
|
||||
/// and readable. Returns that frames version.
|
||||
/// </summary>
|
||||
private async Task<int> CheckTrashAsync(Sequence drop)
|
||||
private async Task<int> CheckTrashAsync(Sequence drop, bool beforeLinks = false)
|
||||
{
|
||||
if (await owner.Workspace.HasUnsentAsync(journal.DropId, _ct).ConfigureAwait(false))
|
||||
throw new InvalidOperationException(Loc.L("Errors.Copies.Unsent", _dropTitle));
|
||||
@@ -835,6 +923,7 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
|
||||
var expected = journal.VerifiedDropFramesVersion ?? throw Changed(_dropTitle);
|
||||
if (drop.FramesVersion != expected) throw Changed(_dropTitle);
|
||||
EnsureDropReadable(drop);
|
||||
if (beforeLinks) await EnsureFolderReadAsync(drop).ConfigureAwait(false);
|
||||
return expected;
|
||||
}
|
||||
|
||||
@@ -859,12 +948,14 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
|
||||
var plan = await PlanTrashAsync().ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await owner.Archives.Trash.DeleteAsync(plan, null, null, _ct, journal.JobId, new Dictionary<Guid, int> { [journal.DropId] = expected })
|
||||
.ConfigureAwait(false);
|
||||
await owner.Archives.Trash.DeleteAsync(plan, null, null, _ct, journal.JobId, new Dictionary<Guid, int> { [journal.DropId] = expected },
|
||||
FolderStillReadAsync).ConfigureAwait(false);
|
||||
}
|
||||
catch (StaleDeletePlanException ex)
|
||||
{
|
||||
throw new InvalidOperationException(Loc.L("Errors.Copies.Changed", _dropTitle), ex);
|
||||
// Photos copied into the other since the verify (a scan reads them), or its frames moved: planned again.
|
||||
ForgetJournal();
|
||||
throw new InvalidOperationException(Loc.L("Errors.Copies.FolderChanged", _dropTitle), ex);
|
||||
}
|
||||
}
|
||||
context.Log(Loc.L("Archive.Log.MergeTrashed", _dropTitle));
|
||||
@@ -908,6 +999,13 @@ internal sealed class MergeJobHandler(ChronosDatabase db, SequenceMerger merger,
|
||||
var dropFrames = await ProcessingFrames.ListAsync(_db, journal.DropId, _ct).ConfigureAwait(false);
|
||||
if (dropFrames.Any(f => (f.Flags & CopySides.UnusableFlags) == 0 && !journal.Verified.ContainsKey(f.Id) && !journal.Settled.Contains(f.Id)))
|
||||
throw Changed(_dropTitle);
|
||||
// A frame flagged Missing or Corrupt since the verify, its file there: never hashed as such, so planned again.
|
||||
if (dropFrames.Any(f => (f.Flags & CopySides.UnusableFlags) != 0 && !journal.FlaggedVerified.Contains(f.Id)
|
||||
&& File.Exists(_dropPaths.FromRelative(f.RelativePath))))
|
||||
{
|
||||
ForgetJournal();
|
||||
throw new InvalidOperationException(Loc.L("Errors.Copies.DamagedPhotos", _dropTitle));
|
||||
}
|
||||
|
||||
// The photos a third sequence held at the verify: one it no longer holds would leave only with the other, never
|
||||
// listed as a last copy. Planned again, the plan lists it.
|
||||
|
||||
@@ -112,6 +112,12 @@ internal sealed class MergeJournal
|
||||
/// <summary>The dropped sequence's frames version the verify read: the trash refuses another.</summary>
|
||||
public int? VerifiedDropFramesVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The dropped sequence's frames flagged Missing or Corrupt whose file was there at the verify, each hashed then and
|
||||
/// settled (held by the kept sequence, a last copy, or held elsewhere): one flagged since keeps the trash from running.
|
||||
/// </summary>
|
||||
public List<Guid> FlaggedVerified { get; set; } = [];
|
||||
|
||||
public List<string> Replaced { get; set; } = [];
|
||||
|
||||
/// <summary>Keys of losing versions a refused trash step kept (reported at the end).</summary>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
@@ -32,6 +33,21 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
|
||||
private readonly CopySides _sides = sides ?? throw new ArgumentNullException(nameof(sides));
|
||||
private readonly DbAccess _access = new(db.Database);
|
||||
|
||||
/// <summary>
|
||||
/// The hashes the dry runs read of the other sequence's files, by frame, with the size and last write time they were read
|
||||
/// at: a plan made again (every change of choice in the dialog) reads only the files that are new or changed. Kept in
|
||||
/// memory only, as a dry run writes nothing to the index; the job's Verify stage hashes every file again.
|
||||
/// </summary>
|
||||
private readonly ConcurrentDictionary<Guid, (long Length, DateTime Written, string Sha256)> _hashes = new();
|
||||
|
||||
/// <summary>The most hashes <see cref="_hashes"/> keeps before it starts again.</summary>
|
||||
private const int HashesKept = 200_000;
|
||||
|
||||
private int _filesHashed;
|
||||
|
||||
/// <summary>Files the dry runs read and hashed so far (tests: a plan made again reads only what changed).</summary>
|
||||
internal int FilesHashed => Volatile.Read(ref _filesHashed);
|
||||
|
||||
/// <summary>The name a server key is shown by (default: the key): the links a merge moves and the server both are linked to.</summary>
|
||||
public Func<string, string?>? ServerNames { get; init; }
|
||||
|
||||
@@ -98,6 +114,9 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
|
||||
var online = ArchiveVolume.Probe(keepPaths) == ArchiveAvailability.Online && ArchiveVolume.Probe(dropPaths) == ArchiveAvailability.Online;
|
||||
if (!online) blocks.Add(CopyBlock.ArchiveOffline);
|
||||
else if (Moved(keepPaths, keepRow) || Moved(dropPaths, dropRow)) blocks.Add(CopyBlock.FolderMoved);
|
||||
// Photos of the other this index has not read (copied in by hand, filed by another index sharing the archive) would
|
||||
// go to the trash with its folder, never copied nor listed: a scan reads them first.
|
||||
else if (await FolderChangedAsync(dropArchive, dropPaths, dropRow, ct).ConfigureAwait(false)) blocks.Add(CopyBlock.FolderChanged);
|
||||
if (await BusyAsync([keep, drop, keepRow.ArchiveId, dropRow.ArchiveId], exceptJob, ct).ConfigureAwait(false)) blocks.Add(CopyBlock.Busy);
|
||||
if (context.UnsentWorkspaceSequences.Contains(drop)) blocks.Add(CopyBlock.UnsentWorkspace);
|
||||
|
||||
@@ -114,6 +133,7 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
|
||||
}
|
||||
var steps = new List<PhotoStep>();
|
||||
var excluded = new List<string>();
|
||||
var unchosen = 0;
|
||||
foreach (var photo in comparison.Photos)
|
||||
{
|
||||
switch (photo.Class)
|
||||
@@ -123,6 +143,9 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
|
||||
steps.Add(Step(photo.Key, PhotoAction.Fetch, photo.There!));
|
||||
break;
|
||||
case PhotoClass.Differs:
|
||||
// Under Choose each a photo nobody chose blocks: its other version would go to the trash unasked (Leave,
|
||||
// which a merge does not offer, keeps the kept sequence's version as Kept does).
|
||||
if (choices.Photos == CopyPhotoPolicy.ChoosePerPhoto && !choices.PerPhoto.ContainsKey(photo.Key)) unchosen++;
|
||||
var choice = choices.Photos switch
|
||||
{
|
||||
CopyPhotoPolicy.Union => PhotoChoice.KeepBoth,
|
||||
@@ -136,6 +159,7 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (unchosen > 0) blocks.Add(CopyBlock.PhotosUnchosen);
|
||||
|
||||
// Last copies: drop originals nothing will hold once the copies are made (losers, tombstoned in keep, converted), and
|
||||
// keep's losing versions nothing else holds.
|
||||
@@ -243,6 +267,7 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
|
||||
LinkNames = [.. moved.Select(ServerName)],
|
||||
BothLinkedServer = bothLinked is null ? null : ServerName(bothLinked),
|
||||
DeletedInOther = comparison.Photos.Count(p => p.Class == PhotoClass.DeletedThere),
|
||||
PhotosUnchosen = unchosen,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -267,8 +292,8 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
|
||||
}
|
||||
try
|
||||
{
|
||||
var sha = await ContentHash.Sha256Async(dropPaths.FromRelative(frame.RelativePath), null, ct).ConfigureAwait(false);
|
||||
photos.Add(photo with { Sha256 = sha.ToLowerInvariant() });
|
||||
var sha = await HashAsync(frame.Id, dropPaths.FromRelative(frame.RelativePath), ct).ConfigureAwait(false);
|
||||
photos.Add(photo with { Sha256 = sha });
|
||||
changed = true;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
@@ -297,7 +322,7 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
|
||||
if (!File.Exists(path)) continue;
|
||||
try
|
||||
{
|
||||
var sha = (await ContentHash.Sha256Async(path, null, ct).ConfigureAwait(false)).ToLowerInvariant();
|
||||
var sha = await HashAsync(frame.Id, path, ct).ConfigureAwait(false);
|
||||
if (!keepHolds.Contains(sha)) hashes.Add(sha);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
@@ -310,6 +335,48 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
|
||||
return hashes.Any(h => !held.Contains(h));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The SHA-256 (lower-case) of the other's file <paramref name="path"/> of frame <paramref name="frameId"/>: the one read
|
||||
/// before while the file keeps its size and last write time (<see cref="_hashes"/>), else read now.
|
||||
/// </summary>
|
||||
private async Task<string> HashAsync(Guid frameId, string path, CancellationToken ct)
|
||||
{
|
||||
var file = new FileInfo(path);
|
||||
if (!file.Exists) throw new FileNotFoundException("The photo is not there.", path);
|
||||
var (length, written) = (file.Length, file.LastWriteTimeUtc);
|
||||
if (_hashes.TryGetValue(frameId, out var known) && known.Length == length && known.Written == written) return known.Sha256;
|
||||
var sha = (await ContentHash.Sha256Async(path, null, ct).ConfigureAwait(false)).ToLowerInvariant();
|
||||
Interlocked.Increment(ref _filesHashed);
|
||||
if (_hashes.Count >= HashesKept) _hashes.Clear();
|
||||
_hashes[frameId] = (length, written, sha);
|
||||
return sha;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the other sequence's folder holds photos this index has not read: photos copied in or removed since the
|
||||
/// photo directory's recorded stamp (<see cref="ArchiveIndexer.PhotosChangedAsync"/>), or a sidecar whose frames are not
|
||||
/// the row's (another index of the archive filed or dropped photos). A sidecar that cannot be read, or names another
|
||||
/// sequence, counts. A sidecar rewritten without new frames does not (the merge's own session-key moves rewrite it).
|
||||
/// </summary>
|
||||
internal async Task<bool> FolderChangedAsync(Archive archive, ArchivePaths paths, Sequence row, CancellationToken ct)
|
||||
{
|
||||
var folder = paths.Sequence(row.Folder);
|
||||
if (!File.Exists(folder.ManifestPath)) return false;
|
||||
SequenceManifest manifest;
|
||||
try
|
||||
{
|
||||
manifest = ManifestStore.ReadSequence(folder.ManifestPath);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or JsonException)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (manifest.Id != row.Id) return true;
|
||||
var indexed = await _db.Sequences.GetAsync(row.Id, ct).ConfigureAwait(false);
|
||||
return indexed is null || indexed.FramesVersion != manifest.Versions.Frames
|
||||
|| await _archives.Indexer.PhotosChangedAsync(archive, folder, ct).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Queues the job that applies <paramref name="plan"/>: the pair goes to <see cref="CopyState.Integrating"/> (its state
|
||||
/// before kept as the previous one), the job targets the kept sequence, then the other (both held from other jobs).
|
||||
@@ -360,7 +427,9 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
|
||||
return block switch
|
||||
{
|
||||
CopyBlock.Busy => Loc.L("Errors.Copies.Busy"),
|
||||
CopyBlock.ArchiveOffline or CopyBlock.FolderMoved or CopyBlock.ChangedFile or CopyBlock.DamagedPhotos => Loc.L("Errors.Copies." + block, dropTitle),
|
||||
CopyBlock.ArchiveOffline or CopyBlock.FolderMoved or CopyBlock.ChangedFile or CopyBlock.DamagedPhotos or CopyBlock.FolderChanged
|
||||
=> Loc.L("Errors.Copies." + block, dropTitle),
|
||||
CopyBlock.PhotosUnchosen => Loc.L("Errors.Copies.PhotosUnchosen"),
|
||||
CopyBlock.NoSpace => Loc.L("Errors.Copies.NoSpace", keepTitle, Size(plan.CopyBytes + SpaceReserve)),
|
||||
CopyBlock.BothLinked => Loc.L("Errors.Copies.BothLinked", plan.BothLinkedServer ?? string.Empty),
|
||||
CopyBlock.UnsentWorkspace => Loc.L("Errors.Copies.Unsent", dropTitle),
|
||||
|
||||
@@ -206,8 +206,14 @@ public sealed partial class SequenceTrash
|
||||
/// merge: a photo added to the dropped sequence meanwhile refuses that step with <see cref="StaleDeletePlanException"/>,
|
||||
/// nothing of it moved). Sequences it does not name are not checked.
|
||||
/// </param>
|
||||
/// <param name="stillAsPlanned">
|
||||
/// Asked of each sequence's folder under its lease just before it moves (a merge: no photo copied into the dropped
|
||||
/// sequence's folder since its verify); false refuses that step with <see cref="StaleDeletePlanException"/>, nothing of
|
||||
/// it moved. Null: not asked.
|
||||
/// </param>
|
||||
public async Task<IReadOnlyList<TrashEntry>> DeleteAsync(DeletePlan plan, string? deletedBy = null, IProgress<int>? progress = null,
|
||||
CancellationToken cancellationToken = default, Guid? exceptJob = null, IReadOnlyDictionary<Guid, int>? expectedFramesVersions = null)
|
||||
CancellationToken cancellationToken = default, Guid? exceptJob = null, IReadOnlyDictionary<Guid, int>? expectedFramesVersions = null,
|
||||
Func<SequencePaths, CancellationToken, Task<bool>>? stillAsPlanned = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(plan);
|
||||
await RevalidateAsync(plan, exceptJob, cancellationToken).ConfigureAwait(false);
|
||||
@@ -217,7 +223,7 @@ public sealed partial class SequenceTrash
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var step = plan.Steps[i];
|
||||
int? expected = expectedFramesVersions is not null && expectedFramesVersions.TryGetValue(step.Sequence.Id, out var version) ? version : null;
|
||||
if (await DeleteOneAsync(step, deletedBy, expected, cancellationToken).ConfigureAwait(false) is { } entry) entries.Add(entry);
|
||||
if (await DeleteOneAsync(step, deletedBy, expected, stillAsPlanned, cancellationToken).ConfigureAwait(false) is { } entry) entries.Add(entry);
|
||||
progress?.Report(i + 1);
|
||||
}
|
||||
return entries;
|
||||
@@ -381,7 +387,8 @@ public sealed partial class SequenceTrash
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<TrashEntry?> DeleteOneAsync(DeleteStep step, string? deletedBy, int? expectedFramesVersion, CancellationToken cancellationToken)
|
||||
private async Task<TrashEntry?> DeleteOneAsync(DeleteStep step, string? deletedBy, int? expectedFramesVersion,
|
||||
Func<SequencePaths, CancellationToken, Task<bool>>? stillAsPlanned, CancellationToken cancellationToken)
|
||||
{
|
||||
var sequence = step.Sequence;
|
||||
var archive = await _db.Archives.GetAsync(sequence.ArchiveId, cancellationToken).ConfigureAwait(false)
|
||||
@@ -405,6 +412,7 @@ public sealed partial class SequenceTrash
|
||||
var folder = paths.Sequence(sequence.Folder);
|
||||
if (!Directory.Exists(folder.Folder) || (File.Exists(folder.ManifestPath) && SidecarId(folder.ManifestPath) != sequence.Id))
|
||||
throw new StaleDeletePlanException(sequence.Id);
|
||||
if (stillAsPlanned is not null && !await stillAsPlanned(folder, cancellationToken).ConfigureAwait(false)) throw new StaleDeletePlanException(sequence.Id);
|
||||
// A photo deletion, a frame replacement, a restore from the trash or an ingest a crash interrupted is settled first,
|
||||
// as any writer does (SequenceWriter.ReadLocked): neither its journal nor the files it moved travel into this entry,
|
||||
// where emptying it would erase them while their own entry still lists them. A restore or a replacement whose entry
|
||||
|
||||
@@ -333,7 +333,7 @@ public sealed class CopyEngine(SyncService sync, ArchiveService archives, Integr
|
||||
// The photo stays (its other version); this version's content may still be held nowhere else.
|
||||
var elsewhere = await _sides.HeldElsewhereAsync([sha], [sequenceId], ct).ConfigureAwait(false);
|
||||
IReadOnlyList<LastCopy> lasts = elsewhere.Contains(sha) ? [] : [new LastCopy(sha, CopySide.ThisPc, name, size)];
|
||||
return new OwnVersionDropPlan(plan, partner, partnerName, partnerSha, lasts);
|
||||
return new OwnVersionDropPlan(plan, partner, partnerName, partnerSha, lasts) { Sha256 = sha, SettingsVersion = sequence.SettingsVersion };
|
||||
}
|
||||
|
||||
public async Task<int> DropOwnVersionAsync(OwnVersionDropPlan plan, CancellationToken ct)
|
||||
@@ -349,13 +349,99 @@ public sealed class CopyEngine(SyncService sync, ArchiveService archives, Integr
|
||||
Log.Info(LogCategory, $"Sequence {sequenceId}: the version kept is no longer there; nothing went to the trash");
|
||||
throw new StaleCopyPlanException(Loc.L("Errors.Copies.OtherVersionGone"));
|
||||
}
|
||||
if ((await Db.Sequences.GetAsync(sequenceId, ct).ConfigureAwait(false))?.FramesVersion != plan.Plan.Sequence.FramesVersion)
|
||||
var row = await Db.Sequences.GetAsync(sequenceId, ct).ConfigureAwait(false);
|
||||
if (row?.FramesVersion != plan.Plan.Sequence.FramesVersion || (plan.SettingsVersion is { } settings && row.SettingsVersion != settings))
|
||||
throw new StaleCopyPlanException();
|
||||
await _archives.FrameTrash.DeleteAsync(plan.Plan, _context(null).PcName, followUps?.Invoke(), ct).ConfigureAwait(false);
|
||||
Log.Info(LogCategory, $"Sequence {sequenceId}: one version of a photo kept in two went to its archive trash");
|
||||
if (plan.Sha256 is { Length: > 0 } dropped) await KeepInMainAsync(sequenceId, plan.PartnerSha256, dropped, plan.SettingsVersion, ct).ConfigureAwait(false);
|
||||
return plan.Plan.Frames.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// After one version of a photo kept in two went to the trash of <paramref name="sequenceId"/>: when Main used it and left
|
||||
/// out the one that stays (a Union keep-both excludes the incoming version), the one that stays is used instead, with the
|
||||
/// hero and keyframes of the one that went (<see cref="CopyPayload.KeepVersion"/>), written at the settings version the
|
||||
/// plan read (the trash moves positions without a new version).
|
||||
/// </summary>
|
||||
/// <exception cref="StaleCopyPlanException">Main changed since the plan: the version is in the trash, Main is left as it is.</exception>
|
||||
private async Task KeepInMainAsync(Guid sequenceId, string keepKey, string droppedKey, int? expectedSettings, CancellationToken ct)
|
||||
{
|
||||
if (await Db.Sequences.GetAsync(sequenceId, ct).ConfigureAwait(false) is not { } row) return;
|
||||
var photos = await SequencePayloadWriter.PhotosAsync(Db, sequenceId, null, ct).ConfigureAwait(false);
|
||||
SyncPayload? kept;
|
||||
try
|
||||
{
|
||||
kept = CopyPayload.KeepVersion(CopyPayload.Portable(SyncPayload.Of(row), photos), keepKey, droppedKey);
|
||||
}
|
||||
catch (Exception ex) when (ex is System.Text.Json.JsonException or InvalidDataException)
|
||||
{
|
||||
// Settings that are not a project of this Chronos: nothing of Main is read as a choice of versions.
|
||||
return;
|
||||
}
|
||||
if (kept is null) return;
|
||||
try
|
||||
{
|
||||
await new SequencePayloadWriter(Db, _archives).ApplyAsync(sequenceId, kept, expectedSettings ?? row.SettingsVersion, ct).ConfigureAwait(false);
|
||||
Log.Info(LogCategory, $"Sequence {sequenceId}: Main uses the version that stays");
|
||||
}
|
||||
catch (SyncConflictChangedException ex)
|
||||
{
|
||||
throw new StaleCopyPlanException(Loc.L("Errors.Copies.MainChanged", row.DisplayTitle), ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="KeepInMainAsync"/> on a server sequence (its Main changed through the API at the version read, three tries
|
||||
/// when it moves meanwhile); an account without the Edit right is told so.
|
||||
/// </summary>
|
||||
private async Task KeepInMainAsync(ISyncRemote remote, Guid remoteId, string keepKey, string droppedKey, string serverName, CancellationToken ct)
|
||||
{
|
||||
for (var attempt = 1; ; attempt++)
|
||||
{
|
||||
var dto = await remote.GetSequenceAsync(remoteId, ct).ConfigureAwait(false);
|
||||
var manifest = await remote.GetManifestAsync(remoteId, ct).ConfigureAwait(false);
|
||||
if (manifest.SettingsVersion != dto.SettingsVersion)
|
||||
{
|
||||
if (attempt >= 3) throw new StaleCopyPlanException(Loc.L("Errors.Copies.MainChanged", dto.Title ?? string.Empty));
|
||||
continue;
|
||||
}
|
||||
var captured = (await remote.ListFramesAsync(remoteId, ct).ConfigureAwait(false)).ToDictionary(f => f.Id, f => f.CapturedAt);
|
||||
var photos = new FramePhotos(manifest.Frames.Select(f =>
|
||||
(f.Index, new FramePhoto(f.Sha256.Length == 0 ? null : f.Sha256.ToLowerInvariant(), f.Size, captured.GetValueOrDefault(f.Id)))));
|
||||
SyncPayload? kept;
|
||||
try
|
||||
{
|
||||
kept = CopyPayload.KeepVersion(CopyPayload.Portable(SyncPayload.Of(dto, manifest.SettingsJson), photos), keepKey, droppedKey);
|
||||
}
|
||||
catch (Exception ex) when (ex is System.Text.Json.JsonException or InvalidDataException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (kept is null) return;
|
||||
var placed = kept with { SettingsJson = ProjectContent.Place(kept.SettingsJson ?? string.Empty, photos) };
|
||||
var frames = ProjectSettings.NamesFrames(placed.SettingsJson) ? manifest.FramesVersion : (int?)null;
|
||||
try
|
||||
{
|
||||
await remote.UpdateSequenceAsync(remoteId, placed.ToRequest(dto.SettingsVersion, frames), ct).ConfigureAwait(false);
|
||||
Log.Info(LogCategory, $"Server sequence {remoteId}: Main uses the version that stays");
|
||||
return;
|
||||
}
|
||||
catch (ChronosApiException ex) when (ex.Status == HttpStatusCode.Conflict && attempt < 3)
|
||||
{
|
||||
Log.Info(LogCategory, $"Server sequence {remoteId} changed while its Main was being set; reading it again");
|
||||
}
|
||||
catch (ChronosApiException ex) when (ex.Status == HttpStatusCode.Conflict)
|
||||
{
|
||||
throw new StaleCopyPlanException(Loc.L("Errors.Copies.MainChanged", dto.Title ?? string.Empty), ex);
|
||||
}
|
||||
catch (ChronosApiException ex) when (ex.Status == HttpStatusCode.Forbidden)
|
||||
{
|
||||
throw new InvalidOperationException(Loc.L("Errors.Copies.MainNotEdited", serverName), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- Deleted on one side ----------------
|
||||
|
||||
public async Task<TrashHerePlan> PlanTrashHereAsync(Guid copyId, IReadOnlyCollection<string> photoKeys, CancellationToken ct)
|
||||
@@ -386,6 +472,7 @@ public sealed class CopyEngine(SyncService sync, ArchiveService archives, Integr
|
||||
var sequence = await Db.Sequences.GetAsync(copy.LocalId, ct).ConfigureAwait(false) ?? throw new StaleCopyPlanException();
|
||||
var herePlan = await _archives.FrameTrash.PlanDeleteAsync(copy.LocalId, [.. mine.Select(f => f.FrameId)], sequence.FramesVersion, ct).ConfigureAwait(false);
|
||||
FrameDeletePlan? otherPlan = null;
|
||||
int? otherSettings = null;
|
||||
var (photos, bytes, version) = (0, 0L, 0);
|
||||
if (remoteId is { } id)
|
||||
{
|
||||
@@ -397,11 +484,16 @@ public sealed class CopyEngine(SyncService sync, ArchiveService archives, Integr
|
||||
{
|
||||
var other = await Db.Sequences.GetAsync(copy.OtherId!.Value, ct).ConfigureAwait(false) ?? throw new StaleCopyPlanException();
|
||||
otherPlan = await _archives.FrameTrash.PlanDeleteAsync(other.Id, [.. theirs.Select(f => f.FrameId)], other.FramesVersion, ct).ConfigureAwait(false);
|
||||
otherSettings = other.SettingsVersion;
|
||||
}
|
||||
Guid[] pairSides = copy.OtherId is { } o ? [copy.LocalId, o] : [copy.LocalId];
|
||||
var lasts = await LastCopiesAsync([.. mine.Take(1)], CopySide.ThisPc, pairSides, ct).ConfigureAwait(false);
|
||||
return new DropVersionPlan(copyId, key, partner, herePlan, otherPlan, remoteId, remoteId is null ? [] : [.. theirs.Select(f => f.FrameId)], photos, bytes,
|
||||
version, lasts);
|
||||
version, lasts)
|
||||
{
|
||||
HereSettingsVersion = sequence.SettingsVersion,
|
||||
OtherSettingsVersion = otherSettings,
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<int> DropVersionAsync(DropVersionPlan plan, ISyncRemote? remote, CancellationToken ct)
|
||||
@@ -425,7 +517,9 @@ public sealed class CopyEngine(SyncService sync, ArchiveService archives, Integr
|
||||
// The local plans are checked before the server moves anything, so a stale one moves nothing anywhere.
|
||||
foreach (var local in new[] { plan.Here, plan.Other }.OfType<FrameDeletePlan>())
|
||||
{
|
||||
if ((await Db.Sequences.GetAsync(local.Sequence.Id, ct).ConfigureAwait(false))?.FramesVersion != local.Sequence.FramesVersion)
|
||||
var row = await Db.Sequences.GetAsync(local.Sequence.Id, ct).ConfigureAwait(false);
|
||||
var settings = ReferenceEquals(local, plan.Here) ? plan.HereSettingsVersion : plan.OtherSettingsVersion;
|
||||
if (row?.FramesVersion != local.Sequence.FramesVersion || (settings is { } expected && row.SettingsVersion != expected))
|
||||
throw new StaleCopyPlanException();
|
||||
}
|
||||
var moved = 0;
|
||||
@@ -441,7 +535,18 @@ public sealed class CopyEngine(SyncService sync, ArchiveService archives, Integr
|
||||
moved += local.Frames.Count;
|
||||
}
|
||||
Log.Info(LogCategory, $"Pair {plan.CopyId}: one version of a photo kept in two went to the trash of both sides");
|
||||
await RecountAsync(copy, remote, ct).ConfigureAwait(false);
|
||||
// The photo stays (owner Q3): where Main used the version that went, it uses the one that stays, on both sides.
|
||||
try
|
||||
{
|
||||
await KeepInMainAsync(copy.LocalId, plan.PartnerKey, plan.Key, plan.HereSettingsVersion, ct).ConfigureAwait(false);
|
||||
if (plan.Other is { } other) await KeepInMainAsync(other.Sequence.Id, plan.PartnerKey, plan.Key, plan.OtherSettingsVersion, ct).ConfigureAwait(false);
|
||||
if (remoteId is { } server)
|
||||
await KeepInMainAsync(remote!, server, plan.PartnerKey, plan.Key, ServerName(copy.Server ?? remote!.Server), ct).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await RecountAsync(copy, remote, ct).ConfigureAwait(false);
|
||||
}
|
||||
return moved;
|
||||
}
|
||||
|
||||
|
||||
@@ -137,6 +137,65 @@ public static class CopyPayload
|
||||
return portable with { SettingsJson = ProjectContent.Canonical((settings with { PendingFrames = pending }).ToJson()) };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// After one version of a photo kept in two went to the trash (design §4.1, Versions; owner Q3: the photo stays): when
|
||||
/// Main left out the version that stays (<paramref name="keepKey"/>) and used the one that went
|
||||
/// (<paramref name="droppedKey"/>), the one that stays is included again; the hero and the keyframes of the one that went
|
||||
/// move to it. Keys as <see cref="ExcludeVersions"/> takes them. Null when nothing changes.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidDataException">The settings are of a newer Chronos.</exception>
|
||||
/// <exception cref="JsonException">The settings are not a project.</exception>
|
||||
public static SyncPayload? KeepVersion(SyncPayload portable, string keepKey, string droppedKey)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(portable);
|
||||
if (Photo(keepKey) is not { } keep || Photo(droppedKey) is not { } dropped) return null;
|
||||
var settings = ProjectSettings.FromJson(SyncRules.NormalizeSettings(portable.SettingsJson));
|
||||
var pending = (settings.PendingFrames ?? []).ToList();
|
||||
var k = pending.FindIndex(p => p.Occurrence == 0 && Names(p, keep));
|
||||
var d = pending.FindIndex(p => p.Occurrence == 0 && Names(p, dropped));
|
||||
var kept = k >= 0 ? pending[k] : null;
|
||||
var gone = d >= 0 ? pending[d] : null;
|
||||
var include = kept is { Excluded: true } && gone is not { Excluded: true };
|
||||
var hero = gone is { Hero: true } && kept is not { Hero: true };
|
||||
var keys = gone is { Keyframes.Count: > 0 } && kept is not { Keyframes.Count: > 0 };
|
||||
if (!include && !hero && !keys) return null;
|
||||
|
||||
var updated = (kept ?? new PendingFrame { Sha256 = keep.Sha256, Size = keep.Size, CapturedAt = keep.CapturedAt }) with
|
||||
{
|
||||
Excluded = kept is { Excluded: true } && !include,
|
||||
Hero = kept is { Hero: true } || hero,
|
||||
Keyframes = keys ? gone!.Keyframes : kept?.Keyframes ?? [],
|
||||
};
|
||||
var rest = gone is null ? null : gone with { Hero = gone.Hero && !hero, Keyframes = keys ? [] : gone.Keyframes };
|
||||
if (k >= 0) pending[k] = updated;
|
||||
else pending.Add(updated);
|
||||
if (d >= 0) pending[d] = rest!;
|
||||
pending.RemoveAll(p => p is { Excluded: false, Hero: false, Keyframes.Count: 0 } && (ReferenceEquals(p, updated) || ReferenceEquals(p, rest)));
|
||||
return portable with
|
||||
{
|
||||
SettingsJson = ProjectContent.Canonical((settings with { PendingFrames = pending.Count == 0 ? null : pending }).ToJson()),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The photos a portable payload's Main excludes from renders, by their canonical SHA-256 (lower-case): which of a
|
||||
/// photo's two versions Main leaves out. Empty for settings that are not a project of this Chronos.
|
||||
/// </summary>
|
||||
public static IReadOnlySet<string> ExcludedKeys(SyncPayload portable)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(portable);
|
||||
try
|
||||
{
|
||||
var settings = ProjectSettings.FromJson(SyncRules.NormalizeSettings(portable.SettingsJson));
|
||||
return (settings.PendingFrames ?? []).Where(p => p is { Excluded: true, Occurrence: 0, Sha256.Length: > 0 })
|
||||
.Select(p => p.Sha256!.ToLowerInvariant()).ToHashSet(StringComparer.Ordinal);
|
||||
}
|
||||
catch (Exception ex) when (ex is JsonException or InvalidDataException)
|
||||
{
|
||||
return new HashSet<string>(StringComparer.Ordinal);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Paths whose value moved between two payloads of one side (the apply-time check of design §5c step 5).</summary>
|
||||
public static IReadOnlySet<string> Moved(SyncPayload before, SyncPayload after)
|
||||
{
|
||||
|
||||
@@ -52,6 +52,15 @@ public enum CopyBlock
|
||||
|
||||
/// <summary>The other sequence of a merge holds photos a verify flagged changed or damaged: they would go to the trash unchecked.</summary>
|
||||
DamagedPhotos,
|
||||
|
||||
/// <summary>
|
||||
/// The other sequence of a merge is not as this index last read it (photos copied in by hand, or filed by another index
|
||||
/// sharing the archive): what the index has not read would go to the trash unseen. A scan settles it.
|
||||
/// </summary>
|
||||
FolderChanged,
|
||||
|
||||
/// <summary>A merge under Choose each with Different photos not chosen yet: no version of the other goes to the trash unasked.</summary>
|
||||
PhotosUnchosen,
|
||||
}
|
||||
|
||||
/// <summary>The choices of an Integrate: photo policy, per-photo choices (by photo key), per-detail sides (by path), projects.</summary>
|
||||
@@ -121,6 +130,9 @@ public sealed record MergePlan(Guid CopyId, Guid KeepId, Guid DropId, MergeChoic
|
||||
|
||||
/// <summary>Photos the kept sequence holds that the other deleted: they stay in the kept one ("Deleted in the other").</summary>
|
||||
public int DeletedInOther { get; init; }
|
||||
|
||||
/// <summary>Different photos left without a choice under Choose each (<see cref="CopyBlock.PhotosUnchosen"/>).</summary>
|
||||
public int PhotosUnchosen { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -150,7 +162,14 @@ public sealed record TrashHerePlan(FrameDeletePlan Plan, IReadOnlyList<LastCopy>
|
||||
/// the version itself when no other sequence of this index holds its content.
|
||||
/// </summary>
|
||||
public sealed record OwnVersionDropPlan(FrameDeletePlan Plan, Guid PartnerFrameId, string PartnerFileName, string PartnerSha256,
|
||||
IReadOnlyList<LastCopy> LastCopies);
|
||||
IReadOnlyList<LastCopy> LastCopies)
|
||||
{
|
||||
/// <summary>The SHA-256 of the version that goes; null when unknown (Main is then not looked at).</summary>
|
||||
public string? Sha256 { get; init; }
|
||||
|
||||
/// <summary>The sequence's settings version the plan read: the drop applies only while it holds; null for no check.</summary>
|
||||
public int? SettingsVersion { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The dry run of dropping one version of a photo kept in two versions (design §4.1, Versions): the version
|
||||
@@ -165,6 +184,12 @@ public sealed record DropVersionPlan(Guid CopyId, string Key, string PartnerKey,
|
||||
{
|
||||
/// <summary>Every frame the drop moves, on both sides.</summary>
|
||||
public int Photos => Here.Frames.Count + (Other?.Frames.Count ?? 0) + RemotePhotos;
|
||||
|
||||
/// <summary>The settings version of this PC's copy the plan read (its Main is changed at it); null for no check.</summary>
|
||||
public int? HereSettingsVersion { get; init; }
|
||||
|
||||
/// <summary>The settings version of the other local copy the plan read; null for a server pair or no check.</summary>
|
||||
public int? OtherSettingsVersion { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -93,7 +93,10 @@ public sealed class CopyReviewBuilder(ChronosDatabase db, ProjectService project
|
||||
var can = copy.Kind == CopyKind.LocalLocal
|
||||
? await LocalCapabilitiesAsync(copy, local, ct).ConfigureAwait(false)
|
||||
: await ServerCapabilitiesAsync(copy, local, photos, details, capabilities, context, remoteOwner, ct).ConfigureAwait(false);
|
||||
return new CopyReview(copy, hereFacts, thereFacts, photos, details, projectsView, renders, can);
|
||||
return new CopyReview(copy, hereFacts, thereFacts, photos, details, projectsView, renders, can)
|
||||
{
|
||||
ExcludedHere = CopyPayload.ExcludedKeys(CopyPayload.Portable(herePayload, herePhotos)),
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<Sequence> SequenceAsync(Guid id, CancellationToken ct) =>
|
||||
|
||||
@@ -27,7 +27,11 @@ public sealed record CopyFacts(string Title, string Where, Guid? ArchiveId, int
|
||||
|
||||
/// <summary>What the Compare dialog shows of a pair: both sides, the photos, the details line by line, projects, renders, and what can be done.</summary>
|
||||
public sealed record CopyReview(FoundCopy Copy, CopyFacts Here, CopyFacts There, CopyComparisonResult Photos,
|
||||
IReadOnlyList<DetailLine> Details, CopyProjectsView Projects, CopyRendersView Renders, CopyCapabilities Can);
|
||||
IReadOnlyList<DetailLine> Details, CopyProjectsView Projects, CopyRendersView Renders, CopyCapabilities Can)
|
||||
{
|
||||
/// <summary>The photos (by key) this PC's Main leaves out: of a photo kept in two versions, the one Main does not use.</summary>
|
||||
public IReadOnlySet<string> ExcludedHere { get; init; } = new HashSet<string>(StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
/// <summary>Whether Integrate (or Merge), Link only and Delete on server are possible, and why not (<see cref="CopyBlock"/>s).</summary>
|
||||
public sealed record CopyCapabilities(bool Integrate, bool LinkOnly, bool DeleteThere, IReadOnlyList<CopyBlock> Blocks);
|
||||
|
||||
@@ -14,6 +14,12 @@ public sealed record PhotoVersions(Guid FirstFrameId, string FirstFileName, stri
|
||||
public long FirstSize { get; init; }
|
||||
|
||||
public long SecondSize { get; init; }
|
||||
|
||||
/// <summary>Main leaves the first version out (a Union keep-both excludes the incoming one): its renders use the second.</summary>
|
||||
public bool FirstExcluded { get; init; }
|
||||
|
||||
/// <summary>Main leaves the second version out.</summary>
|
||||
public bool SecondExcluded { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,6 +73,7 @@ public sealed class CopySides(ChronosDatabase db)
|
||||
public async Task<IReadOnlyList<PhotoVersions>> VersionsAsync(Guid sequenceId, CancellationToken ct)
|
||||
{
|
||||
var frames = await Processing.SequenceFrames.ListAsync(_db, sequenceId, ct).ConfigureAwait(false);
|
||||
var excluded = ExcludedIndices((await _db.Sequences.GetAsync(sequenceId, ct).ConfigureAwait(false))?.SettingsJson);
|
||||
var result = new List<PhotoVersions>();
|
||||
foreach (var group in frames.Where(f => (f.Flags & UnusableFlags) == 0 && f.Sha256 is { Length: > 0 } && f.CapturedAt is not null)
|
||||
.GroupBy(f => CopyComparer.Millisecond(f.CapturedAt!.Value)))
|
||||
@@ -80,11 +87,27 @@ public sealed class CopySides(ChronosDatabase db)
|
||||
CapturedAt = versions[0].CapturedAt,
|
||||
FirstSize = versions[0].Size,
|
||||
SecondSize = versions[1].Size,
|
||||
FirstExcluded = excluded.Contains(versions[0].Index),
|
||||
SecondExcluded = excluded.Contains(versions[1].Index),
|
||||
});
|
||||
}
|
||||
return [.. result.OrderBy(v => frames.First(f => f.Id == v.FirstFrameId).Index)];
|
||||
}
|
||||
|
||||
/// <summary>The frame positions Main excludes from renders; none for settings that are not a project of this Chronos.</summary>
|
||||
private static HashSet<int> ExcludedIndices(string? settingsJson)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(settingsJson)) return [];
|
||||
try
|
||||
{
|
||||
return [.. Core.Project.ProjectSettings.FromJson(settingsJson).ExcludedFrames];
|
||||
}
|
||||
catch (Exception ex) when (ex is System.Text.Json.JsonException or InvalidDataException)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The raw SHA-256 (lower-case) of <paramref name="sha256"/> that a usable frame (not Missing or Corrupt) of any sequence
|
||||
/// of this index other than <paramref name="except"/> holds: what is not the last copy of its photo. Batched.
|
||||
|
||||
Reference in new issue
Block a user