|
19 | 19 | #import "AWSS3TransferUtilityDatabaseHelper.h"
|
20 | 20 | #import "AWSS3TransferUtilityTasks.h"
|
21 | 21 | #import "AWSS3CreateMultipartUploadRequest+RequestHeaders.h"
|
| 22 | +#import "AWSS3TransferUtilityTasks+Completion.h" |
22 | 23 |
|
23 | 24 | #import <AWSCore/AWSFMDB.h>
|
24 | 25 | #import <AWSCore/AWSSynchronizedMutableDictionary.h>
|
@@ -1178,14 +1179,11 @@ - (void) retryUpload: (AWSS3TransferUtilityUploadTask *) transferUtilityUploadTa
|
1178 | 1179 | if (![[NSFileManager defaultManager] fileExistsAtPath:transferUtilityUploadTask.file]) {
|
1179 | 1180 | NSDictionary *userInfo = [NSDictionary dictionaryWithObject:@"Local file not found"
|
1180 | 1181 | forKey:@"Message"];
|
1181 |
| - |
1182 | 1182 | NSError *error = [NSError errorWithDomain:AWSS3TransferUtilityErrorDomain
|
1183 | 1183 | code:AWSS3TransferUtilityErrorLocalFileNotFound
|
1184 | 1184 | userInfo:userInfo];
|
1185 |
| - |
1186 |
| - if (transferUtilityUploadTask.expression.completionHandler) { |
1187 |
| - transferUtilityUploadTask.expression.completionHandler(transferUtilityUploadTask, error); |
1188 |
| - } |
| 1185 | + transferUtilityUploadTask.error = error; |
| 1186 | + [self completeTask:transferUtilityUploadTask]; |
1189 | 1187 | }
|
1190 | 1188 | else {
|
1191 | 1189 | //This will update the AWSS3TransferUtilityUploadTask passed into it with a new URL Session
|
@@ -1705,11 +1703,9 @@ -(void) retryUploadSubTask: (AWSS3TransferUtilityMultiPartUploadTask *) transfer
|
1705 | 1703 | //cancel the multipart transfer
|
1706 | 1704 | [transferUtilityMultiPartUploadTask cancel];
|
1707 | 1705 | transferUtilityMultiPartUploadTask.status = AWSS3TransferUtilityTransferStatusError;
|
1708 |
| - |
| 1706 | + transferUtilityMultiPartUploadTask.error = subTaskCreationError; |
1709 | 1707 | //Call the completion handler if one was present
|
1710 |
| - if (transferUtilityMultiPartUploadTask.expression.completionHandler) { |
1711 |
| - transferUtilityMultiPartUploadTask.expression.completionHandler(transferUtilityMultiPartUploadTask, subTaskCreationError); |
1712 |
| - } |
| 1708 | + [self completeTask:transferUtilityMultiPartUploadTask]; |
1713 | 1709 | }
|
1714 | 1710 | }
|
1715 | 1711 |
|
@@ -2210,10 +2206,8 @@ - (void)URLSession:(NSURLSession *)session
|
2210 | 2206 | }
|
2211 | 2207 |
|
2212 | 2208 | [self cleanupForUploadTask:uploadTask];
|
2213 |
| - |
2214 |
| - if(uploadTask.expression.completionHandler) { |
2215 |
| - uploadTask.expression.completionHandler(uploadTask,uploadTask.error); |
2216 |
| - } |
| 2209 | + |
| 2210 | + [self completeTask:uploadTask]; |
2217 | 2211 | return;
|
2218 | 2212 | }
|
2219 | 2213 | else if ([transferUtilityTask isKindOfClass:[AWSS3TransferUtilityMultiPartUploadTask class]]) {
|
@@ -2278,10 +2272,8 @@ - (void)URLSession:(NSURLSession *)session
|
2278 | 2272 | transferUtilityMultiPartUploadTask.status = AWSS3TransferUtilityTransferStatusError;
|
2279 | 2273 |
|
2280 | 2274 | //Execute call back if provided.
|
2281 |
| - if(transferUtilityMultiPartUploadTask.expression.completionHandler) { |
2282 |
| - transferUtilityMultiPartUploadTask.expression.completionHandler(transferUtilityMultiPartUploadTask, transferUtilityMultiPartUploadTask.error); |
2283 |
| - } |
2284 |
| - |
| 2275 | + [self completeTask:transferUtilityMultiPartUploadTask]; |
| 2276 | + |
2285 | 2277 | //Make sure all other parts that are in progress are canceled.
|
2286 | 2278 | for (NSNumber *key in [transferUtilityMultiPartUploadTask.inProgressPartsDictionary allKeys]) {
|
2287 | 2279 | AWSS3TransferUtilityUploadSubTask *subTask = [transferUtilityMultiPartUploadTask.inProgressPartsDictionary objectForKey:key];
|
@@ -2364,10 +2356,8 @@ - (void)URLSession:(NSURLSession *)session
|
2364 | 2356 | userInfo:userInfo];
|
2365 | 2357 |
|
2366 | 2358 | //Execute call back if provided.
|
2367 |
| - if(transferUtilityMultiPartUploadTask.expression.completionHandler) { |
2368 |
| - transferUtilityMultiPartUploadTask.expression.completionHandler(transferUtilityMultiPartUploadTask, transferUtilityMultiPartUploadTask.error); |
2369 |
| - } |
2370 |
| - |
| 2359 | + [self completeTask:transferUtilityMultiPartUploadTask]; |
| 2360 | + |
2371 | 2361 | //Abort the request, so the server can clean up any partials.
|
2372 | 2362 | [self callAbortMultiPartForUploadTask:transferUtilityMultiPartUploadTask];
|
2373 | 2363 |
|
@@ -2402,9 +2392,7 @@ - (void)URLSession:(NSURLSession *)session
|
2402 | 2392 | [self cleanupForMultiPartUploadTask:transferUtilityMultiPartUploadTask];
|
2403 | 2393 |
|
2404 | 2394 | //Call the callback function is specified.
|
2405 |
| - if(transferUtilityMultiPartUploadTask.expression.completionHandler) { |
2406 |
| - transferUtilityMultiPartUploadTask.expression.completionHandler(transferUtilityMultiPartUploadTask,error); |
2407 |
| - } |
| 2395 | + [self completeTask:transferUtilityMultiPartUploadTask]; |
2408 | 2396 | return nil;
|
2409 | 2397 | }];
|
2410 | 2398 | }
|
@@ -2463,12 +2451,7 @@ - (void)URLSession:(NSURLSession *)session
|
2463 | 2451 | downloadTask.expression.progressBlock(downloadTask, downloadTask.progress);
|
2464 | 2452 | }
|
2465 | 2453 | }
|
2466 |
| - if (downloadTask.expression.completionHandler) { |
2467 |
| - downloadTask.expression.completionHandler(downloadTask, |
2468 |
| - downloadTask.location, |
2469 |
| - downloadTask.data, |
2470 |
| - downloadTask.error); |
2471 |
| - } |
| 2454 | + [self completeTask:downloadTask]; |
2472 | 2455 | [self.completedTaskDictionary setObject:downloadTask forKey:downloadTask.transferID];
|
2473 | 2456 | [self.taskDictionary removeObjectForKey:@(downloadTask.sessionTask.taskIdentifier)];
|
2474 | 2457 | [AWSS3TransferUtilityDatabaseHelper deleteTransferRequestFromDB:downloadTask.transferID databaseQueue:_databaseQueue];
|
@@ -2539,6 +2522,12 @@ - (void)URLSession:(NSURLSession *)session
|
2539 | 2522 |
|
2540 | 2523 | #pragma mark - Helper methods
|
2541 | 2524 |
|
| 2525 | +- (void)completeTask:(AWSS3TransferUtilityTask *)task { |
| 2526 | + [task complete]; |
| 2527 | + // complete task before removing from dictionary |
| 2528 | + [self.completedTaskDictionary removeObjectForKey:task.transferID]; |
| 2529 | +} |
| 2530 | + |
2542 | 2531 | - (void) cleanupForMultiPartUploadTask: (AWSS3TransferUtilityMultiPartUploadTask *) task {
|
2543 | 2532 |
|
2544 | 2533 | //Add it to list of completed Tasks
|
|
0 commit comments