fix(workspace): follow server renames, never keep a thumbnail as a proxy on resume
A pull and the server's renamed event write the home's name into the copy, so a rename made on the server reaches the workspace. A copy from a server marks a thumbnail taken for a missing proxy before moving it into place; a resumed run reads the marker and fetches the proxy the server has now, instead of recording the thumbnail as one. Tests also cover the frames stamp (frames read only when it moves), an older server's copy refusal and a viewer's 403 push. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
44f0d30147
commit
cdd29f8e84
4 files changed
+227
-7
No files matched your search
@@ -249,17 +249,38 @@ public sealed class WorkspaceHost
|
||||
return;
|
||||
}
|
||||
// The folder is named by the project's id: only a project this workspace holds, of that server and sequence, is told.
|
||||
BundleHome home;
|
||||
try
|
||||
{
|
||||
if (!IsAvailable || Store.Find(change.ProjectId)?.ReadBundle().Workspace?.Home is not { IsArchive: false } home || home.SequenceId != change.SequenceId
|
||||
|| !string.Equals(home.Server, server, StringComparison.OrdinalIgnoreCase))
|
||||
if (!IsAvailable || Store.Find(change.ProjectId)?.ReadBundle().Workspace?.Home is not { IsArchive: false } held || held.SequenceId != change.SequenceId
|
||||
|| !string.Equals(held.Server, server, StringComparison.OrdinalIgnoreCase))
|
||||
return;
|
||||
home = held;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or InvalidDataException or UnauthorizedAccessException)
|
||||
{
|
||||
Log.Info("workspace", $"A change of project {change.ProjectId} on {server} could not be matched: {ex.Message}");
|
||||
return;
|
||||
}
|
||||
if (change.Change != ProjectChanges.Renamed)
|
||||
{
|
||||
HomeChanged?.Invoke(new WorkspaceHomeChange(server, change.ProjectId, change.Change));
|
||||
return;
|
||||
}
|
||||
// A rename at the server is written to the copy here before it is told, so the state read again shows the new name.
|
||||
_ = FollowNameThenTellAsync(server, home, change);
|
||||
}
|
||||
|
||||
private async Task FollowNameThenTellAsync(string server, BundleHome home, ProjectChangedEvent change)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (HomeOf(home) is { } reached) await Sync.FollowNameAsync(change.ProjectId, reached).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
Log.Info("workspace", $"The new name of project {change.ProjectId} on {server} could not be followed: {ex.Message}");
|
||||
}
|
||||
HomeChanged?.Invoke(new WorkspaceHomeChange(server, change.ProjectId, change.Change));
|
||||
}
|
||||
|
||||
|
||||
@@ -115,6 +115,9 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
|
||||
private static readonly TimeSpan LockWait = TimeSpan.FromMinutes(2);
|
||||
private static readonly TimeSpan CheckpointEvery = TimeSpan.FromSeconds(5);
|
||||
|
||||
/// <summary>Beside a server's thumbnail downloaded for a frame until the copy commits: what it is, should the run stop first.</summary>
|
||||
internal const string StandInSuffix = ".thumb";
|
||||
|
||||
/// <summary>Bytes left free on the workspace's drive besides the copy, as a download keeps (<see cref="SyncTransfers"/>).</summary>
|
||||
internal const long SpaceReserve = 512L << 20;
|
||||
|
||||
@@ -540,11 +543,13 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
|
||||
{
|
||||
var keptSha = await ContentHash.Sha256Async(target, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
// The editor's file of another photo of the frame (a conversion since) was left by an earlier copy, not this run.
|
||||
if (!listed || keptSha != current!.FileSha256 || SamePhoto(current, frame))
|
||||
// A run stopped before it recorded the file's kind left a marker beside a thumbnail it took for a missing proxy.
|
||||
var keptKind = KindOf(fetched, keptSha) ?? KindOf(current, keptSha)
|
||||
?? (File.Exists(StandInMarker(target)) ? ProxyCache.Thumb : offered.FirstOrDefault() ?? ProxyCache.Proxy);
|
||||
if ((!listed || keptSha != current!.FileSha256 || SamePhoto(current, frame)) && !(keptKind == ProxyCache.Thumb && offered.Contains(ProxyCache.Proxy)))
|
||||
{
|
||||
tally.Keep();
|
||||
return WorkspaceFrame.Of(frame, name, keptSha, new FileInfo(target).Length,
|
||||
KindOf(fetched, keptSha) ?? KindOf(current, keptSha) ?? offered.FirstOrDefault() ?? ProxyCache.Proxy);
|
||||
return WorkspaceFrame.Of(frame, name, keptSha, new FileInfo(target).Length, keptKind);
|
||||
}
|
||||
}
|
||||
// What this run downloaded in an earlier pass, then the editor's file of the same photo, unless a thumbnail stands in
|
||||
@@ -602,6 +607,9 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
|
||||
file = WorkspaceProject.ProxyName(frame.Id, received);
|
||||
path = project.MediaFile(file);
|
||||
}
|
||||
// The kind is known on disk before the file is: a run stopped after the move resumes with it.
|
||||
if (kind == ProxyCache.Thumb) File.WriteAllBytes(StandInMarker(path), []);
|
||||
else if (File.Exists(StandInMarker(path))) File.Delete(StandInMarker(path));
|
||||
File.Move(part, path, overwrite: true);
|
||||
if (await ContentHash.Sha256Async(path, cancellationToken: cancellationToken).ConfigureAwait(false) == received)
|
||||
{
|
||||
@@ -612,6 +620,8 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
|
||||
if (attempt == 2) throw new IOException(Loc.L("Errors.Workspace.CopyMismatch", path));
|
||||
}
|
||||
|
||||
static string StandInMarker(string file) => file + StandInSuffix;
|
||||
|
||||
static string? KindOf(WorkspaceFrame? entry, string sha) =>
|
||||
entry is { FileSha256: { } held } && string.Equals(held, sha, StringComparison.OrdinalIgnoreCase) ? entry.FileKind ?? ProxyCache.Proxy : null;
|
||||
}
|
||||
@@ -867,6 +877,8 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService
|
||||
{
|
||||
if (!listed.Contains(Path.GetFileName(file))) TryDelete(file);
|
||||
}
|
||||
// The media committed record each file's kind: the markers of a run are done with.
|
||||
foreach (var marker in Directory.EnumerateFiles(project.ProxiesDirectory, "*" + StandInSuffix)) TryDelete(marker);
|
||||
}
|
||||
|
||||
private static void TryDelete(string file)
|
||||
|
||||
@@ -370,10 +370,41 @@ public sealed class WorkspaceSync(WorkspaceStore store, string clientName)
|
||||
return new WorkspaceSyncResult(await StatusLockedAsync(project, home, cancellationToken).ConfigureAwait(false), [], pulled);
|
||||
}
|
||||
if (project.ReadSync().Conflict is null) PruneReplaced(project);
|
||||
await FollowNameLockedAsync(project, home, cancellationToken).ConfigureAwait(false);
|
||||
return new WorkspaceSyncResult(await StatusLockedAsync(project, home, cancellationToken).ConfigureAwait(false), [], pulled);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The project's name (and whether it is Main) as its home has them now, written to the copy here: a rename made at the
|
||||
/// home reaches the workspace. True when the copy's name changed; false when it already matched, or the home could not
|
||||
/// say (unreachable, or no longer listing the project): the next pull or status tells those.
|
||||
/// </summary>
|
||||
public async Task<bool> FollowNameAsync(Guid projectId, IProjectHome home, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(home);
|
||||
var project = Existing(projectId);
|
||||
using (await project.LockAsync(LockWait, cancellationToken).ConfigureAwait(false))
|
||||
return await FollowNameLockedAsync(project, home, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static async Task<bool> FollowNameLockedAsync(WorkspaceProject project, IProjectHome home, CancellationToken cancellationToken)
|
||||
{
|
||||
SequenceProject? listed;
|
||||
try
|
||||
{
|
||||
listed = (await home.ListAsync(cancellationToken).ConfigureAwait(false)).FirstOrDefault(p => p.Id == project.ProjectId);
|
||||
}
|
||||
catch (Exception ex) when (ex is HomeUnavailableException or ProjectException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var bundle = project.ReadBundle();
|
||||
if (listed is null || bundle.Workspace is not { } workspace || (workspace.Name == listed.Name && workspace.IsMain == listed.IsMain)) return false;
|
||||
project.WriteBundle(bundle with { Workspace = workspace with { Name = listed.Name, IsMain = listed.IsMain } });
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Settles the conflict a pull or push stopped at, as the user was shown it (<paramref name="shown"/>, else the one
|
||||
/// recorded). <see cref="ConflictChoice.KeepMine"/> keeps this workspace's values (but for the members in
|
||||
|
||||
Reference in new issue
Block a user