fix(archive): a rebase moves no row of the sequence that took the old folder; writers refuse a folder another sequence holds
Round 4 let every row under the old folder follow when that folder holds another sequence now. When the scan took the new holder first, its own row (already rebased into the old folder) then followed the moving sequence too and named that sequence's file, leaving its own export without a row; a second scan did not repair it. Only the moving sequence's own rows now follow because the old folder is taken, and a row of the sequence holding the old folder never follows: its export is in its own folder whatever the other one took along under the same name. The rebase callback now gets the owner of each row. Writers that file into the folder the index has for a sequence checked only that the folder existed. After another index moved the sequence away and another one into that folder, Take server wrote the server's settings into the other sequence's project.json, Save both wrote this PC's copy into its .chronos, and a render sent for the sequence was filed among its exports. SequenceFolders.Holds treats a folder whose sidecar names another sequence exactly like a missing one, and every such writer asks it: settings sync and conflict resolution (Errors.Archive.FolderMoved), Save both's copy and its clean-up, server render filing (503 folder_moved, the upload kept), export downloads, render jobs as they start, proxies sent and proxy passes, the deep analysis checkpoint and the editor's project save. A thumbnail pass refuses a sidecar of another sequence before it opens the pack. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit b406a4f6a9a7a3121e9e40289663fb62ee31948e)
This commit is contained in:
1 parent
26b03d1c6d
commit
8c2b9f1bfe
17 files changed
+260
-57
No files matched your search
@@ -123,6 +123,13 @@ internal sealed class ArchiveFixture : IAsyncDisposable
|
||||
return (path, bytes.Length, Convert.ToHexStringLower(SHA256.HashData(bytes)));
|
||||
}
|
||||
|
||||
/// <summary>Every file under <paramref name="folder"/> with the hash of its content, in path order: what a test compares to tell that nothing there changed.</summary>
|
||||
public static List<string> FilesOf(string folder) =>
|
||||
[
|
||||
.. Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories).Order(StringComparer.Ordinal)
|
||||
.Select(p => $"{Path.GetRelativePath(folder, p).Replace('\\', '/')} {Convert.ToHexStringLower(SHA256.HashData(File.ReadAllBytes(p)))}"),
|
||||
];
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
foreach (var owned in _owned) await owned.DisposeAsync();
|
||||
|
||||
@@ -356,31 +356,38 @@ public sealed class MassRenameTests(TestContext context)
|
||||
[Test]
|
||||
public async Task AnExportNeverNamesTheOneAnotherSequenceBroughtIntoItsOldFolder()
|
||||
{
|
||||
// The new folder is scanned after "inbox/a", then before it.
|
||||
foreach (var template in new[] { "moved/{date}", "done/{date}" })
|
||||
// The new folder is scanned after "inbox/a", then before it. "inbox/a" and "inbox/c" each have an export of the
|
||||
// same name: the one of "inbox/a" gone, both there, or the one of "inbox/c" gone.
|
||||
var cases = from template in new[] { "moved/{date}", "done/{date}" }
|
||||
from files in new[] { (A: false, C: true), (A: true, C: true), (A: true, C: false) }
|
||||
select (template, files.A, files.C);
|
||||
foreach (var (template, a, c) in cases)
|
||||
{
|
||||
var label = $"{template}, a {(a ? "there" : "gone")}, c {(c ? "there" : "gone")}";
|
||||
await using var fx = await CreateAsync(context);
|
||||
var ids = await PopulateAsync(fx);
|
||||
// The export of "inbox/a" is gone; "inbox/c" has one of the same name.
|
||||
List<Guid> renders =
|
||||
[
|
||||
await RenderAsync(fx, ids[0], "inbox/a/exports/Clip.mp4", write: false),
|
||||
await RenderAsync(fx, ids[2], "inbox/c/exports/Clip.mp4"),
|
||||
await RenderAsync(fx, ids[0], "inbox/a/exports/Clip.mp4", write: a),
|
||||
await RenderAsync(fx, ids[2], "inbox/c/exports/Clip.mp4", write: c),
|
||||
];
|
||||
if (a) await File.WriteAllTextAsync(fx.Paths.FromRelative("inbox/a/exports/Clip.mp4"), "a", fx.Ct);
|
||||
if (c) await File.WriteAllTextAsync(fx.Paths.FromRelative("inbox/c/exports/Clip.mp4"), "c", fx.Ct);
|
||||
var (server, archive) = await fx.OtherWriterAsync();
|
||||
|
||||
// The other index moves "inbox/a", then "inbox/c" into the folder it left, its export along.
|
||||
// The other index moves "inbox/a", then "inbox/c" into the folder it left, their exports along.
|
||||
var first = await server.PlanRenameAsync(archive.Id, [ids[0]], template, null, fx.Ct);
|
||||
await server.ApplyRenameAsync(first, null, fx.Ct);
|
||||
await server.ApplyRenameAsync(await server.PlanRenameAsync(archive.Id, [ids[2]], "inbox/a", null, fx.Ct), null, fx.Ct);
|
||||
|
||||
// The first sequence's row follows its folder, missing there too, and never names the other one's file.
|
||||
// Each row follows its own sequence's folder, its file there or missing there too, and never names the other one's.
|
||||
await fx.ScanAsync();
|
||||
string[] expected = [first.Steps.Single().ToFolder + "/exports/Clip.mp4", "inbox/a/exports/Clip.mp4"];
|
||||
Assert.SequenceEqual(expected, await OutputsAsync(fx, renders), template);
|
||||
Assert.FileExists(fx.Paths.FromRelative(expected[1]));
|
||||
Assert.SequenceEqual(expected, await OutputsAsync(fx, renders), label);
|
||||
if (a) Assert.Equal("a", await File.ReadAllTextAsync(fx.Paths.FromRelative(expected[0]), fx.Ct), label);
|
||||
if (c) Assert.Equal("c", await File.ReadAllTextAsync(fx.Paths.FromRelative(expected[1]), fx.Ct), label);
|
||||
Assert.Equal(0, (await fx.ScanAsync()).Indexed);
|
||||
Assert.SequenceEqual(expected, await OutputsAsync(fx, renders), template);
|
||||
Assert.SequenceEqual(expected, await OutputsAsync(fx, renders), label);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +117,33 @@ public sealed class ProxyTests(TestContext context)
|
||||
Assert.SequenceEqual(proxy, await File.ReadAllBytesAsync(moved.Proxy(0), fx.Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ImagesOfAFolderAnotherSequenceTookAreNotWrittenThere()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var (sequence, frames) = await HeifSequenceAsync(fx);
|
||||
Photos.WriteSeries(Path.Combine(fx.Paths.Root, "inbox", "other"), Start.AddDays(3), 2, firstSeed: 70);
|
||||
await fx.ScanAsync();
|
||||
var stranger = (await fx.Db.Sequences.ListLocationsAsync(fx.Archive.Id, fx.Ct)).Single(l => l.Folder == "inbox/other").Id;
|
||||
var images = fx.Service.Images;
|
||||
var (server, archive) = await fx.OtherWriterAsync();
|
||||
await server.ApplyRenameAsync(await server.PlanRenameAsync(archive.Id, [sequence.Id], "moved/{date}", null, fx.Ct), null, fx.Ct);
|
||||
await server.ApplyRenameAsync(await server.PlanRenameAsync(archive.Id, [stranger], sequence.Folder, null, fx.Ct), null, fx.Ct);
|
||||
var folder = fx.Paths.Sequence(sequence.Folder).Folder;
|
||||
var before = FilesOf(folder);
|
||||
|
||||
// This index still has the sequence in the folder the other sequence holds now: a proxy sent, a proxy pass and a
|
||||
// thumbnail pass write nothing there.
|
||||
Assert.Equal(ProxyStoreResult.Gone, await images.StoreProxyAsync(fx.Archive, sequence, frames[0], Proxy(frames[0].CapturedAt!.Value, 2), fx.Ct));
|
||||
foreach (var pass in new Func<Task<ImagePassResult>>[]
|
||||
{
|
||||
() => images.BuildProxiesAsync(fx.Archive, sequence, force: false, 0, (_, _) => ValueTask.CompletedTask, fx.Ct),
|
||||
() => images.BuildThumbnailsAsync(fx.Archive, sequence, force: true, 0, (_, _) => ValueTask.CompletedTask, fx.Ct),
|
||||
})
|
||||
Assert.Equal(Loc.L("Errors.Archive.FolderMoved"), (await Assert.ThrowsAsync<InvalidOperationException>(pass)).Message);
|
||||
Assert.SequenceEqual(before, FilesOf(folder));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AProxyPassLetsAnotherProcessReorganizeBetweenItsBatches()
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using Chronos.Core.Project;
|
||||
using Chronos.Core.Video;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Data.Processing;
|
||||
using Chronos.Data.Tests.Archiving;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Data.Tests.Processing;
|
||||
@@ -154,6 +155,27 @@ public sealed class RenderJobTests(TestContext context)
|
||||
Assert.False(Directory.Exists(left));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARenderNeverWritesIntoAnotherSequenceMovedIntoItsFolder()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fx.AddAsync(Scene());
|
||||
var stranger = await fx.AddAsync(Scene(), "Other");
|
||||
var (server, archive) = await fx.Archive.OtherWriterAsync();
|
||||
await server.ApplyRenameAsync(await server.PlanRenameAsync(archive.Id, [sequence.Id], "Moved/{date}", null, fx.Ct), null, fx.Ct);
|
||||
await server.ApplyRenameAsync(await server.PlanRenameAsync(archive.Id, [stranger.Id], sequence.Folder, null, fx.Ct), null, fx.Ct);
|
||||
var folder = fx.Folder(sequence).Folder;
|
||||
var before = ArchiveFixture.FilesOf(folder);
|
||||
await fx.StartEngineAsync();
|
||||
|
||||
// A server sharing the archive moved the folder away and the other sequence into it; this index has not scanned since.
|
||||
var job = await fx.EnqueueAsync(ProcessingJobs.Render(sequence, Mjpeg, 96, 64));
|
||||
var failed = await fx.WaitForAsync(job.Id, JobState.Failed);
|
||||
Assert.Equal(Loc.L("Errors.Archive.FolderMoved"), failed.Error);
|
||||
Assert.SequenceEqual(before, ArchiveFixture.FilesOf(folder), "the other sequence's files are untouched");
|
||||
Assert.Empty(await fx.Db.Renders.ListBySequenceAsync(sequence.Id, fx.Ct));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AFrameThatNoLongerDecodesIsReplacedByItsNeighbourAndLeftOutNextTime()
|
||||
{
|
||||
|
||||
@@ -530,6 +530,47 @@ public sealed class SyncServiceTests(TestContext context)
|
||||
"the moved project is this PC's version");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TakeServerAndSaveBothWriteNothingIntoAnotherSequenceMovedIntoTheFolder()
|
||||
{
|
||||
const string strangers = """{"exposure":{"deflickerWindow":{"isAuto":false,"manual":7}}}""";
|
||||
foreach (var resolution in new[] { SyncResolution.TakeServer, SyncResolution.SaveBoth })
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var (local, remote) = await ConflictAsync(f);
|
||||
var stranger = await f.LocalAsync("Stranger", f.NewPhotos(2), strangers);
|
||||
var folder = f.Archive.Paths.Sequence(local.Folder);
|
||||
|
||||
// Another index moves the folder away while the server's version is read, then another sequence (first parked
|
||||
// elsewhere: its folder is the same name with a number) into the folder it left; this index has scanned neither.
|
||||
var (other, archive) = await f.Archive.OtherWriterAsync();
|
||||
List<string>? before = null;
|
||||
f.Remote.OnceBeforeManifest = async () =>
|
||||
{
|
||||
foreach (var (id, template) in new[] { (local.Id, "moved/{title}"), (stranger.Id, "parked/{title}"), (stranger.Id, local.Folder) })
|
||||
await other.ApplyRenameAsync(await other.PlanRenameAsync(archive.Id, [id], template, null, f.Ct), null, f.Ct);
|
||||
before = ArchiveFixture.FilesOf(folder.Folder);
|
||||
};
|
||||
var refused = await Assert.ThrowsAsync<SyncConflictChangedException>(() => f.Sync.ResolveAsync(f.Remote, remote.Id, resolution, f.Ct));
|
||||
Assert.Equal(Loc.L("Errors.Archive.FolderMoved"), refused.Message, $"{resolution}: the user hears to try again after the next scan");
|
||||
|
||||
// Neither version went into the other sequence's folder, nor replaced this PC's where the sequence is.
|
||||
Assert.Equal(stranger.Id, SequenceTrash.SidecarId(folder.ManifestPath), "the other sequence holds the folder");
|
||||
Assert.SequenceEqual(before!, ArchiveFixture.FilesOf(folder.Folder), $"{resolution}: the other sequence's files are untouched");
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.SettingsJson), "nothing applied");
|
||||
var moved = f.Archive.Paths.Sequence("moved/Holy grail");
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window41, await File.ReadAllTextAsync(moved.ProjectPath, f.Ct)), "the moved project is this PC's version");
|
||||
Assert.Empty(Directory.GetFiles(moved.MetaDirectory, SyncService.SavedCopyPattern));
|
||||
|
||||
// Chosen again once this index's scan found both, it is done where the sequence is now.
|
||||
await f.Archive.ScanAsync();
|
||||
var copy = await f.Sync.ResolveAsync(f.Remote, remote.Id, resolution, f.Ct);
|
||||
Assert.True(SyncRules.SameSettings(SyncFixture.Window33, await File.ReadAllTextAsync(moved.ProjectPath, f.Ct)), resolution.ToString());
|
||||
Assert.Equal(resolution == SyncResolution.SaveBoth, copy is not null && Path.GetDirectoryName(copy) == moved.MetaDirectory);
|
||||
Assert.True(SyncRules.SameSettings(strangers, await File.ReadAllTextAsync(folder.ProjectPath, f.Ct)), "the other sequence keeps its own");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task KeepMineRefusesWhenTheServerChangedAfterTheConflictWasShown()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user