feat: found copies foundation (contracts, migration 0012, store, wire, trash and job hooks, keys)
Owner review 6 asks Chronos to recognise the same time-lapse held under different ids on the server and on this PC, compare the copies, and keep them apart or integrate and sync them. This lays the shared foundation the later parcels build on, without any UI or detection yet. - Migration 0012 adds found_copies (local-server and local-local pairs with evidence, scores, answer, policy and the 404 record) and copy_probes; every existing link with a local sequence becomes a Linked pair, so a server deletion and the per-link policy have a place. - FoundCopyStore keeps the pairs: upserts that never touch the answer, a compare-and-set of the state with an Integrating backstop (a failed or cancelled job reads as the previous state), link promotion and demotion, the once-per-refresh 404 count, the merge's links stage (session keys, links reset, pairs moved, refused when both are linked on one server), the local overlap queries and the probes. SyncLinkStore.RekeyAsync moves pairs and probes with the links in the same transaction. - Contracts for detection, review, plans, the Integrate and MergeSequences jobs (kinds 25/26, High level, new detail steps) and the Upload all rule that keeps suspected, kept-apart, deleted, busy and server-born sequences here. - Wire: POST photos/lookup, uploads into a target (IntoTarget/Copied, trailing and optional), frames/delete on the client, capabilities photo-lookup and upload-into, cached per remote. - The trash plans and deletes accept the job that holds the sequence (its own hold is not Busy) and a frames version checked under the lease; a Background job never interrupts a running one. - Settings for linking, the photo policy and projects; the en and it keys of design section 9. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
43719bb5c5
commit
283d04d9cd
57 files changed
+3302
-26
No files matched your search
@@ -0,0 +1,173 @@
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Projects;
|
||||
using Chronos.Data.Sync;
|
||||
|
||||
namespace Chronos.Data.Copies;
|
||||
|
||||
/// <summary>The user's choice for one photo under Choose each (nothing preselected: <see cref="Leave"/>).</summary>
|
||||
public enum PhotoChoice
|
||||
{
|
||||
Leave = 0,
|
||||
Bring = 1,
|
||||
KeepBoth = 2,
|
||||
TakeHere = 3,
|
||||
TakeThere = 4,
|
||||
}
|
||||
|
||||
/// <summary>What a plan does with one photo.</summary>
|
||||
public enum PhotoAction
|
||||
{
|
||||
Send = 0,
|
||||
Fetch = 1,
|
||||
SendVersion = 2,
|
||||
FetchVersion = 3,
|
||||
TrashHere = 4,
|
||||
TrashThere = 5,
|
||||
}
|
||||
|
||||
/// <summary>Why a plan cannot be applied (each maps to one <c>Errors.Copies.*</c> key).</summary>
|
||||
public enum CopyBlock
|
||||
{
|
||||
NeedsNewerServer,
|
||||
NoUploadRight,
|
||||
NoFetchRight,
|
||||
NoEditRight,
|
||||
NoDeleteRight,
|
||||
LinkTaken,
|
||||
NoSpace,
|
||||
Busy,
|
||||
ArchiveOffline,
|
||||
DetailsUnchosen,
|
||||
FolderMoved,
|
||||
UnsentWorkspace,
|
||||
BothLinked,
|
||||
TrashBlocked,
|
||||
KeptUnchosen,
|
||||
ChangedFile,
|
||||
}
|
||||
|
||||
/// <summary>The choices of an Integrate: photo policy, per-photo choices (by photo key), per-detail sides (by path), projects.</summary>
|
||||
public sealed record IntegrateChoices(CopyPhotoPolicy Photos, IReadOnlyDictionary<string, PhotoChoice> PerPhoto,
|
||||
IReadOnlyDictionary<string, CopySide> Details, CopyProjects Projects);
|
||||
|
||||
/// <summary>One photo step of a plan: the photo's key, what is done, the frame it starts from, its name, size and SHA-256.</summary>
|
||||
public sealed record PhotoStep(string Key, PhotoAction Action, Guid? FrameId, string FileName, long Bytes, string? Sha256);
|
||||
|
||||
/// <summary>A photo a trash step takes whose raw SHA-256 nothing else holds (no other frame of this index, nor the other side).</summary>
|
||||
public sealed record LastCopy(string Key, CopySide Side, string FileName, long Bytes);
|
||||
|
||||
/// <summary>A project copied across: from which side, the source, the name it gets at the other home, its versions and head.</summary>
|
||||
public sealed record ProjectStep(CopySide From, Guid SourceProjectId, string SourceName, string TargetName, int Versions, Guid SourceHeadId);
|
||||
|
||||
/// <summary>
|
||||
/// The dry run of an Integrate of a local sequence with a server sequence (design §5c). Payload is the one portable payload
|
||||
/// both sides get; LocalPayload and RemotePayload are each side's as planned (the apply-time content check).
|
||||
/// </summary>
|
||||
public sealed record IntegratePlan(Guid CopyId, string Server, Guid LocalId, Guid RemoteId, IntegrateChoices Choices,
|
||||
IReadOnlyList<PhotoStep> Photos, IReadOnlyList<LastCopy> LastCopies, int LeftOut, SyncPayload? Payload,
|
||||
SyncPayload? LocalPayload, SyncPayload? RemotePayload, int DetailChanges, IReadOnlyList<ProjectStep> Projects,
|
||||
long FetchBytes, long SendBytes, long FreeBytes, long? QuotaLeftBytes, IReadOnlyList<CopyBlock> Blocks,
|
||||
int LocalFramesVersion, int LocalSettingsVersion, int RemoteFramesVersion, int RemoteSettingsVersion, string Fingerprint)
|
||||
{
|
||||
public bool CanApply => Blocks.Count == 0;
|
||||
|
||||
public bool Destructive => Photos.Any(p => p.Action is PhotoAction.TrashHere or PhotoAction.TrashThere);
|
||||
|
||||
/// <summary>New photos move by themselves afterwards only when the plan leaves nothing on one side only (design §6.1).</summary>
|
||||
public bool AutoPhotos => LeftOut == 0;
|
||||
}
|
||||
|
||||
/// <summary>The choices of a merge of two local copies (projects are always copied across: the other's home goes to the trash).</summary>
|
||||
public sealed record MergeChoices(CopyPhotoPolicy Photos, IReadOnlyDictionary<string, PhotoChoice> PerPhoto,
|
||||
IReadOnlyDictionary<string, CopySide> Details);
|
||||
|
||||
/// <summary>A render of the dropped sequence that moves to the kept one (its row keeps its id).</summary>
|
||||
public sealed record RenderStep(Guid RenderId, string FileName, long Bytes, string? Sha256);
|
||||
|
||||
/// <summary>The dry run of a merge of two local sequences into the kept one (design §5d).</summary>
|
||||
public sealed record MergePlan(Guid CopyId, Guid KeepId, Guid DropId, MergeChoices Choices, IReadOnlyList<PhotoStep> Photos,
|
||||
IReadOnlyList<LastCopy> LastCopies, IReadOnlyList<RenderStep> Renders, SyncPayload? Payload, int DetailChanges,
|
||||
IReadOnlyList<ProjectStep> Projects, IReadOnlyList<string> SessionKeys, IReadOnlyList<string> SkippedSessionKeys,
|
||||
IReadOnlyList<string> Links, DeletePlan Trash, long CopyBytes, long FreeBytes, IReadOnlyList<CopyBlock> Blocks,
|
||||
int KeepFramesVersion, int KeepSettingsVersion, int DropFramesVersion, int DropSettingsVersion, string Fingerprint)
|
||||
{
|
||||
public bool CanApply => Blocks.Count == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What the planners need to know of this PC and the signed-in account: names, rights (OwnsOrAdmin: of the server sequence),
|
||||
/// whether the server keeps projects, the quota left, sequences with unsent workspace work, and every server's originals archive.
|
||||
/// </summary>
|
||||
public sealed record CopyPlanContext(string PcName, string? ServerName, bool CanUpload, bool CanFetch, bool CanEdit, bool CanDelete,
|
||||
bool OwnsOrAdmin, bool KeepsProjects, long? QuotaLeft, IReadOnlySet<Guid> UnsentWorkspaceSequences,
|
||||
IReadOnlySet<Guid> ServerOriginalsArchives);
|
||||
|
||||
/// <summary>The server-side dry run of moving photos of a pair's server sequence to the server's trash (design §6.2).</summary>
|
||||
public sealed record TrashTherePlan(Guid CopyId, string Server, Guid RemoteId, IReadOnlyList<Guid> FrameIds, IReadOnlyList<string> Keys, int Photos,
|
||||
long Bytes, int FramesVersion, IReadOnlyList<LastCopy> LastCopies);
|
||||
|
||||
/// <summary>
|
||||
/// The journal of one project copied to another home: the intended name, when it was asked, the copy once made, the version
|
||||
/// the copy was made from, and the versions pushed so far (source version id to the copy's).
|
||||
/// </summary>
|
||||
public sealed record TransplantStep(string Intent, DateTimeOffset Asked, Guid? TargetId, Guid? BaseId, int BaseNumber,
|
||||
IReadOnlyList<TransplantMove> Moves);
|
||||
|
||||
/// <summary>A version of the source project and its copy at the other home.</summary>
|
||||
public sealed record TransplantMove(Guid Source, Guid Copy);
|
||||
|
||||
/// <summary>Copies a project with its whole history from one home to another (ProjectTransplant).</summary>
|
||||
public interface IProjectCopier
|
||||
{
|
||||
Task<SequenceProject> CopyAsync(IProjectHome from, SequenceProject source, IProjectHome to, string name,
|
||||
TransplantStep? journal, Func<TransplantStep, ValueTask> save, CancellationToken ct);
|
||||
}
|
||||
|
||||
/// <summary>Whether a sequence has workspace projects with unsent versions or unsaved work (a merge waits for them).</summary>
|
||||
public interface IWorkspaceGuard
|
||||
{
|
||||
Task<bool> HasUnsentAsync(Guid sequenceId, CancellationToken ct);
|
||||
}
|
||||
|
||||
/// <summary>The sequences changed since the plan was made: nothing was applied; the pair goes back to its previous state.</summary>
|
||||
public sealed class StaleCopyPlanException : InvalidOperationException
|
||||
{
|
||||
public StaleCopyPlanException()
|
||||
: base(Loc.L("Errors.Copies.StalePlan"))
|
||||
{
|
||||
}
|
||||
|
||||
public StaleCopyPlanException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public StaleCopyPlanException(string message, Exception inner)
|
||||
: base(message, inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A sequence of the pair is already linked to another sequence of that server: nothing was changed.</summary>
|
||||
public sealed class CopyLinkTakenException : InvalidOperationException
|
||||
{
|
||||
public CopyLinkTakenException()
|
||||
: base(Loc.L("Errors.Copies.LinkTaken", string.Empty, string.Empty))
|
||||
{
|
||||
}
|
||||
|
||||
public CopyLinkTakenException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public CopyLinkTakenException(string message, Exception inner)
|
||||
: base(message, inner)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>The refusal for <paramref name="title"/> already linked to another sequence of <paramref name="server"/>.</summary>
|
||||
public static CopyLinkTakenException For(string title, string server) => new(Loc.L("Errors.Copies.LinkTaken", title, server));
|
||||
}
|
||||
Reference in new issue
Block a user