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/SDLUploadFileOperation.m | |
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/SDLUploadFileOperation.m')
-rw-r--r-- | SmartDeviceLink/SDLUploadFileOperation.m | 14 |
1 files changed, 10 insertions, 4 deletions
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; } |