From b9f987382ca53518afe281b58d98e211687a6f0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Sun, 16 Nov 2014 17:00:36 +0100 Subject: [PATCH] Don't call SUClearLog() unless logging something Don't delete the log file and log app name to it when only checking for updates - this is something done frequently, on many apps' startup. Instead, clear the log before writing the first entry to it, so that it stays untouched if there's nothing to add to it. Log the application name before the first "real" log entry, instead of doing it unconditionally every time checkForUpdatesWithDriver: is called. --- Sparkle/SULog.m | 7 +++++++ Sparkle/SUUpdater.m | 3 --- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Sparkle/SULog.m b/Sparkle/SULog.m index 3def222c..5941aac7 100644 --- a/Sparkle/SULog.m +++ b/Sparkle/SULog.m @@ -37,6 +37,7 @@ void SUClearLog(void) FILE *logfile = fopen([[SULogFilePath stringByExpandingTildeInPath] fileSystemRepresentation], "w"); if (logfile) { fclose(logfile); + SULog(@"===== %@ =====", [[NSFileManager defaultManager] displayNameAtPath:[[NSBundle mainBundle] bundlePath]]); } } @@ -53,6 +54,12 @@ void SUClearLog(void) void SULog(NSString *format, ...) { + static BOOL loggedYet = NO; + if (!loggedYet) { + loggedYet = YES; + SUClearLog(); + } + va_list ap; va_start(ap, format); NSString *theStr = [[NSString alloc] initWithFormat:format arguments:ap]; diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 612ee52b..1aada864 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -332,9 +332,6 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults if ([self updateInProgress]) { return; } if (self.checkTimer) { [self.checkTimer invalidate]; self.checkTimer = nil; } // Timer is non-repeating, may have invalidated itself, so we had to retain it. - SUClearLog(); - SULog(@"===== %@ =====", [[NSFileManager defaultManager] displayNameAtPath:[[NSBundle mainBundle] bundlePath]]); - [self willChangeValueForKey:@"lastUpdateCheckDate"]; [self.host setObject:[NSDate date] forUserDefaultsKey:SULastCheckTimeKey]; [self didChangeValueForKey:@"lastUpdateCheckDate"];