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:
Alby96andClaude Opus 5.5 committed 2026-11-04 17:32:48 +01:00
1 parent 09fcff4eb2
commit 2654683a12
125 files changed
+1618 -401

No files matched your search

@@ -334,6 +334,175 @@ public sealed class WorkspaceMoveTests(TestContext context)
Assert.False(Directory.Exists(to));
}
[Test]
public async Task TwoVolumesUnderOneFolderAreCopiedWhenTheFirstRenameIsRefused()
{
var (from, _) = Workspace(projects: 2);
var before = Contents(from);
var to = Path.Combine(context.CreateTempDirectory("target"), "moved");
var renames = 0;
var copied = 0;
var mover = new WorkspaceMover(from, to)
{
// Both under one drive letter, the target a volume mounted in a folder: the system refuses the rename.
SameVolume = true,
Cut = (step, _) =>
{
if (step == "rename" && ++renames == 1)
throw new IOException("The system cannot move the file to a different disk drive.", OperatingSystem.IsWindows() ? unchecked((int)0x80070011) : 18);
if (step == "copied") copied++;
},
};
var (survey, resumed) = await mover.MoveAsync(mover.Survey().Fingerprint, cancellationToken: context.Cancellation);
Assert.False(resumed);
Assert.True(survey.SameVolume, "planned as one volume");
Assert.Equal(1, renames);
Assert.Equal(before.Keys.Count(k => !IsLease(k)), copied, "every file copied and verified instead");
var after = Contents(to);
foreach (var (name, sha) in before.Where(b => !IsLease(b.Key))) Assert.Equal(sha, after.GetValueOrDefault(name), name);
Assert.False(Directory.Exists(from));
}
[Test]
public async Task AnEntryThatChangedAfterItsCopyIsKeptAndTheMoveEndsWell()
{
var (from, ids) = Workspace(projects: 2);
var to = Path.Combine(context.CreateTempDirectory("target"), "moved");
var changed = Path.Combine(from, ids[0].ToString("N"), "versions", "0001.json");
var mover = new WorkspaceMover(from, to)
{
SameVolume = false,
Cut = (step, _) =>
{
// Written after its copy was verified, before the source is cleared.
if (step == "switched") File.AppendAllText(changed, " ");
},
};
var log = new List<string>();
var survey = mover.Survey();
await mover.MoveAsync(survey.Fingerprint, log: log.Add, cancellationToken: context.Cancellation);
Assert.Equal("{} ", File.ReadAllText(changed), "never deleted");
Assert.False(Directory.Exists(Path.Combine(from, ids[1].ToString("N"))), "the other project went");
Assert.Contains(Loc.L("Archive.Log.WorkspaceMoveLeft", mover.From, 1), log);
Assert.Contains(Loc.L("Archive.Log.WorkspaceMoved", mover.To, 2, survey.Files), log);
Assert.Equal(2, new WorkspaceStore(to).List().Count);
}
[Test]
[WindowsOnly]
public async Task AnEntryHeldOpenAfterTheSwitchStaysInTheJournalAndIsClearedWhenTakenUp()
{
var (from, ids) = Workspace(projects: 2);
var to = Path.Combine(context.CreateTempDirectory("target"), "moved");
var heldFile = Path.Combine(from, ids[1].ToString("N"), WorkspaceProject.BundleFile);
FileStream? held = null;
var mover = new WorkspaceMover(from, to)
{
SameVolume = false,
Cut = (step, _) =>
{
// An editor elsewhere holds a file of the old folder open: it cannot be deleted.
if (step == "switched") held = new FileStream(heldFile, FileMode.Open, FileAccess.Read, FileShare.Read);
},
};
var log = new List<string>();
try
{
// The move ends well: the target is the workspace, the left entry is a notice.
await mover.MoveAsync(mover.Survey().Fingerprint, log: log.Add, cancellationToken: context.Cancellation);
}
finally
{
held?.Dispose();
}
Assert.Contains(Loc.L("Archive.Log.WorkspaceMoveLeft", mover.From, 1), log);
var journal = Assert.NotNull(WorkspaceMover.ReadJournal(from));
Assert.Equal(WorkspaceMoveStage.Switched, journal.Stage);
Assert.SequenceEqual([ids[1].ToString("N")], journal.Entries);
Assert.Equal(2, new WorkspaceStore(to).List().Count);
// Taken up once let go: told again, the entry cleared, the journal and the old folder gone.
var told = 0;
var (_, resumed) = await new WorkspaceMover(from, to) { SameVolume = false }.MoveAsync("whatever", (_, _) =>
{
told++;
return Task.CompletedTask;
}, cancellationToken: context.Cancellation);
Assert.True(resumed);
Assert.Equal(1, told);
Assert.False(Directory.Exists(from));
Assert.Equal(2, new WorkspaceStore(to).List().Count);
}
[Test]
public async Task AMoveCutInsideAnEntryLeavingAPartFinishesWithEveryFileWhole()
{
var (from, ids) = Workspace(projects: 2);
var before = Contents(from);
var to = Path.Combine(context.CreateTempDirectory("target"), "moved");
using var stop = CancellationTokenSource.CreateLinkedTokenSource(context.Cancellation);
var copied = 0;
var first = new WorkspaceMover(from, to)
{
SameVolume = false,
Cut = (step, _) =>
{
// The second file of an entry reached the target: the entry is not verified yet.
if (step == "copied" && ++copied == 2) stop.Cancel();
},
};
var fingerprint = first.Survey().Fingerprint;
await Assert.ThrowsAsync<OperationCanceledException>(() => first.MoveAsync(fingerprint, cancellationToken: stop.Token));
Assert.Empty(WorkspaceMover.ReadJournal(from)!.Verified);
// The program was killed while it wrote the next file: half of it is left as a part beside its name.
var proxies = Path.Combine(to, ids.Select(i => i.ToString("N")).Order(StringComparer.Ordinal).First(), "media", "proxies");
Directory.CreateDirectory(proxies);
File.WriteAllBytes(Path.Combine(proxies, "2.jpg" + WorkspaceMover.PartSuffix), new byte[100]);
var (_, resumed) = await new WorkspaceMover(from, to) { SameVolume = false }.MoveAsync("whatever", cancellationToken: context.Cancellation);
Assert.True(resumed);
var after = Contents(to);
foreach (var (name, sha) in before.Where(b => !IsLease(b.Key))) Assert.Equal(sha, after.GetValueOrDefault(name), name);
Assert.Empty(Directory.EnumerateFiles(to, "*" + WorkspaceMover.PartSuffix, SearchOption.AllDirectories));
Assert.False(Directory.Exists(from));
}
[Test]
public async Task AJobFindsItsProjectWhereTheWorkspaceIsNowAndWaitsWhileItIsMoved()
{
var (from, ids) = Workspace(projects: 1);
var id = ids[0];
const string missing = "Errors.Workspace.NotCheckedOut";
Assert.Equal(WorkspaceStore.FullRoot(from), WorkspaceJobRoots.Resolve(from, id, null, missing));
var other = Assert.Throws<InvalidOperationException>(() => WorkspaceJobRoots.Resolve(from, Guid.CreateVersion7(), null, missing));
Assert.Equal(Loc.L(missing), other.Message);
// A move under way (before its switch): every job of either folder waits for it.
var to = Path.Combine(context.CreateTempDirectory("target"), "moved");
using (var stop = CancellationTokenSource.CreateLinkedTokenSource(context.Cancellation))
{
var moving = new WorkspaceMover(from, to) { SameVolume = false, Cut = (step, _) => { if (step == "copied") stop.Cancel(); } };
await Assert.ThrowsAsync<OperationCanceledException>(() => moving.MoveAsync(moving.Survey().Fingerprint, cancellationToken: stop.Token));
}
Assert.Equal(Loc.L("Errors.Workspace.Moving"), Assert.Throws<InvalidOperationException>(() => WorkspaceJobRoots.Resolve(from, id, null, missing)).Message);
Assert.Equal(Loc.L("Errors.Workspace.Moving"), Assert.Throws<InvalidOperationException>(() => WorkspaceJobRoots.Resolve(to, id, () => from, missing)).Message);
// Past its switch, the source not cleared yet: a job queued for the old folder works in the new one.
var switched = new WorkspaceMover(from, to) { SameVolume = false, Cut = (step, _) => { if (step == "switched") throw new IOException("closed at the switch"); } };
await Assert.ThrowsAsync<IOException>(() => switched.MoveAsync("whatever", cancellationToken: context.Cancellation));
Assert.Equal(WorkspaceMoveStage.Switched, WorkspaceMover.ReadJournal(from)!.Stage);
Assert.Equal(WorkspaceStore.FullRoot(to), WorkspaceJobRoots.Resolve(from, id, null, missing));
// Once ended: the old folder holds nothing; the folder in use does.
await new WorkspaceMover(from, to) { SameVolume = false }.MoveAsync("whatever", cancellationToken: context.Cancellation);
Assert.False(Directory.Exists(from));
Assert.Equal(WorkspaceStore.FullRoot(to), WorkspaceJobRoots.Resolve(from, id, () => to, missing));
Assert.Equal(Loc.L(missing), Assert.Throws<InvalidOperationException>(() => WorkspaceJobRoots.Resolve(from, id, null, missing)).Message);
}
/// <summary>
/// A workspace with <paramref name="projects"/> projects (a working state, media with an empty folder, versions, the
/// lease), its manifest and a trash entry.