diff options
author | NicoleYarroch <nicole@livio.io> | 2017-08-02 16:52:26 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2017-08-02 16:52:26 -0400 |
commit | 3de70af62573df871afeaed902d60efc4cb0c83e (patch) | |
tree | 9bad8b53a2a394f1d89dbb8a260d91103f6a8cdc /SmartDeviceLink | |
parent | 995d19ddd7279d7f59704411bfc34c9b889b2364 (diff) | |
download | sdl_ios-3de70af62573df871afeaed902d60efc4cb0c83e.tar.gz |
- Class now returns an error if user passes an invalid file path url or if they pass invalid or empty data.feature/issue_536_input_stream_file_manager
- Added test cases for checking invalid file paths and invalid data
- Made some fixes to the highestCorrelationIDReceived() method
Signed-off-by: NicoleYarroch <nicole@livio.io>
Diffstat (limited to 'SmartDeviceLink')
-rw-r--r-- | SmartDeviceLink/SDLError.h | 1 | ||||
-rw-r--r-- | SmartDeviceLink/SDLError.m | 11 | ||||
-rw-r--r-- | SmartDeviceLink/SDLErrorConstants.h | 4 | ||||
-rw-r--r-- | SmartDeviceLink/SDLUploadFileOperation.m | 14 |
4 files changed, 26 insertions, 4 deletions
diff --git a/SmartDeviceLink/SDLError.h b/SmartDeviceLink/SDLError.h index 09ec20ee8..717fb7ac5 100644 --- a/SmartDeviceLink/SDLError.h +++ b/SmartDeviceLink/SDLError.h @@ -39,6 +39,7 @@ extern SDLErrorDomain *const SDLErrorDomainFileManager; + (NSError *)sdl_fileManager_noKnownFileError; + (NSError *)sdl_fileManager_unableToStartError; + (NSError *)sdl_fileManager_unableToUploadError; ++ (NSError *)sdl_fileManager_fileDoesNotExistError; @end diff --git a/SmartDeviceLink/SDLError.m b/SmartDeviceLink/SDLError.m index 511f91deb..69ec729d5 100644 --- a/SmartDeviceLink/SDLError.m +++ b/SmartDeviceLink/SDLError.m @@ -140,6 +140,17 @@ SDLErrorDomain *const SDLErrorDomainFileManager = @"com.sdl.filemanager.error"; return [NSError errorWithDomain:SDLErrorDomainFileManager code:SDLFileManagerErrorUnableToUpload userInfo:userInfo]; } +#pragma mark SDLUploadFileOperation + ++ (NSError *)sdl_fileManager_fileDoesNotExistError { + NSDictionary<NSString *, NSString *> *userInfo = @{ + NSLocalizedDescriptionKey: NSLocalizedString(@"The file manager was unable to send the file", nil), + NSLocalizedFailureReasonErrorKey: NSLocalizedString(@"This could be because the file does not exist at the specified file path or that passed data is invalid", nil), + NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString(@"Make sure that the the correct file path is being set and that the passed data is valid", nil) + }; +return [NSError errorWithDomain:SDLErrorDomainFileManager code:SDLFileManagerErrorFileDoesNotExist userInfo:userInfo]; +} + @end diff --git a/SmartDeviceLink/SDLErrorConstants.h b/SmartDeviceLink/SDLErrorConstants.h index c439d3fd6..9f532a6fe 100644 --- a/SmartDeviceLink/SDLErrorConstants.h +++ b/SmartDeviceLink/SDLErrorConstants.h @@ -62,4 +62,8 @@ typedef NS_ENUM(NSInteger, SDLFileManagerError) { * The file manager was unable to send this file. */ SDLFileManagerErrorUnableToUpload = -4, + /** + * The file manager could not find the local file + */ + SDLFileManagerErrorFileDoesNotExist = -5, }; diff --git a/SmartDeviceLink/SDLUploadFileOperation.m b/SmartDeviceLink/SDLUploadFileOperation.m index c3b849663..acde2d721 100644 --- a/SmartDeviceLink/SDLUploadFileOperation.m +++ b/SmartDeviceLink/SDLUploadFileOperation.m @@ -9,6 +9,7 @@ #import "SDLUploadFileOperation.h" #import "SDLConnectionManagerType.h" +#import "SDLError.h" #import "SDLFile.h" #import "SDLFileWrapper.h" #import "SDLGlobals.h" @@ -65,6 +66,13 @@ NS_ASSUME_NONNULL_BEGIN __block NSUInteger bytesAvailable = 0; __block NSInteger highestCorrelationIDReceived = -1; + NSInputStream *inputStream = [self sdl_openInputStreamWithFile:file]; + + // If the file does not exist or the passed data is nil, return an error + if (inputStream == nil) { + return completion(NO, bytesAvailable, [NSError sdl_fileManager_fileDoesNotExistError]); + } + dispatch_group_t putFileGroup = dispatch_group_create(); dispatch_group_enter(putFileGroup); @@ -80,8 +88,6 @@ NS_ASSUME_NONNULL_BEGIN [weakself finishOperation]; }); - NSInputStream *inputStream = [self sdl_openInputStreamWithFile:file]; - // Break the data into small pieces, each of which will be sent in a separate putfile NSUInteger currentOffset = 0; for (int i = 0; i < (((file.fileSize - 1) / mtuSize) + 1); i++) { @@ -117,7 +123,7 @@ NS_ASSUME_NONNULL_BEGIN } // If no errors, watch for a response containing the amount of storage left on the SDL Core - if ([self sdl_newHighestCorrelationID:request highestCorrelationIDReceived:highestCorrelationIDReceived]) { + if ([[self class] sdl_newHighestCorrelationID:request highestCorrelationIDReceived:highestCorrelationIDReceived]) { highestCorrelationIDReceived = [request.correlationID integerValue]; bytesAvailable = [(SDLPutFileResponse *)response spaceAvailable].unsignedIntegerValue; } @@ -213,7 +219,7 @@ NS_ASSUME_NONNULL_BEGIN @param highestCorrelationIDReceived The largest currently received correlation id @return Whether or not the newest request contains the highest correlationId */ -- (Boolean)sdl_newHighestCorrelationID:(nullable SDLRPCRequest *)request highestCorrelationIDReceived:(NSInteger)highestCorrelationIDReceived { ++ (BOOL)sdl_newHighestCorrelationID:(SDLRPCRequest *)request highestCorrelationIDReceived:(NSInteger)highestCorrelationIDReceived { if ([request.correlationID integerValue] > highestCorrelationIDReceived) { return true; } |