summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/public
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2021-09-22 13:47:12 -0400
committerJoel Fischer <joeljfischer@gmail.com>2021-09-22 13:47:12 -0400
commit09e5e226d01ed512cec25e10de379fcbb5235440 (patch)
tree7178267a0488ad915995996b3ba95d6f6c3899d4 /SmartDeviceLink/public
parentaa48cff19fe5861546ac930ca275d0ba3a263df1 (diff)
downloadsdl_ios-09e5e226d01ed512cec25e10de379fcbb5235440.tar.gz
Fix overwriting files in various circumstances
* Fix overwriting files when an identical file hasn't completed its operation but is running * Fix overwriting files when modified after operation start * Fix incorrect error message
Diffstat (limited to 'SmartDeviceLink/public')
-rw-r--r--SmartDeviceLink/public/SDLFileManager.m23
1 files changed, 9 insertions, 14 deletions
diff --git a/SmartDeviceLink/public/SDLFileManager.m b/SmartDeviceLink/public/SDLFileManager.m
index d02762fe5..38d63ec2c 100644
--- a/SmartDeviceLink/public/SDLFileManager.m
+++ b/SmartDeviceLink/public/SDLFileManager.m
@@ -387,35 +387,30 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError";
return;
}
- // HAX: [#827](https://github.com/smartdevicelink/sdl_ios/issues/827) Older versions of Core had a bug where list files would cache incorrectly. This led to attempted uploads failing due to the system thinking they were already there when they were not. This is only needed if connecting to Core v4.3.1 or less which corresponds to RPC v4.3.1 or less
- if (!file.persistent && ![self hasUploadedFile:file] && [[SDLGlobals sharedGlobals].rpcVersion isLessThanVersion:[SDLVersion versionWithMajor:4 minor:4 patch:0]]) {
- file.overwrite = YES;
- }
-
// If we didn't error out over the overwrite, then continue on
[self sdl_uploadFile:file completionHandler:handler];
}
- (void)sdl_uploadFile:(SDLFile *)file completionHandler:(nullable SDLFileManagerUploadCompletionHandler)handler {
- __block NSString *fileName = file.name;
- __block SDLFileManagerUploadCompletionHandler uploadCompletion = [handler copy];
+ SDLFile *fileCopy = [file copy];
+ SDLFileManagerUploadCompletionHandler uploadCompletion = [handler copy];
__weak typeof(self) weakSelf = self;
- SDLFileWrapper *fileWrapper = [SDLFileWrapper wrapperWithFile:file completionHandler:^(BOOL success, NSUInteger bytesAvailable, NSError *_Nullable error) {
+ SDLFileWrapper *fileWrapper = [SDLFileWrapper wrapperWithFile:fileCopy completionHandler:^(BOOL success, NSUInteger bytesAvailable, NSError *_Nullable error) {
if (success) {
weakSelf.bytesAvailable = bytesAvailable;
- [weakSelf.mutableRemoteFileNames addObject:fileName];
+ [weakSelf.mutableRemoteFileNames addObject:fileCopy.name];
if (!file.persistent) {
- [weakSelf.uploadedEphemeralFileNames addObject:fileName];
+ [weakSelf.uploadedEphemeralFileNames addObject:fileCopy.name];
}
} else if (error.code != SDLFileManagerErrorCannotOverwrite) {
- weakSelf.failedFileUploadsCount = [weakSelf.class sdl_incrementFailedUploadCountForFileName:file.name failedFileUploadsCount:weakSelf.failedFileUploadsCount];
+ weakSelf.failedFileUploadsCount = [weakSelf.class sdl_incrementFailedUploadCountForFileName:fileCopy.name failedFileUploadsCount:weakSelf.failedFileUploadsCount];
- NSUInteger maxUploadCount = [file isMemberOfClass:[SDLArtwork class]] ? weakSelf.maxArtworkUploadAttempts : self.maxFileUploadAttempts;
- if ([weakSelf sdl_canFileBeUploadedAgain:file maxUploadCount:maxUploadCount failedFileUploadsCount:weakSelf.failedFileUploadsCount]) {
+ NSUInteger maxUploadCount = [fileCopy isMemberOfClass:[SDLArtwork class]] ? weakSelf.maxArtworkUploadAttempts : weakSelf.maxFileUploadAttempts;
+ if ([weakSelf sdl_canFileBeUploadedAgain:fileCopy maxUploadCount:maxUploadCount failedFileUploadsCount:weakSelf.failedFileUploadsCount]) {
SDLLogD(@"Attempting to resend file with name %@ after a failed upload attempt", file.name);
- return [weakSelf sdl_uploadFile:file completionHandler:handler];
+ return [weakSelf sdl_uploadFile:fileCopy completionHandler:handler];
}
}