Skip to content

Commit

Permalink
Fix #827
Browse files Browse the repository at this point in the history
* Set overwrite to true on uploading ephemeral files that have not been uploaded during this session
  • Loading branch information
joeljfischer committed Jan 29, 2018
1 parent 882aa24 commit 2cc9168
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions SmartDeviceLink/SDLFileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ @interface SDLFileManager ()
// Local state
@property (strong, nonatomic) NSOperationQueue *transactionQueue;
@property (strong, nonatomic) NSMutableDictionary<SDLFileName *, NSOperation *> *uploadsInProgress;
@property (strong, nonatomic) NSMutableSet<SDLFileName *> *localUploadedFileNames;
@property (strong, nonatomic) SDLStateMachine *stateMachine;
@property (copy, nonatomic, nullable) SDLFileManagerStartupCompletionHandler startupCompletionHandler;

Expand All @@ -71,6 +72,7 @@ - (instancetype)initWithConnectionManager:(id<SDLConnectionManagerType>)manager
_transactionQueue.name = @"SDLFileManager Transaction Queue";
_transactionQueue.maxConcurrentOperationCount = 1;
_uploadsInProgress = [[NSMutableDictionary alloc] init];
_localUploadedFileNames = [[NSMutableSet<SDLFileName *> alloc] init];

_stateMachine = [[SDLStateMachine alloc] initWithTarget:self initialState:SDLFileManagerStateShutdown states:[self.class sdl_stateTransitionDictionary]];

Expand Down Expand Up @@ -272,6 +274,11 @@ - (void)uploadFiles:(NSArray<SDLFile *> *)files progressHandler:(nullable SDLFil
for(SDLFile *file in files) {
dispatch_group_enter(uploadFilesTask);

// 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.
if (!file.persistent && [self.remoteFileNames containsObject:file.name] && ![self.localUploadedFileNames containsObject:file.name]) {
file.overwrite = true;
}

[self uploadFile:file completionHandler:^(BOOL success, NSUInteger bytesAvailable, NSError * _Nullable error) {
if(!success) {
failedUploads[file.name] = error;
Expand Down Expand Up @@ -383,6 +390,7 @@ - (void)sdl_uploadFile:(SDLFile *)file completionHandler:(nullable SDLFileManage
}
if (success) {
[weakSelf.mutableRemoteFileNames addObject:fileName];
[weakSelf.localUploadedFileNames addObject:fileName];
}
if (uploadCompletion != nil) {
uploadCompletion(success, bytesAvailable, error);
Expand Down

0 comments on commit 2cc9168

Please sign in to comment.