Skip to content

Commit

Permalink
Fix OAImportBackupTask concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-osm committed Jan 19, 2025
1 parent afb4fcf commit d470dac
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Sources/Backup/OAImportBackupTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#import "OAImportBackupItemsTask.h"
#import "OASettingsImporter.h"
#import "OABackupInfo.h"
#import "OAConcurrentCollections.h"

@implementation OAItemProgressInfo

Expand Down Expand Up @@ -55,7 +56,7 @@ @implementation OAImportBackupTask
NSArray<OARemoteFile *> *_remoteFiles;

NSString *_key;
NSMutableDictionary<NSString *, OAItemProgressInfo *> *_itemsProgress;
OAConcurrentDictionary<NSString *, OAItemProgressInfo *> *_itemsProgress;
}

- (instancetype) initWithKey:(NSString *)key
Expand Down Expand Up @@ -124,7 +125,7 @@ - (void) commonInit
{
_helper = OANetworkSettingsHelper.sharedInstance;
_importer = [[OABackupImporter alloc] initWithListener:self];
_itemsProgress = [NSMutableDictionary dictionary];
_itemsProgress = [[OAConcurrentDictionary alloc] init];
_maxProgress = [self.class calculateMaxProgress];
}

Expand All @@ -142,7 +143,7 @@ + (NSInteger) calculateMaxProgress

- (OAItemProgressInfo *) getItemProgressInfo:(NSString *)type fileName:(NSString *)fileName
{
return _itemsProgress[[type stringByAppendingString:fileName]];
return [_itemsProgress objectForKeySync:[type stringByAppendingString:fileName]];
}

- (void)main
Expand Down Expand Up @@ -328,7 +329,7 @@ - (void) onProgressUpdate:(OAItemProgressInfo *)info
if (prevInfo)
info.work = prevInfo.work;

_itemsProgress[[info.type stringByAppendingString:info.fileName]] = info;
[_itemsProgress setObjectSync:info forKey:[info.type stringByAppendingString:info.fileName]];

if (info.finished)
[_importListener onImportItemFinished:info.type fileName:info.fileName];
Expand Down

0 comments on commit d470dac

Please sign in to comment.