diff --git a/src/Microsoft.DotNet.Build.Tasks.Feed/src/AzureStorageExtensions.cs b/src/Microsoft.DotNet.Build.Tasks.Feed/src/AzureStorageExtensions.cs index 75dc243162c..84c2c882454 100644 --- a/src/Microsoft.DotNet.Build.Tasks.Feed/src/AzureStorageExtensions.cs +++ b/src/Microsoft.DotNet.Build.Tasks.Feed/src/AzureStorageExtensions.cs @@ -32,6 +32,14 @@ public static async Task IsFileIdenticalToBlobAsync(this BlobClient client return blobMD5.Equals(localMD5, StringComparison.OrdinalIgnoreCase); } + var localFileSize = new FileInfo(file).Length; + var blobSize = (await client.GetPropertiesAsync()).Value.ContentLength; + + if (localFileSize != blobSize) + { + return false; + } + int bytesPerMegabyte = 1 * 1024 * 1024; using Stream localFileStream = File.OpenRead(file); byte[] localBuffer = new byte[bytesPerMegabyte]; @@ -42,6 +50,11 @@ public static async Task IsFileIdenticalToBlobAsync(this BlobClient client { long start = localFileStream.Position; localBytesRead = await localFileStream.ReadAsync(localBuffer, 0, bytesPerMegabyte); + if (localBytesRead == 0) + { + // eof == we are done, we have already validated that they are the same size + return true; + } var range = new HttpRange(start, localBytesRead); BlobDownloadInfo download = await client.DownloadAsync(range).ConfigureAwait(false);