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
@@ -397,7 +397,11 @@ internal sealed class SyncTransfers(SyncService sync)
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>A verified copy in staging: resumed from a partial download, accepted only with the manifest's SHA-256 (two attempts).</summary>
|
||||
/// <summary>
|
||||
/// A verified copy in staging: resumed from a partial download, accepted only with the manifest's SHA-256 (two
|
||||
/// attempts). A part as long as the file (a job stopped while hashing it) is only hashed again; a part the server can
|
||||
/// no longer resume (416) starts over.
|
||||
/// </summary>
|
||||
private static async Task<string> FetchOriginalAsync(ISyncRemote remote, ManifestFrame frame, string staging, CancellationToken cancellationToken)
|
||||
{
|
||||
var sha = frame.Sha256.ToLowerInvariant();
|
||||
@@ -407,8 +411,19 @@ internal sealed class SyncTransfers(SyncService sync)
|
||||
var part = target + ".part";
|
||||
for (var attempt = 1; ; attempt++)
|
||||
{
|
||||
await using (var file = new FileStream(part, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
|
||||
await remote.DownloadFrameAsync(frame.Id, "original", file, cancellationToken).ConfigureAwait(false);
|
||||
if (!File.Exists(part) || new FileInfo(part).Length < frame.Size)
|
||||
{
|
||||
try
|
||||
{
|
||||
await using (var file = new FileStream(part, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
|
||||
await remote.DownloadFrameAsync(frame.Id, "original", file, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (TitanoApiException ex) when (ex.Status == HttpStatusCode.RequestedRangeNotSatisfiable && attempt == 1)
|
||||
{
|
||||
File.Delete(part);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (await TitanoClient.HashFileAsync(part, cancellationToken).ConfigureAwait(false) == sha)
|
||||
{
|
||||
File.Move(part, target, overwrite: true);
|
||||
|
||||
Reference in new issue
Block a user