Skip to content

Commit ca38dab

Browse files
committed
Populate TransferUtilityDownloadDirectoryResponse with total objects downloaded
stack-info: PR: #4109, branch: GarrettBeatty/stacked/14
1 parent e63ed78 commit ca38dab

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"services": [
3+
{
4+
"serviceName": "S3",
5+
"type": "patch",
6+
"changeLogMessages": [
7+
"Populate TransferUtilityDownloadDirectoryResponse with total objects downloaded"
8+
]
9+
}
10+
]
11+
}

sdk/src/Services/S3/Custom/Transfer/Internal/_bcl+netstandard/DownloadDirectoryCommand.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public override async Task<TransferUtilityDownloadDirectoryResponse> ExecuteAsyn
6565

6666
SemaphoreSlim asyncThrottler = null;
6767
CancellationTokenSource internalCts = null;
68+
int successfulDownloads = 0;
6869

6970
try
7071
{
@@ -107,13 +108,25 @@ await asyncThrottler.WaitAsync(cancellationToken)
107108
var downloadRequest = ConstructTransferUtilityDownloadRequest(s3o, prefixLength);
108109
var command = new DownloadCommand(this._s3Client, downloadRequest);
109110

110-
var task = ExecuteCommandAsync(command, internalCts, asyncThrottler);
111+
var task = ExecuteCommandAsync(command, internalCts, asyncThrottler)
112+
.ContinueWith(t => {
113+
if (t.Status == TaskStatus.RanToCompletion)
114+
{
115+
Interlocked.Increment(ref successfulDownloads);
116+
}
117+
return t;
118+
}, TaskScheduler.Default)
119+
.Unwrap();
120+
111121
pendingTasks.Add(task);
112122
}
113123
await WhenAllOrFirstExceptionAsync(pendingTasks, cancellationToken)
114124
.ConfigureAwait(continueOnCapturedContext: false);
115125

116-
return new TransferUtilityDownloadDirectoryResponse();
126+
return new TransferUtilityDownloadDirectoryResponse
127+
{
128+
ObjectsDownloaded = successfulDownloads
129+
};
117130
}
118131
finally
119132
{

sdk/src/Services/S3/Custom/Transfer/TransferUtilityDownloadDirectoryResponse.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@ namespace Amazon.S3.Transfer
2222
/// </summary>
2323
public class TransferUtilityDownloadDirectoryResponse
2424
{
25+
/// <summary>
26+
/// The number of objects that have been downloaded
27+
/// </summary>
28+
public long ObjectsDownloaded { get; set; }
2529
}
2630
}

0 commit comments

Comments
 (0)