fix(workspace): close the phase 5c review findings
Originals are now judged by their bytes, never by the media index: a removal or clean-up hashes every file under media/originals and deletes it only when the home holds that SHA-256; every other file, named or not, goes to the workspace trash. Trash entries are filled under a staging name that Empty never lists. A ledger can only name files inside exports/. Jobs follow the workspace: a copy, render or send resolves the folder that holds its project now (a moved workspace, a retry after a move) and waits while a move has not switched yet. A clean-up failure after the switch is a warning that keeps the journal for a later resume; entries that changed since they were copied are kept, and a same-volume rename refused across volumes falls back to copy and verify. Sends map a replayed version by content hash, or go with the project only, and note an old server that drops provenance. The media index (format 2) and project file (format 3) refuse older readers while they hold originals. Metered connections also hold sync downloads and server copies. The editor gains Send again, the Settings page can resume a stopped move, the disabled tooltips say why, and unused strings are pruned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
09fcff4eb2
commit
2654683a12
125 files changed
+1618
-401
No files matched your search
@@ -45,6 +45,11 @@ public interface IWorkspaceUi
|
||||
|
||||
/// <summary>The home's sequence changed (a version of Main sent: its settings and hero frame): what shows it reads it again.</summary>
|
||||
Task SequenceChangedAsync(Guid sequenceId);
|
||||
|
||||
/// <summary>Shows the Jobs screen (a toast's Jobs action); nothing where there is none.</summary>
|
||||
void ShowJobs()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -212,10 +217,14 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
/// <summary>Proxies only… (phase 5c): the originals copied here deleted once the home is checked to hold each one.</summary>
|
||||
public ICommand ProxiesOnlyCommand { get; }
|
||||
|
||||
/// <summary>What Copy originals… does, or why it is disabled (the media busy, or the originals here already).</summary>
|
||||
public string CopyOriginalsToolTip => IsMediaBusy ? Loc.L("Tooltips.Editor.Project.MediaBusy")
|
||||
: HoldsOriginals ? Loc.L("Tooltips.Editor.Project.HasOriginals")
|
||||
: WorkspaceText.ForHome("Tooltips.Editor.Project.CopyOriginals", IsServerHome);
|
||||
|
||||
/// <summary>What Proxies only… does, or why it is disabled (the media busy, or proxies only here already).</summary>
|
||||
public string ProxiesOnlyToolTip => IsMediaBusy ? Loc.L("Tooltips.Editor.Project.MediaBusy")
|
||||
: !HoldsOriginals ? Loc.L("Tooltips.Editor.Project.ProxiesAlready")
|
||||
: WorkspaceText.ForHome("Tooltips.Editor.Project.ProxiesOnly", IsServerHome);
|
||||
|
||||
/// <summary>Reads where the project stands (against its home) and whether the home's frames moved.</summary>
|
||||
@@ -729,7 +738,7 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
_copyJob = job.Id;
|
||||
_copyingOriginals = true;
|
||||
RaiseState();
|
||||
_ui.Notify(Loc.L("Editor.Workspace.CopyingOriginals"), _session.Content.Sequence.DisplayTitle, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"));
|
||||
_ui.Notify(Loc.L("Editor.Workspace.CopyingOriginals"), _session.Content.Sequence.DisplayTitle, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"), _ui.ShowJobs);
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
|
||||
@@ -84,7 +84,7 @@ public sealed class OpenInWorkspaceDialogViewModel : ArchiveDialogViewModel
|
||||
? [new DialogFact(Loc.L("Editor.OpenWorkspace.Originals"), Formatting.Bytes(originals), Reason: Loc.L("Tooltips.Editor.OpenWorkspace.OriginalsSize"))]
|
||||
: Array.Empty<DialogFact>(),
|
||||
];
|
||||
_isOriginals = defaultMedia == BundleMedia.Originals && CanCopyOriginals;
|
||||
_isOriginals = string.Equals(defaultMedia, BundleMedia.Originals, StringComparison.OrdinalIgnoreCase) && CanCopyOriginals;
|
||||
Projects = [.. projects.OrderByDescending(p => p.IsMain).Select(p => new ProjectOption(p, unreadable?.GetValueOrDefault(p.Id)))];
|
||||
_selected = Projects.FirstOrDefault(p => p.IsAvailable);
|
||||
_isNew = !HasProjects;
|
||||
|
||||
@@ -148,6 +148,24 @@ public static class WorkspaceFolderChange
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Settings › Workspace › Resume: the move that stopped before it ended (<see cref="WorkspaceHost.UnfinishedMoveAsync"/>)
|
||||
/// queued again from its journal; nothing when there is none any more.
|
||||
/// </summary>
|
||||
public static async Task ResumeUnfinishedAsync(ShellViewModel shell)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(shell);
|
||||
try
|
||||
{
|
||||
if (await shell.Services.Workspace.UnfinishedMoveAsync() is { } journal) await ResumeAsync(shell, journal);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or DatabaseException)
|
||||
{
|
||||
Log.Warning("workspace", "An unfinished move of the workspace could not be looked for", ex);
|
||||
shell.Notify(Loc.L("Settings.Workspace.NotMoved"), ErrorText.For(ex), isError: true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The move's plan as a confirmation: where the projects go, how many and how big, the free bytes at the target, whether
|
||||
/// folders are renamed or files copied and checked, and how many projects hold work not at their home (they move with it).
|
||||
|
||||
@@ -190,7 +190,7 @@ public sealed partial class WorkspaceHost
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(project);
|
||||
var unsent = WorkspaceCleaner.UnsentRenders(project);
|
||||
var last = (await LastOriginalsOfAsync(project, cancellationToken).ConfigureAwait(false)).Count;
|
||||
var last = await LastOriginalsOfAsync(project, cancellationToken).ConfigureAwait(false);
|
||||
return (unsent, last);
|
||||
}
|
||||
|
||||
@@ -216,13 +216,17 @@ public sealed partial class WorkspaceHost
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Before a removed copy's media are deleted, under the project's lease: the originals the home no longer holds with the
|
||||
/// same SHA-256 moved into <paramref name="aside"/> (the copy's trash entry), never deleted.
|
||||
/// Before a removed copy's media are deleted, under the project's lease: every file of its folder of originals, named by
|
||||
/// the media index or not (an index that cannot be read names none), hashed now and deleted only when the home's frames,
|
||||
/// read now, hold a photo of that SHA-256; every other one moved into <paramref name="aside"/> (the copy's trash entry),
|
||||
/// never deleted, and every one when the home cannot be asked (<see cref="WorkspaceOriginals.ClearOriginals"/>).
|
||||
/// </summary>
|
||||
private async Task KeepLastOriginalsAsync(WorkspaceProject project, string aside, CancellationToken cancellationToken)
|
||||
/// <returns>The originals that could be neither deleted nor moved: they stay in the folder of originals.</returns>
|
||||
private async Task<int> ClearOriginalsAsync(WorkspaceProject project, string aside, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(project);
|
||||
ArgumentException.ThrowIfNullOrEmpty(aside);
|
||||
if (!WorkspaceCleaner.HoldsOriginalFiles(project)) return 0;
|
||||
// The working state went into the entry first: the home is read from there.
|
||||
BundleHome? home = null;
|
||||
try
|
||||
@@ -233,19 +237,39 @@ public sealed partial class WorkspaceHost
|
||||
{
|
||||
Log.Info("workspace", $"The home of removed project {project.ProjectId} is not known: every original it holds is kept ({ex.Message})");
|
||||
}
|
||||
var last = await LastOriginalsOfAsync(project, cancellationToken, home, known: true).ConfigureAwait(false);
|
||||
if (last.Count == 0) return;
|
||||
var moved = WorkspaceCleaner.SetOriginalsAside(project, last, aside);
|
||||
Log.Info("workspace", $"{moved} original(s) of project {project.ProjectId} its home no longer holds kept in {aside}");
|
||||
var held = home is null ? null : await HomeFramesAsync(project, home, cancellationToken).ConfigureAwait(false);
|
||||
var (deleted, trashed, _, left) = WorkspaceOriginals.ClearOriginals(project, held?.Frames, aside);
|
||||
Log.Info("workspace", $"Originals of removed project {project.ProjectId}: {deleted} deleted (the home holds them), {trashed} kept in {aside}"
|
||||
+ (left > 0 ? $", {left} left where they are (held open)" : string.Empty));
|
||||
return left;
|
||||
}
|
||||
|
||||
/// <summary>The frames of <paramref name="home"/> as it holds them now; null (logged) when it cannot be asked.</summary>
|
||||
private async Task<HomeFrames?> HomeFramesAsync(WorkspaceProject project, BundleHome home, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
return HomeOf(home) is { } reached ? await reached.FramesAsync(cancellationToken).ConfigureAwait(false) : null;
|
||||
}
|
||||
catch (Exception ex) when (ex is HomeUnavailableException or ProjectException or DatabaseException or IOException or InvalidDataException)
|
||||
{
|
||||
// Not known: every original counts as the last one, and goes to the trash.
|
||||
Log.Info("workspace", $"The home of project {project.ProjectId} could not be asked for its frames: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The frames whose original the workspace holds and the home no longer holds as it is (every one while the home cannot
|
||||
/// be asked); the home is the working state's, else (<paramref name="known"/>) <paramref name="named"/>.
|
||||
/// What a removal plan counts of the originals that go to the trash rather than away: the files of the folder of
|
||||
/// originals the media index does not name (every one when the index cannot be read), plus the frames whose recorded
|
||||
/// original the home no longer holds as it is (every one while the home cannot be asked). The removal hashes each file
|
||||
/// itself; this count is what the plan says, never what decides.
|
||||
/// </summary>
|
||||
private async Task<IReadOnlyList<WorkspaceFrame>> LastOriginalsOfAsync(WorkspaceProject project, CancellationToken cancellationToken, BundleHome? named = null,
|
||||
bool known = false)
|
||||
private async Task<int> LastOriginalsOfAsync(WorkspaceProject project, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!WorkspaceCleaner.HoldsOriginalFiles(project)) return 0;
|
||||
var files = Directory.EnumerateFiles(project.OriginalsDirectory)
|
||||
.Where(f => !f.EndsWith(".part", StringComparison.OrdinalIgnoreCase)).Select(Path.GetFileName).OfType<string>().ToList();
|
||||
WorkspaceMedia? media;
|
||||
try
|
||||
{
|
||||
@@ -253,22 +277,49 @@ public sealed partial class WorkspaceHost
|
||||
}
|
||||
catch (InvalidDataException ex)
|
||||
{
|
||||
Log.Info("workspace", $"The media index of project {project.ProjectId} cannot be read: no original is counted from it ({ex.Message})");
|
||||
return [];
|
||||
Log.Info("workspace", $"The media index of project {project.ProjectId} cannot be read: every original counts as one to keep ({ex.Message})");
|
||||
return files.Count;
|
||||
}
|
||||
if (media is null || !media.Frames.Any(f => f.HasOriginal)) return [];
|
||||
var named = media?.Frames.Where(f => f.Original is not null).Select(f => Path.GetFileName(f.Original!)).ToHashSet(StringComparer.OrdinalIgnoreCase) ?? [];
|
||||
var unnamed = files.Count(f => !named.Contains(f));
|
||||
if (media is null || named.Count == 0) return unnamed;
|
||||
HomeFrames? held = null;
|
||||
try
|
||||
{
|
||||
var homeOf = known ? named : project.ReadBundle().Workspace!.Home;
|
||||
if (homeOf is not null && HomeOf(homeOf) is { } home) held = await home.FramesAsync(cancellationToken).ConfigureAwait(false);
|
||||
held = await HomeFramesAsync(project, project.ReadBundle().Workspace!.Home, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (ex is HomeUnavailableException or ProjectException or DatabaseException or IOException or InvalidDataException)
|
||||
catch (Exception ex) when (ex is IOException or InvalidDataException or UnauthorizedAccessException)
|
||||
{
|
||||
// Not known: every original counts as the last one, and goes to the trash.
|
||||
Log.Info("workspace", $"The home of project {project.ProjectId} could not be asked for its frames: {ex.Message}");
|
||||
Log.Info("workspace", $"The home of project {project.ProjectId} is not known: {ex.Message}");
|
||||
}
|
||||
return WorkspaceCleaner.LastOriginals(media, held);
|
||||
return unnamed + WorkspaceCleaner.LastOriginals(media, held).Count(f => files.Contains(Path.GetFileName(f.Original!), StringComparer.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Edit › Export › Send again: queues the sending home of every render of the project not sent yet
|
||||
/// (<see cref="JobKind.WorkspaceSend"/>), unless one is queued, running or paused already.
|
||||
/// </summary>
|
||||
/// <returns>True when a send is queued or waits already; false when nothing waits to be sent.</returns>
|
||||
/// <exception cref="WorkspaceException">The workspace is being moved, or the index or the engine is not open.</exception>
|
||||
public Task<bool> SendRendersAsync(Guid projectId, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
EnsureNotMoving();
|
||||
if (_engine() is null || _db() is null) throw new WorkspaceException(Loc.L("Editor.Error.NoEngine"));
|
||||
var project = Existing(projectId);
|
||||
if (WorkspaceCleaner.UnsentRenders(project) == 0) return false;
|
||||
await QueueRenderSendAsync(project, project.ReadBundle().Workspace!, cancellationToken).ConfigureAwait(false);
|
||||
return true;
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>A send of the project's renders is queued, running or paused (Send again waits for it).</summary>
|
||||
public async Task<bool> RenderSendPendingAsync(Guid projectId, Guid sequenceId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (_db() is not { } db) return false;
|
||||
foreach (var pending in await db.Jobs.ListPendingAsync(JobKind.WorkspaceSend, sequenceId, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
if (WorkspaceJobs.SendParameters(pending)?.ProjectId == projectId) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Queues the sending of the project's renders not sent yet (<see cref="JobKind.WorkspaceSend"/>), unless one is queued or running.</summary>
|
||||
|
||||
@@ -80,10 +80,20 @@ public sealed partial class WorkspaceHost
|
||||
/// </summary>
|
||||
public event Action? MoveEnded;
|
||||
|
||||
/// <summary>A move job followed here waits, runs or is paused (no disk is read).</summary>
|
||||
public bool IsMoveQueued
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_gate) return _moveJob != Guid.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A move stopped before it ended: the folder in use holds its journal and no move job waits, runs or is paused. Null
|
||||
/// when there is none (a move under way is no move to take up). A move job waiting at start is followed from now on,
|
||||
/// so the workspace waits for it (<see cref="IsMoving"/>).
|
||||
/// A move stopped before it ended: the folder in use holds its journal and no move job waits, runs or is paused; or a
|
||||
/// move switched to the folder in use and left part of the folder it came from (its journal there names what is left
|
||||
/// to clear). Null when there is none (a move under way is no move to take up). A move job waiting at start is followed
|
||||
/// from now on, so the workspace waits for it (<see cref="IsMoving"/>).
|
||||
/// </summary>
|
||||
public Task<WorkspaceMoveJournal?> UnfinishedMoveAsync(CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
@@ -96,7 +106,20 @@ public sealed partial class WorkspaceHost
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return WorkspaceMover.HasJournal(Root) ? WorkspaceMover.ReadJournal(Root) : null;
|
||||
if (WorkspaceMover.HasJournal(Root)) return WorkspaceMover.ReadJournal(Root);
|
||||
// The folder in use is a move's target: the folder it left may hold what could not be cleared after the switch.
|
||||
var root = Path.TrimEndingDirectorySeparator(Path.GetFullPath(Root));
|
||||
foreach (var state in new[] { JobState.Done, JobState.Failed, JobState.Cancelled })
|
||||
{
|
||||
foreach (var job in (await db.Jobs.ListAsync(state, JobKind.WorkspaceMove, 5, cancellationToken: cancellationToken).ConfigureAwait(false)).Items)
|
||||
{
|
||||
if (WorkspaceJobs.MoveParameters(job) is not { From.Length: > 0 } moved || !WorkspaceMover.HasJournal(moved.From)) continue;
|
||||
if (WorkspaceMover.ReadJournal(moved.From) is { Stage: WorkspaceMoveStage.Switched } left
|
||||
&& string.Equals(Path.TrimEndingDirectorySeparator(Path.GetFullPath(left.To)), root, StringComparison.OrdinalIgnoreCase))
|
||||
return left;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -296,7 +296,9 @@ public sealed partial class WorkspaceHost
|
||||
{
|
||||
try
|
||||
{
|
||||
if (HomeOf(home) is { } reached) await Sync.FollowNameAsync(change.ProjectId, reached).ConfigureAwait(false);
|
||||
// Nothing is written into a folder being moved: the next status read takes the name.
|
||||
if (IsMoving) Log.Info("workspace", $"The new name of project {change.ProjectId} on {server} waits for the workspace's move");
|
||||
else if (HomeOf(home) is { } reached) await Sync.FollowNameAsync(change.ProjectId, reached).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
@@ -944,10 +946,11 @@ public sealed partial class WorkspaceHost
|
||||
if (copy != Guid.Empty && _engine() is { } engine && _db() is { } db && await db.Jobs.GetAsync(copy, cancellationToken).ConfigureAwait(false) is
|
||||
{ State: JobState.Queued or JobState.Running or JobState.Paused })
|
||||
await engine.CancelAsync(copy, cancellationToken).ConfigureAwait(false);
|
||||
var aside = Path.Combine(Store.Root, TrashFolder, project.ProjectId.ToString("N") + "-" + DateTime.UtcNow.Ticks.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||
// Filled under a staging name Empty… never lists, and named once whole.
|
||||
using var trash = WorkspaceTrash.Begin(Store.Root, project.ProjectId, DateTime.UtcNow);
|
||||
var aside = trash.Path;
|
||||
using (await project.LockAsync(LockWait, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
Directory.CreateDirectory(aside);
|
||||
var moved = new List<(string From, string To)>();
|
||||
try
|
||||
{
|
||||
@@ -987,9 +990,21 @@ public sealed partial class WorkspaceHost
|
||||
}
|
||||
throw;
|
||||
}
|
||||
// Originals the home no longer holds go aside with the rest; only what the home can make again is deleted.
|
||||
await KeepLastOriginalsAsync(project, aside, cancellationToken).ConfigureAwait(false);
|
||||
if (Directory.Exists(project.MediaDirectory)) Directory.Delete(project.MediaDirectory, recursive: true);
|
||||
// Every original is hashed and goes aside unless the home holds the same bytes; only what the home can make again
|
||||
// is deleted. One that can be neither deleted nor moved stays where it is, and the media folder with it.
|
||||
if (await ClearOriginalsAsync(project, aside, cancellationToken).ConfigureAwait(false) == 0)
|
||||
{
|
||||
if (Directory.Exists(project.MediaDirectory)) Directory.Delete(project.MediaDirectory, recursive: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var entry in Directory.EnumerateFileSystemEntries(project.MediaDirectory).ToList())
|
||||
{
|
||||
if (string.Equals(Path.GetFileName(entry), WorkspaceProject.OriginalsFolder, StringComparison.OrdinalIgnoreCase)) continue;
|
||||
if (Directory.Exists(entry)) Directory.Delete(entry, recursive: true);
|
||||
else File.Delete(entry);
|
||||
}
|
||||
}
|
||||
|
||||
void Move(string from, string to)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user