From 717bf0ded2895d950d0a69ecca780245ec96176d Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Fri, 17 Dec 2010 20:41:22 +0000 Subject: [PATCH] Keep a log of uploaded crash IDs on the Mac. Review URL: http://breakpad.appspot.com/245001 git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@748 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/client/mac/Framework/Breakpad.h | 5 +++- src/client/mac/sender/crash_report_sender.m | 27 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/client/mac/Framework/Breakpad.h b/src/client/mac/Framework/Breakpad.h index 52ea6c6b..fa861431 100644 --- a/src/client/mac/Framework/Breakpad.h +++ b/src/client/mac/Framework/Breakpad.h @@ -50,10 +50,13 @@ extern "C" { #include #include - // Keys for configuration file +// Keys for configuration file #define kReporterMinidumpDirectoryKey "MinidumpDir" #define kReporterMinidumpIDKey "MinidumpID" +// Filename for recording uploaded IDs +#define kReporterLogFilename "uploads.log" + // The default subdirectory of the Library to put crash dumps in // The subdirectory is // ~/Library// diff --git a/src/client/mac/sender/crash_report_sender.m b/src/client/mac/sender/crash_report_sender.m index cdee262b..5bf806a3 100644 --- a/src/client/mac/sender/crash_report_sender.m +++ b/src/client/mac/sender/crash_report_sender.m @@ -255,6 +255,9 @@ NSString *const kDefaultServerType = @"google"; // in their comments/email. - (void)controlTextDidBeginEditing:(NSNotification *)aNotification; +// Records the uploaded crash ID to the log file. +- (void)logUploadWithID:(const char *)uploadID; + @end @implementation Reporter @@ -992,6 +995,7 @@ doCommandBySelector:(SEL)commandSelector { } else { NSCharacterSet *trimSet = [NSCharacterSet whitespaceAndNewlineCharacterSet]; reportID = [[result stringByTrimmingCharactersInSet:trimSet] UTF8String]; + [self logUploadWithID:reportID]; } // rename the minidump file according to the id returned from the server @@ -1036,6 +1040,29 @@ doCommandBySelector:(SEL)commandSelector { [upload release]; } +- (void)logUploadWithID:(const char *)uploadID { + NSString *minidumpDir = + [parameters_ objectForKey:@kReporterMinidumpDirectoryKey]; + NSString *logFilePath = [NSString stringWithFormat:@"%@/%s", + minidumpDir, kReporterLogFilename]; + NSString *logLine = [NSString stringWithFormat:@"%0.f,%s\n", + [[NSDate date] timeIntervalSince1970], uploadID]; + NSData *logData = [logLine dataUsingEncoding:kCFStringEncodingUTF8]; + + NSFileManager *fileManager = [NSFileManager defaultManager]; + if ([fileManager fileExistsAtPath:logFilePath]) { + NSFileHandle *logFileHandle = + [NSFileHandle fileHandleForWritingAtPath:logFilePath]; + [logFileHandle seekToEndOfFile]; + [logFileHandle writeData:logData]; + [logFileHandle closeFile]; + } else { + [fileManager createFileAtPath:logFilePath + contents:logData + attributes:nil]; + } +} + //============================================================================= - (void)dealloc { [parameters_ release];