From f2ee62efde7b11f8b67cf40e4f0570b48cae6fde Mon Sep 17 00:00:00 2001 From: chrislu Date: Tue, 28 Oct 2025 22:07:07 -0700 Subject: [PATCH] ensure the expected size --- weed/replication/sink/azuresink/azure_sink.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/weed/replication/sink/azuresink/azure_sink.go b/weed/replication/sink/azuresink/azure_sink.go index 598be7f3e..8eb2218e7 100644 --- a/weed/replication/sink/azuresink/azure_sink.go +++ b/weed/replication/sink/azuresink/azure_sink.go @@ -190,13 +190,14 @@ func (g *AzureSink) handleExistingBlob(appendBlobClient *appendblob.Client, key return false, fmt.Errorf("azure get properties %s/%s: %w", g.container, key, propErr) } - // Check if we can skip writing based on modification time. + // Check if we can skip writing based on modification time and size. if entry.Attributes != nil && entry.Attributes.Mtime > 0 && props.LastModified != nil && props.ContentLength != nil { const clockSkewTolerance = int64(2) // seconds - allow small clock differences remoteMtime := props.LastModified.Unix() localMtime := entry.Attributes.Mtime - // Skip if remote is newer/same (within skew tolerance) and has content, OR if both are zero-length. - if remoteMtime >= localMtime-clockSkewTolerance && ((*props.ContentLength > 0) || (*props.ContentLength == 0 && totalSize == 0)) { + // Skip if remote is newer/same (within skew tolerance) and has the SAME size. + // This prevents skipping partial/corrupted files that may have a newer mtime. + if remoteMtime >= localMtime-clockSkewTolerance && *props.ContentLength == int64(totalSize) { glog.V(2).Infof("skip overwriting %s/%s: remote is up-to-date (remote mtime: %d >= local mtime: %d, size: %d)", g.container, key, remoteMtime, localMtime, *props.ContentLength) return false, nil