summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLFileManager.m
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2017-09-01 16:04:41 -0400
committerNicoleYarroch <nicole@livio.io>2017-09-01 16:04:41 -0400
commitfb8f8f300e96e645259277c296c7df1334731831 (patch)
treeafd387a3c6af42f138345bb7a45eb75641b0b5c4 /SmartDeviceLink/SDLFileManager.m
parentda9f32fbbdd858c3b939ec4679f64eb6d107e555 (diff)
downloadsdl_ios-fb8f8f300e96e645259277c296c7df1334731831.tar.gz
Added test cases for canceling multiple uploads
Signed-off-by: NicoleYarroch <nicole@livio.io>
Diffstat (limited to 'SmartDeviceLink/SDLFileManager.m')
-rw-r--r--SmartDeviceLink/SDLFileManager.m23
1 files changed, 15 insertions, 8 deletions
diff --git a/SmartDeviceLink/SDLFileManager.m b/SmartDeviceLink/SDLFileManager.m
index d8d3f5ea6..e022f8f52 100644
--- a/SmartDeviceLink/SDLFileManager.m
+++ b/SmartDeviceLink/SDLFileManager.m
@@ -45,6 +45,7 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError";
// Local state
@property (strong, nonatomic) NSOperationQueue *transactionQueue;
+@property (strong, nonatomic) NSMutableDictionary<SDLFileName *, NSOperation *> *uploadsInProgress;
@property (strong, nonatomic) SDLStateMachine *stateMachine;
@property (copy, nonatomic, nullable) SDLFileManagerStartupCompletionHandler startupCompletionHandler;
@@ -69,6 +70,7 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError";
_transactionQueue = [[NSOperationQueue alloc] init];
_transactionQueue.name = @"SDLFileManager Transaction Queue";
_transactionQueue.maxConcurrentOperationCount = 1;
+ _uploadsInProgress = [[NSMutableDictionary alloc] init];
_stateMachine = [[SDLStateMachine alloc] initWithTarget:self initialState:SDLFileManagerStateShutdown states:[self.class sdl_stateTransitionDictionary]];
@@ -268,6 +270,7 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError";
dispatch_group_enter(uploadFilesTask);
[self uploadFile:file completionHandler:^(BOOL success, NSUInteger bytesAvailable, NSError * _Nullable error) {
+
if(!success) {
failedUploads[file.name] = error;
}
@@ -281,7 +284,15 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError";
if (cancel) {
// If user sets cancel to YES, cancel all future operations
dispatch_group_leave(uploadFilesTask);
- [self.transactionQueue cancelAllOperations];
+
+ for(SDLFile *file in files) {
+ // Cancel any remaining files waiting to be uploaded
+ NSOperation *fileUploadOperation = self.uploadsInProgress[file.name];
+ if (fileUploadOperation != nil) {
+ [fileUploadOperation cancel];
+ }
+ }
+
BLOCK_RETURN;
}
}
@@ -365,7 +376,7 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError";
__weak typeof(self) weakSelf = self;
SDLFileWrapper *fileWrapper = [SDLFileWrapper wrapperWithFile:file
completionHandler:^(BOOL success, NSUInteger bytesAvailable, NSError *_Nullable error) {
- [weakSelf.class sdl_deleteTemporaryFile:file.fileURL];
+ [self.uploadsInProgress removeObjectForKey:file.name];
if (bytesAvailable != 0) {
weakSelf.bytesAvailable = bytesAvailable;
@@ -380,6 +391,8 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError";
SDLUploadFileOperation *uploadOperation = [[SDLUploadFileOperation alloc] initWithFile:fileWrapper connectionManager:self.connectionManager];
+ // TODO: - remove from upload one file...
+ self.uploadsInProgress[file.name] = uploadOperation;
[self.transactionQueue addOperation:uploadOperation];
}
@@ -410,12 +423,6 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError";
}
}
-+ (void)sdl_deleteTemporaryFile:(NSURL *)fileURL {
- NSError *error = nil;
- if (![[NSFileManager defaultManager] removeItemAtURL:fileURL error:&error]) {
- SDLLogW(@"[Error clearing temporary file directory] %@ (%@)", error, fileURL);
- }
-}
@end