fix(sync): finish stuck downloads and keep edits saved during a comparison
A download whose .part already held the whole original (the job stopped while hashing it) or more asked the server to resume past the end, got 416 and failed on every retry; such a part is now hashed again, and one the server cannot resume starts over (CD-1). Auto-sync pulled the server's settings with the copy of the sequence read when the comparison began, so an edit saved on this PC meanwhile was overwritten unseen. The payload is now applied in one step under the sequence lease and only while the local settings version is the one read; otherwise nothing is written and the change is settled as a conflict (CD-3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
4 files changed
+137
-27
No files matched your search
@@ -112,16 +112,19 @@ public sealed class SyncServerTests(TestContext context)
|
||||
var (_, _, token) = await server.UserAsync("alberto", "editor");
|
||||
await using var studio = await SyncClient.StartAsync(context, server, token, "studio");
|
||||
await using var laptop = await SyncClient.StartAsync(context, server, token, "laptop");
|
||||
var photos = Enumerable.Range(20, 3).Select(SyncClient.Photo).ToList();
|
||||
var photos = Enumerable.Range(20, 4).Select(SyncClient.Photo).ToList();
|
||||
var local = await studio.LocalAsync("Aurora", photos);
|
||||
await studio.WaitAsync((await studio.Sync.EnqueueUploadAsync(studio.Engine, studio.Server, local)).Id);
|
||||
var remoteId = (await studio.EntryAsync("Aurora")).Link!.RemoteId;
|
||||
|
||||
// An earlier attempt left half of one original, and a damaged half of another.
|
||||
// An earlier attempt left half of one original, a damaged half of another, a third complete (stopped while it was
|
||||
// being hashed) and a fourth longer than the file: the server cannot resume either of the last two (416).
|
||||
var staging = Path.Combine(laptop.Archive.RootPath, ".titano", "staging", "sync-" + remoteId.ToString("N"));
|
||||
Directory.CreateDirectory(staging);
|
||||
await File.WriteAllBytesAsync(Path.Combine(staging, SyncClient.Sha(photos[0]) + ".jpg.part"), photos[0][..(photos[0].Length / 2)]);
|
||||
await File.WriteAllBytesAsync(Path.Combine(staging, SyncClient.Sha(photos[1]) + ".jpg.part"), new byte[photos[1].Length / 2]);
|
||||
await File.WriteAllBytesAsync(Path.Combine(staging, SyncClient.Sha(photos[2]) + ".jpg.part"), photos[2]);
|
||||
await File.WriteAllBytesAsync(Path.Combine(staging, SyncClient.Sha(photos[3]) + ".jpg.part"), [.. photos[3], .. new byte[64]]);
|
||||
|
||||
await laptop.Sync.RefreshAsync(laptop.Remote, new SyncPolicy(), context.Cancellation);
|
||||
var download = await laptop.Sync.EnqueueDownloadAsync(laptop.Engine, laptop.Server, remoteId, "Aurora", SyncDownloadMode.Originals, laptop.Archive.Id);
|
||||
|
||||
Reference in new issue
Block a user