summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLUploadFileOperation.m
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2017-04-07 10:44:26 -0400
committerNicoleYarroch <nicole@livio.io>2017-04-07 10:44:26 -0400
commit7574184d7acc40a56679004eff98cf6d4a48eb33 (patch)
treebde12f323adb148c652452e9c44ba1d0dd669b72 /SmartDeviceLink/SDLUploadFileOperation.m
parent7ae53459046d19800f8f4384c4480a6091cfe7d9 (diff)
downloadsdl_ios-7574184d7acc40a56679004eff98cf6d4a48eb33.tar.gz
Test cases in SDLFileManagerSpec pass
- changed test cases with to() to toEventually(). Signed-off-by: NicoleYarroch <nicole@livio.io>
Diffstat (limited to 'SmartDeviceLink/SDLUploadFileOperation.m')
-rw-r--r--SmartDeviceLink/SDLUploadFileOperation.m29
1 files changed, 15 insertions, 14 deletions
diff --git a/SmartDeviceLink/SDLUploadFileOperation.m b/SmartDeviceLink/SDLUploadFileOperation.m
index db77fdf3d..f16288a3b 100644
--- a/SmartDeviceLink/SDLUploadFileOperation.m
+++ b/SmartDeviceLink/SDLUploadFileOperation.m
@@ -55,15 +55,6 @@ NS_ASSUME_NONNULL_BEGIN
[self sendPutFiles:self.fileWrapper.file mtuSize:[SDLGlobals sharedGlobals].maxMTUSize withCompletion:self.fileWrapper.completionHandler];
}
-- (void)startWithCompletion:(SDLFileManagerUploadCompletionHandler)completion {
- [super start];
-
- [self sendPutFiles:self.fileWrapper.file mtuSize:[SDLGlobals sharedGlobals].maxMTUSize withCompletion:^(BOOL success, NSUInteger bytesAvailable, NSError * _Nullable error) {
- self.fileWrapper.completionHandler(success, bytesAvailable, error);
- return completion(success, bytesAvailable, error);
- }];
-}
-
- (void)sendPutFiles:(SDLFile *)file mtuSize:(NSUInteger)mtuSize withCompletion:(SDLFileManagerUploadCompletionHandler)completion {
// iStream is NSInputStream instance variable
@@ -88,6 +79,7 @@ NS_ASSUME_NONNULL_BEGIN
} else {
completion(YES, bytesAvailable, nil);
}
+
[weakself finishOperation];
});
@@ -97,9 +89,10 @@ NS_ASSUME_NONNULL_BEGIN
unsigned long long numberOfFilesToSend = (((fileSize - 1) / mtuSize) + 1);
for (int i = 0; i < numberOfFilesToSend; i++) {
SDLPutFile *putFile = [[SDLPutFile alloc] initWithFileName:file.name fileType:file.fileType persistentFile:file.isPersistent];
- putFile.offset = @(currentOffset);
+ dispatch_group_enter(putFileGroup);
// The putfile's length parameter is based on the current offset
+ putFile.offset = @(currentOffset);
NSInteger putFileLength = [self getPutFileLengthForOffset:currentOffset fileSize:fileSize mtuSize:mtuSize];
putFile.length = @(putFileLength);
@@ -109,25 +102,33 @@ NS_ASSUME_NONNULL_BEGIN
NSData *dataChunk = [self getDataChunkWithSize:dataSize inputStream:self.inputStream error:&error];
if (dataChunk == nil) {
// TODO: - ????? Add error message here!
- return completion(NO, bytesAvailable, streamError);
+ // return completion(NO, bytesAvailable, streamError);
+ [self cancel];
+ streamError = error;
+ dispatch_group_leave(putFileGroup);
+ BLOCK_RETURN;
}
putFile.bulkData = dataChunk;
currentOffset += dataSize;
// Send the putfile
- dispatch_group_enter(putFileGroup);
__weak typeof(self) weakself = self;
[self.connectionManager sendManagerRequest:putFile withResponseHandler:^(__kindof SDLRPCRequest *_Nullable request, __kindof SDLRPCResponse *_Nullable response, NSError *_Nullable error) {
typeof(weakself) strongself = weakself;
+ // If we've already encountered an error, then just abort
// TODO: Is this the right way to handle this case? Should we just abort everything in the future? Should we be deleting what we sent? Should we have an automatic retry strategy based on what the error was?
if (strongself.isCancelled) {
+ stop = YES;
+ }
+
+ if (stop) {
dispatch_group_leave(putFileGroup);
BLOCK_RETURN;
}
// If we encounted an error, abort in the future and call the completion handler
- if (error != nil || response == nil || ![response.success boolValue] || strongself.isCancelled) {
- [strongself cancel];
+ if (error != nil || response == nil || ![response.success boolValue]) {
+ stop = YES;
streamError = error;
dispatch_group_leave(putFileGroup);
BLOCK_RETURN;