diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 4eb1acdd80..44541ca8bb 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -1267,7 +1267,7 @@ static void uncaughtExceptionHandler(NSException *exception) [SignalApp.shared ensureRootViewController:launchStartedAt]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), - ^{ [DebugLogger.shared removeObsoleteDebugLogs]; }); + ^{ [DebugLogger.shared postLaunchLogCleanup]; }); } - (void)registrationStateDidChange diff --git a/SignalMessaging/utils/DebugLogger.h b/SignalMessaging/utils/DebugLogger.h index c4b4b36c88..31479fbd1c 100644 --- a/SignalMessaging/utils/DebugLogger.h +++ b/SignalMessaging/utils/DebugLogger.h @@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)wipeLogs; -- (void)removeObsoleteDebugLogs; +- (void)postLaunchLogCleanup; - (NSArray *)allLogFilePaths; diff --git a/SignalMessaging/utils/DebugLogger.m b/SignalMessaging/utils/DebugLogger.m index ae2ef26243..a9d47e48a0 100644 --- a/SignalMessaging/utils/DebugLogger.m +++ b/SignalMessaging/utils/DebugLogger.m @@ -9,6 +9,7 @@ #import #import #import +#import #import #import #import @@ -229,6 +230,21 @@ const NSUInteger kMaxDebugLogFileSize = 1024 * 1024 * 3; } } +static NSString *const kLastCleanupVersionKey = @"kLastCleanupVersionKey"; +static NSString *const kFirstValidLogVersion = @"5.35.1.2"; +- (void)postLaunchLogCleanup +{ + NSString *lastCleanupVersion = [CurrentAppContext().appUserDefaults stringForKey:kLastCleanupVersionKey] ?: @"0"; + + if ([AppVersion compareAppVersion:lastCleanupVersion with:kFirstValidLogVersion] == NSOrderedAscending) { + [self wipeLogs]; + OWSLogWarn(@"Wiped logs. (%@ < %@)", lastCleanupVersion, kFirstValidLogVersion); + } + [self removeObsoleteDebugLogs]; + + [CurrentAppContext().appUserDefaults setObject:AppVersion.shared.currentAppVersion4 forKey:kLastCleanupVersionKey]; +} + @end #pragma mark - diff --git a/SignalServiceKit/src/Util/AppVersion.h b/SignalServiceKit/src/Util/AppVersion.h index 41ed790cc9..7fcd1556ed 100755 --- a/SignalServiceKit/src/Util/AppVersion.h +++ b/SignalServiceKit/src/Util/AppVersion.h @@ -55,6 +55,8 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)isFirstLaunch; ++ (NSComparisonResult)compareAppVersion:(NSString *)lhs with:(NSString *)rhs; + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Util/AppVersion.m b/SignalServiceKit/src/Util/AppVersion.m index 44809e417b..fcc6b7cd6d 100755 --- a/SignalServiceKit/src/Util/AppVersion.m +++ b/SignalServiceKit/src/Util/AppVersion.m @@ -215,6 +215,29 @@ NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion_NSE return self.firstAppVersion != nil; } ++ (NSComparisonResult)compareAppVersion:(NSString *)lhs with:(NSString *)rhs +{ + // It might be nice to have a first-class version struct that's comparable, but it's not important right now. + NSArray *lhsComponents = [lhs componentsSeparatedByString:@"."]; + NSArray *rhsComponents = [rhs componentsSeparatedByString:@"."]; + + NSUInteger largestIdx = MAX(lhsComponents.count, rhsComponents.count); + for (NSInteger idx = 0; idx < largestIdx; idx++) { + // If we run off the end of an array, we'll assume zero for the component segment + NSString *lhsComponentString = (idx < lhsComponents.count) ? lhsComponents[idx] : nil; + NSString *rhsComponentString = (idx < rhsComponents.count) ? rhsComponents[idx] : nil; + NSInteger lhsComponent = [lhsComponentString integerValue]; + NSInteger rhsComponent = [rhsComponentString integerValue]; + + if (lhsComponent != rhsComponent) { + return (lhsComponent < rhsComponent) ? NSOrderedAscending : NSOrderedDescending; + } + } + + // If we get here, the versions are effectively equal + return NSOrderedSame; +} + @end NS_ASSUME_NONNULL_END