Skip to content

Commit 374a93a

Browse files
Brennan StehlingbrennanMKE
authored andcommitted
WIP
1 parent fbb1de7 commit 374a93a

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

AWSS3/AWSS3TransferUtility.m

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -433,23 +433,22 @@ - (void) hydrateFromDB:(NSMutableDictionary *) tempMultiPartMasterTaskDictionary
433433
}
434434
}
435435

436-
- (void) linkTransfersToNSURLSession:(NSMutableDictionary *) tempMultiPartMasterTaskDictionary
437-
tempTransferDictionary: (NSMutableDictionary *) tempTransferDictionary
438-
completionHandler: (void (^)(NSError *_Nullable error)) completionHandler{
436+
- (void)linkTransfersToNSURLSession:(NSMutableDictionary *) tempMultiPartMasterTaskDictionary
437+
tempTransferDictionary:(NSMutableDictionary *)tempTransferDictionary
438+
completionHandler:(void (^)(NSError *_Nullable error)) completionHandler {
439439
//Get tasks from the NSURLSession and reattach to them.
440440
//getTasksWithCompletionHandler is an ansynchronous task, so the thread that is calling this method will not be blocked.
441441
[self.session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
442-
442+
443443
//Loop through all the upload Tasks.
444-
for( NSURLSessionUploadTask *task in uploadTasks) {
444+
for (NSURLSessionUploadTask *task in uploadTasks) {
445445
AWSDDLogDebug(@"Iterating through task Identifier [%lu]", (unsigned long)task.taskIdentifier);
446446
NSError *taskError = [task error];
447-
447+
448448
//Get the Task
449449
id obj = [tempTransferDictionary objectForKey:@(task.taskIdentifier)];
450-
451-
if ([obj isKindOfClass:[AWSS3TransferUtilityUploadTask class]])
452-
{
450+
451+
if ([obj isKindOfClass:[AWSS3TransferUtilityUploadTask class]]) {
453452
//Found a upload task.
454453
AWSS3TransferUtilityUploadTask *uploadTask = obj;
455454
uploadTask.sessionTask = task;
@@ -469,11 +468,11 @@ - (void) linkTransfersToNSURLSession:(NSMutableDictionary *) tempMultiPartMaster
469468
filePath:uploadTask.file];
470469
continue;
471470
}
472-
471+
473472
//Check if it is InProgress
474473
if (uploadTask.status == AWSS3TransferUtilityTransferStatusInProgress) {
475474
//Check if the the underlying NSURLSession task is completed. If so, delete the record from the DB, clean up any temp files and call the completion handler.
476-
if ([task state] == NSURLSessionTaskStateCompleted) {
475+
if (task.state == NSURLSessionTaskStateCompleted) {
477476
//Set progress to 100%
478477
uploadTask.progress.completedUnitCount = uploadTask.progress.totalUnitCount;
479478
uploadTask.status = AWSS3TransferUtilityTransferStatusCompleted;
@@ -484,7 +483,7 @@ - (void) linkTransfersToNSURLSession:(NSMutableDictionary *) tempMultiPartMaster
484483
continue;
485484
}
486485
//If it is in any other status than running, then we need to recover by retrying.
487-
if ([task state] != NSURLSessionTaskStateRunning) {
486+
if (task.state != NSURLSessionTaskStateRunning) {
488487
//We think the task in IN_PROGRESS. The underlying task is not running.
489488
//Recover the situation by retrying.
490489
[self retryUpload:uploadTask];
@@ -522,15 +521,15 @@ - (void) linkTransfersToNSURLSession:(NSMutableDictionary *) tempMultiPartMaster
522521
//Check if this is in progress
523522
if (downloadTask.status == AWSS3TransferUtilityTransferStatusInProgress) {
524523

525-
if ([task state] == NSURLSessionTaskStateCompleted) {
524+
if (task.state == NSURLSessionTaskStateCompleted) {
526525
//Set progress to 100%
527526
downloadTask.progress.completedUnitCount = downloadTask.progress.totalUnitCount;
528527
downloadTask.status = AWSS3TransferUtilityTransferStatusCompleted;
529528
[self markTransferAsCompleted:downloadTask taskError:taskError temporaryFileCreated:NO filePath:@""];
530529
continue;
531530
}
532531
//Check if the underlying task's status is not in Progress.
533-
else if ([task state] != NSURLSessionTaskStateRunning) {
532+
else if (task.state != NSURLSessionTaskStateRunning) {
534533
//We think the task in Progress. The underlying task is not in progress.
535534
//Recover the situation by retrying
536535
[self retryDownload:downloadTask];
@@ -716,10 +715,9 @@ - (AWSS3TransferUtilityDownloadTask *)hydrateDownloadTask:(NSMutableDictionary *
716715
}
717716

718717

719-
-( AWSS3TransferUtilityMultiPartUploadTask *) hydrateMultiPartUploadTask: (NSMutableDictionary *) task
720-
sessionIdentifier: (NSString *) sessionIdentifier
721-
databaseQueue: (AWSFMDatabaseQueue *) databaseQueue
722-
{
718+
- (AWSS3TransferUtilityMultiPartUploadTask *)hydrateMultiPartUploadTask: (NSMutableDictionary *) task
719+
sessionIdentifier:(NSString *) sessionIdentifier
720+
databaseQueue: (AWSFMDatabaseQueue *) databaseQueue {
723721
AWSS3TransferUtilityMultiPartUploadTask *transferUtilityMultiPartUploadTask = [AWSS3TransferUtilityMultiPartUploadTask new];
724722
[transferUtilityMultiPartUploadTask integrateWithTransferUtility:self];
725723
transferUtilityMultiPartUploadTask.nsURLSessionID = sessionIdentifier;

AWSS3/AWSS3TransferUtilityTasks.m

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,15 @@ - (void)suspend {
256256
//
257257

258258
// Cancel session task for all subtasks which are in progress and set status to paused
259-
for (NSNumber *taskIdentifier in self.inProgressPartsDictionary.allKeys) {
260-
AWSS3TransferUtilityUploadSubTask *inProgressSubTask = self.inProgressPartsDictionary[taskIdentifier];
259+
for (AWSS3TransferUtilityUploadSubTask *inProgressSubTask in self.inProgressTasks) {
261260
// Note: This can happen due to lack of thread-safety
262261
if (!inProgressSubTask) {
262+
NSCAssert(NO, @"Sub Task should not be nil!");
263263
continue;
264264
}
265265

266266
// cancel the URLSessionTask
267+
inProgressSubTask.status = AWSS3TransferUtilityTransferStatusPaused;
267268
[inProgressSubTask.sessionTask cancel];
268269

269270
AWSS3TransferUtilityUploadSubTask *subTask = [AWSS3TransferUtilityUploadSubTask new];
@@ -286,7 +287,7 @@ - (void)suspend {
286287
AWSDDLogError(@"Error creating AWSS3TransferUtilityUploadSubTask [%@]", error);
287288
self.error = error;
288289
} else {
289-
self.inProgressPartsDictionary[taskIdentifier] = nil;
290+
self.inProgressPartsDictionary[@(inProgressSubTask.taskIdentifier)] = nil;
290291

291292
[AWSS3TransferUtilityDatabaseHelper updateTransferRequestInDB:inProgressSubTask.transferID partNumber:inProgressSubTask.partNumber taskIdentifier:inProgressSubTask.taskIdentifier eTag:nil status:AWSS3TransferUtilityTransferStatusCancelled retry_count:0 databaseQueue:self.databaseQueue];
292293

@@ -367,8 +368,8 @@ - (void)moveInProgressAndSuspendedTasks {
367368
}
368369

369370
for (AWSS3TransferUtilityUploadSubTask *aSubTask in inProgressAndSuspendedTasks) {
370-
[self.inProgressPartsDictionary removeObjectForKey:@(aSubTask.taskIdentifier)];
371-
[self.waitingPartsDictionary setObject:aSubTask forKey:@(aSubTask.taskIdentifier)];
371+
self.inProgressPartsDictionary[@(aSubTask.taskIdentifier)] = nil;
372+
self.waitingPartsDictionary[@(aSubTask.taskIdentifier)] = aSubTask;
372373
}
373374
}
374375

@@ -383,7 +384,7 @@ - (void)moveWaitingTasksToInProgress:(BOOL)startTransfer {
383384
AWSS3TransferUtilityUploadSubTask *nextSubTask = [[self.waitingPartsDictionary allValues] objectAtIndex:0];
384385

385386
//Add to inProgress list
386-
[self.inProgressPartsDictionary setObject:nextSubTask forKey:@(nextSubTask.taskIdentifier)];
387+
self.inProgressPartsDictionary[@(nextSubTask.taskIdentifier)] = nextSubTask;
387388

388389
//Remove it from the waitingList
389390
[self.waitingPartsDictionary removeObjectForKey:@(nextSubTask.taskIdentifier)];
@@ -402,7 +403,7 @@ - (void)completeUploadSubTask:(AWSS3TransferUtilityUploadSubTask *)subTask
402403

403404
//Add it to completed parts and remove it from remaining parts.
404405
[self.completedPartsSet addObject:subTask];
405-
[self.inProgressPartsDictionary removeObjectForKey:@(subTask.taskIdentifier)];
406+
self.inProgressPartsDictionary[@(subTask.taskIdentifier)] = nil;
406407
//Update progress
407408
self.progress.completedUnitCount = self.progress.completedUnitCount - subTask.totalBytesSent + subTask.totalBytesExpectedToSend;
408409

0 commit comments

Comments
 (0)