fix(workspace): a deleted project asks nothing, prunes and copies clean up only after what ended well
Owner review 2, phase 5a (R8), fix round 4. A project the library no longer has now reads as Gone with no conflict to answer. The conflict stays recorded in sync.json, so Save both on a deleted project says Gone once and offers its copy. It no longer reopens the conflict dialog. Keep mine and Take the library's first check that the home still has the project. Neither is merged onto the last version a deleted project had, so the working state and the unsent versions stay as they were. Old files in versions/.replaced are pruned only after a push that ended well, never after one that stopped at a conflict. A file an earlier build set aside kept the time its version was written. It now counts as set aside no earlier than when this build first knew the folder (versions/.replaced.since), so an upgrade does not prune it by an old mtime. The Merge mark goes on the replayed version whose own change met a setting the conflict listed. A version that only rides along with a working-state conflict stays a commit. A first copy cancelled while paused or failed, which no handler runs, now has its partial media removed under the project's lease, as a running one does (ICancelledJobHandler). The space estimate counts a proxy held under its <id>-<sha16>.jpg name. The frames stamp carries a weighted SQL checksum of the hashes, so a hash replaced in place (a Verify) makes the workspace read the frames again. Desktop: a removal that cannot move a file puts back what it moved, so the copy stays whole and listed, and the failure is said. The Removed toast names a damaged copy as it is known, never by its folder id. One copy that cannot be listed no longer hides the others. A Main this Chronos cannot read (newer or damaged) is refused at once with the reason, and a damaged one offers Remove local copy. Save version is off on a Gone project, and Send/Delete there say the project was deleted in the library. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c5ed31bced
commit
279ebf437f
14 files changed
+729
-57
No files matched your search
@@ -66,10 +66,11 @@ public static class WorkspaceJobs
|
||||
/// job stops saying how much is missing (the workspace shares this PC's drive with the index and the logs).
|
||||
/// Checkpoint: <c>copy:<frame>:<frames version>:<folder></c>; a run resumed on other frames or in another folder
|
||||
/// checks every file again, and a pass started again stores that before it reads anything. A first copy the user cancels
|
||||
/// removes the media it wrote itself, once it has stopped writing and under the project's lease (<see cref="RemovePartialMediaAsync"/>).
|
||||
/// removes the media it wrote itself, once it has stopped writing and under the project's lease (<see cref="RemovePartialMediaAsync"/>);
|
||||
/// one cancelled while paused or failed, which no handler runs, has them removed the same way (<see cref="CancelledAsync"/>).
|
||||
/// Originals come in phase 5c: asked for, the job fails saying so.
|
||||
/// </summary>
|
||||
internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService archives) : IJobHandler
|
||||
internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService archives) : ICancelledJobHandler
|
||||
{
|
||||
private const int PageSize = 1000;
|
||||
private const int Passes = 3;
|
||||
@@ -119,6 +120,40 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A copy cancelled while no handler ran it (paused, failed): what a first copy wrote goes as after a cancel while it ran,
|
||||
/// under the project's lease, in the background (the lease may be held for a while: the cancel does not wait for it).
|
||||
/// A workspace folder or a project no longer there has nothing to clear, and nothing is made for it.
|
||||
/// </summary>
|
||||
public Task CancelledAsync(Job job, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(job);
|
||||
WorkspaceCopyParameters parameters;
|
||||
try
|
||||
{
|
||||
parameters = Parameters(job);
|
||||
}
|
||||
catch (InvalidDataException)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
// Opening a store makes its folder: one gone stays gone.
|
||||
if (!Directory.Exists(Path.Combine(parameters.WorkspaceRoot, parameters.ProjectId.ToString("N")))) return Task.CompletedTask;
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (new WorkspaceStore(parameters.WorkspaceRoot).Find(parameters.ProjectId) is { } project) await RemovePartialMediaAsync(job, project).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
// Nobody waits for this task: whatever stopped it is logged; the next copy checks every file it finds.
|
||||
Log.Warning("workspace", $"The media of cancelled copy {job.Id} could not be cleared", ex);
|
||||
}
|
||||
}, CancellationToken.None);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A first copy of the project's media the user cancelled (the job reads <see cref="JobState.Cancelled"/>), once it has
|
||||
/// stopped writing: the photos it wrote (copies the home can make again) are removed under the project's lease, so the
|
||||
@@ -131,6 +166,8 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
|
||||
try
|
||||
{
|
||||
if (await db.Jobs.GetAsync(job.Id, CancellationToken.None).ConfigureAwait(false) is not { State: JobState.Cancelled }) return;
|
||||
// Nothing half written (or the copy removed meanwhile): the lease, which makes the folder, is not taken.
|
||||
if (File.Exists(project.MediaIndexPath) || !Directory.Exists(project.MediaDirectory)) return;
|
||||
using (await project.LockAsync(LockWait, CancellationToken.None).ConfigureAwait(false))
|
||||
{
|
||||
if (File.Exists(project.MediaIndexPath) || !Directory.Exists(project.MediaDirectory)) return;
|
||||
@@ -441,15 +478,26 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
|
||||
|
||||
/// <summary>
|
||||
/// The bytes the copy still writes from each frame on (index <c>i</c>: frames <c>i</c> to the last; one more entry, 0):
|
||||
/// nothing for a frame the workspace holds a file of already (kept, or replaced by one of about its size), the archive's
|
||||
/// nothing for a frame the workspace holds a file of already (kept, or replaced by one of about its size; under its own
|
||||
/// name or the one other bytes of it take, <see cref="WorkspaceProject.ProxyName(Guid, string)"/>), the archive's
|
||||
/// proxy's size where it has one, else an estimate at the proxy size the copy makes (<see cref="Estimate"/>).
|
||||
/// </summary>
|
||||
private static long[] Remaining(WorkspaceProject project, SequencePaths folder, List<Frame> frames, ProxyPolicy policy) =>
|
||||
Remaining(Directory.Exists(project.ProxiesDirectory)
|
||||
? Directory.EnumerateFiles(project.ProxiesDirectory).Select(Path.GetFileName).ToHashSet(StringComparer.OrdinalIgnoreCase)
|
||||
: [], folder, frames, policy);
|
||||
Remaining(Directory.Exists(project.ProxiesDirectory) ? HeldFrames(Directory.EnumerateFiles(project.ProxiesDirectory, "*.jpg")) : [], folder, frames, policy);
|
||||
|
||||
private static long[] Remaining(HashSet<string?> held, SequencePaths folder, List<Frame> frames, ProxyPolicy policy)
|
||||
/// <summary>The frames the files at <paramref name="paths"/> are proxies of: "<frame id>.jpg" and "<frame id>-<sha16>.jpg".</summary>
|
||||
internal static HashSet<Guid> HeldFrames(IEnumerable<string> paths)
|
||||
{
|
||||
var held = new HashSet<Guid>();
|
||||
foreach (var path in paths)
|
||||
{
|
||||
var name = Path.GetFileNameWithoutExtension(path);
|
||||
if (name.Length >= 32 && (name.Length == 32 || name[32] == '-') && Guid.TryParseExact(name[..32], "N", out var id)) held.Add(id);
|
||||
}
|
||||
return held;
|
||||
}
|
||||
|
||||
private static long[] Remaining(HashSet<Guid> held, SequencePaths folder, List<Frame> frames, ProxyPolicy policy)
|
||||
{
|
||||
var proxies = Directory.Exists(folder.Proxies)
|
||||
? new DirectoryInfo(folder.Proxies).EnumerateFiles().ToDictionary(f => f.Name, f => f.Length, StringComparer.OrdinalIgnoreCase)
|
||||
@@ -458,7 +506,7 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
|
||||
for (var i = frames.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var frame = frames[i];
|
||||
var bytes = held.Contains(ProxyCache.FileName(frame.Id)) ? 0
|
||||
var bytes = held.Contains(frame.Id) ? 0
|
||||
: proxies.TryGetValue(ArchiveLayout.ProxyFileName(frame.Index), out var length) ? length
|
||||
: (frame.Flags & FrameFlags.Missing) != 0 ? 0
|
||||
: Estimate(frame, policy);
|
||||
|
||||
Reference in new issue
Block a user