diff --git a/src/Titano.Data/Sync/SyncService.cs b/src/Titano.Data/Sync/SyncService.cs index 35d9d0c7..e0efcfc5 100644 --- a/src/Titano.Data/Sync/SyncService.cs +++ b/src/Titano.Data/Sync/SyncService.cs @@ -767,6 +767,9 @@ public sealed class SyncService if (metadata) { var manifest = SequenceWriter.ReadLocked(folder, row.Id); + // Asked before the sidecar is written: frames or flags another process wrote there since this index last + // synced the folder keep it changed for the next scan (ArchiveIndexer.InStepAsync). + var inStep = await Archives.Indexer.InStepAsync(archive, folder, manifest, cancellationToken).ConfigureAwait(false); ManifestStore.WriteSequence(folder.ManifestPath, manifest with { Title = updated.Title, @@ -776,7 +779,7 @@ public sealed class SyncService Versions = manifest.Versions with { Settings = Math.Max(manifest.Versions.Settings, updated.SettingsVersion) }, UpdatedAt = DateTimeOffset.UtcNow, }); - await Archives.Indexer.RecordStampsAsync(archive, folder, row.Id, cancellationToken).ConfigureAwait(false); + if (inStep) await Archives.Indexer.RecordStampsAsync(archive, folder, row.Id, cancellationToken).ConfigureAwait(false); } return updated; } diff --git a/tests/Titano.Data.Tests/Sync/SyncServiceTests.cs b/tests/Titano.Data.Tests/Sync/SyncServiceTests.cs index 9d090650..1a348d07 100644 --- a/tests/Titano.Data.Tests/Sync/SyncServiceTests.cs +++ b/tests/Titano.Data.Tests/Sync/SyncServiceTests.cs @@ -1,6 +1,8 @@ using Titano.Core.Model; using Titano.Core.Project; +using Titano.Data.Archiving; using Titano.Data.Sync; +using Titano.Data.Tests.Archiving; using Titano.Protocol; using Titano.Protocol.Client; using Titano.Testing; @@ -289,6 +291,34 @@ public sealed class SyncServiceTests(TestContext context) Assert.SequenceEqual(["sunset"], (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!.Tags); } + [Test] + public async Task InfoTakenFromTheServerLeavesPhotosAnotherWriterAddedHereToTheNextScan() + { + await using var f = await SyncFixture.CreateAsync(context); + var photos = f.NewPhotos(2); + var local = await f.LocalAsync("Harbour", photos); + var remote = f.Remote.Add("Harbour", photos); + await f.Sync.LinkAsync(f.Server, remote.Id, local.Id, f.Ct); + await f.RefreshAsync(); + + // A desktop sharing this PC's archive imports a photo into the sequence: its own index follows the sidecar, this one not yet. + var (desktop, archive) = await f.Archive.OtherWriterAsync(); + var staged = f.Archive.Stage(ArchiveFixture.Start.AddMinutes(10), seed: 90); + await desktop.Ingest.CommitAsync(new IngestRequest(archive.Id, local.Id, null, null, staged.Path, "IMG_0009.JPG", staged.Size, staged.Sha256, null, null), + f.Ct); + + // The server's new title reaches this PC meanwhile, in its index and the sidecar. + await f.Remote.UpdateSequenceAsync(remote.Id, new UpdateSequenceRequest("Harbour at dusk", null, null, null, null, null), f.Ct); + await f.RefreshAsync(); + var taken = (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!; + Assert.Equal(("Harbour at dusk", 2), (taken.Title, taken.FrameCount)); + + // The next scan still finds the folder changed, and indexes the photo. + Assert.Contains(local.Id, (await f.Archive.ScanAsync()).Sequences); + var row = (await f.Db.Sequences.GetAsync(local.Id, f.Ct))!; + Assert.Equal(("Harbour at dusk", 3), (row.Title, row.FrameCount)); + } + [Test] public async Task TheSameEditOnBothSidesIsAgreedWithoutAConflict() {