Skip to content

Commit

Permalink
Rework configurator flow a bit so calls cannot be made out of order
Browse files Browse the repository at this point in the history
  • Loading branch information
mlw committed Jan 22, 2024
1 parent 82c2cd2 commit 8f202e2
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Source/common/SNTConfigurator.m
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ - (instancetype)initWithSyncStateFile:(NSString *)syncStateFilePath
[self cacheStaticRules];

_syncState = [self readSyncStateFromDisk] ?: [NSMutableDictionary dictionary];
[self migrateDeprecatedSyncStateKeys];
if ([self migrateDeprecatedSyncStateKeys]) {
// Save the updated sync state if any keys were migrated.
[self saveSyncStateToDisk];
}

_debugFlag = [[NSProcessInfo processInfo].arguments containsObject:@"--debug"];
[self startWatchingDefaults];
Expand Down Expand Up @@ -1120,11 +1123,6 @@ - (void)updateSyncStateForKey:(NSString *)key value:(id)value {
///
/// Read the saved syncState.
///
/// IMPORTANT: Should only be called on the `init` path because this method will
/// cause the dictionary to be written to disk outside of the dispatch queue used
/// to serialize access. This is to ensure the operation can happen early at
/// startup and not interfere with normal operation.
///
- (NSMutableDictionary *)readSyncStateFromDisk {
if (!self.syncStateAccessAuthorizerBlock()) {
return nil;
Expand All @@ -1148,10 +1146,12 @@ - (NSMutableDictionary *)readSyncStateFromDisk {
///
/// Migrate any deprecated sync state keys/values to alternative keys/values.
///
- (void)migrateDeprecatedSyncStateKeys {
/// Returns YES if any keys were migrated. Otherwise NO.
///
- (BOOL)migrateDeprecatedSyncStateKeys {
// Currently only one key to migrate
if (!self.syncState[kSyncCleanRequiredDeprecated]) {
return;
return NO;
}

NSMutableDictionary *syncState = self.syncState.mutableCopy;
Expand All @@ -1169,7 +1169,7 @@ - (void)migrateDeprecatedSyncStateKeys {

self.syncState = syncState;

[self saveSyncStateToDisk];
return YES;
}

///
Expand Down

0 comments on commit 8f202e2

Please sign in to comment.