Skip to content

Commit 11b6dc8

Browse files
authored
Fixed bug when downloading zero length StorageResources in a StorageResourceContainer will throw an exception. (Azure#36368)
1 parent 4487c9b commit 11b6dc8

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

sdk/storage/Azure.Storage.DataMovement/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Fix to prevent empty strings or null to be passed as paths for `LocalFileStorageResource` and `LocalDirectoryStorageResourceContainer`.
1414
- Fixed `ErrorHandlingOptions.ContinueOnFailure` not be respected.
1515
- Fixed bug where resuming a transfer where the source and destination is a `StorageResourceContainer` would throw a null reference exception.
16+
- Fixed bug when downloading zero length `StorageResource`s in a `StorageResourceContainer` will throw an exception.
1617

1718
### Other Changes
1819

sdk/storage/Azure.Storage.DataMovement/src/UriToStreamJobPart.cs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -193,23 +193,7 @@ internal async Task UnknownDownloadInternal()
193193
// length is 0 bytes.
194194
if (initialResult == default || initialLength == 0)
195195
{
196-
// We just need to at minimum create the file
197-
bool succesfulCreation = await CopyToStreamInternal(
198-
offset: 0,
199-
sourceLength: 0,
200-
source: default,
201-
expectedLength: 0).ConfigureAwait(false);
202-
if (succesfulCreation)
203-
{
204-
// Queue the work to end the download
205-
await QueueChunkToChannelAsync(
206-
async () =>
207-
await CompleteFileDownload().ConfigureAwait(false)).ConfigureAwait(false);
208-
}
209-
else
210-
{
211-
await CheckAndUpdateCancellationStatusAsync().ConfigureAwait(false);
212-
}
196+
await CreateZeroLengthDownload().ConfigureAwait(false);
213197
return;
214198
}
215199

@@ -272,7 +256,11 @@ await DownloadStreamingInternal(range: httpRange).ConfigureAwait(false))
272256
internal async Task LengthKnownDownloadInternal()
273257
{
274258
long totalLength = _sourceResource.Length.Value;
275-
if (_initialTransferSize <= totalLength)
259+
if (totalLength == 0)
260+
{
261+
await CreateZeroLengthDownload().ConfigureAwait(false);
262+
}
263+
else if (_initialTransferSize <= totalLength)
276264
{
277265
// To prevent requesting a range that is invalid when
278266
// we already know the length we can just make one get blob request.
@@ -309,6 +297,7 @@ await CompleteFileDownload().ConfigureAwait(false))
309297

310298
// Get list of ranges of the blob
311299
IList<HttpRange> ranges = GetRangesList(0, totalLength, rangeSize);
300+
312301
// Create Download Chunk event handler to manage when the ranges finish downloading
313302
_downloadChunkHandler = GetDownloadChunkHandler(
314303
currentTranferred: 0,
@@ -503,5 +492,26 @@ internal async Task DisposeHandlers()
503492
await _downloadChunkHandler.DisposeAsync().ConfigureAwait(false);
504493
}
505494
}
495+
496+
private async Task CreateZeroLengthDownload()
497+
{
498+
// We just need to at minimum create the file
499+
bool succesfulCreation = await CopyToStreamInternal(
500+
offset: 0,
501+
sourceLength: 0,
502+
source: default,
503+
expectedLength: 0).ConfigureAwait(false);
504+
if (succesfulCreation)
505+
{
506+
// Queue the work to end the download
507+
await QueueChunkToChannelAsync(
508+
async () =>
509+
await CompleteFileDownload().ConfigureAwait(false)).ConfigureAwait(false);
510+
}
511+
else
512+
{
513+
await CheckAndUpdateCancellationStatusAsync().ConfigureAwait(false);
514+
}
515+
}
506516
}
507517
}

0 commit comments

Comments
 (0)