From 8f202e220dd156f0372c1524534479f4aea51815 Mon Sep 17 00:00:00 2001 From: Matt White <436037+mlw@users.noreply.github.com> Date: Mon, 22 Jan 2024 16:04:28 -0500 Subject: [PATCH] Rework configurator flow a bit so calls cannot be made out of order --- Source/common/SNTConfigurator.m | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/common/SNTConfigurator.m b/Source/common/SNTConfigurator.m index fe526deff..404a3f652 100644 --- a/Source/common/SNTConfigurator.m +++ b/Source/common/SNTConfigurator.m @@ -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]; @@ -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; @@ -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; @@ -1169,7 +1169,7 @@ - (void)migrateDeprecatedSyncStateKeys { self.syncState = syncState; - [self saveSyncStateToDisk]; + return YES; } ///