aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-04-25 16:47:34 +0000
committerstuconnolly <stuart02@gmail.com>2010-04-25 16:47:34 +0000
commited48d6800ff18def939d2ec8ce804cf54839067a (patch)
tree0a384b39134666cc954897a57133cc1227d3a5e1 /Source
parentfe6d4051cd47ee24c33775eec8624ebd7bb42160 (diff)
downloadsequelpro-ed48d6800ff18def939d2ec8ce804cf54839067a.tar.gz
sequelpro-ed48d6800ff18def939d2ec8ce804cf54839067a.tar.bz2
sequelpro-ed48d6800ff18def939d2ec8ce804cf54839067a.zip
Add the option to set whether or not old leaks logs are deleted.
Diffstat (limited to 'Source')
-rw-r--r--Source/SPLogger.h11
-rw-r--r--Source/SPLogger.m69
2 files changed, 43 insertions, 37 deletions
diff --git a/Source/SPLogger.h b/Source/SPLogger.h
index 09fbfd53..4d394b83 100644
--- a/Source/SPLogger.h
+++ b/Source/SPLogger.h
@@ -33,6 +33,11 @@
BOOL dumpLeaksOnTermination;
/**
+ * Remove old leak dumps on termination flag.
+ */
+ BOOL removeOldLeakDumpsOnTermination;
+
+ /**
* Log file initialized successfully flag.
*/
BOOL initializedSuccessfully;
@@ -50,10 +55,8 @@
*/
+ (SPLogger *)logger;
-/**
- * Tells the logger to dump leaks analysis upon app termination.
- */
-- (void)setDumpLeaksOnTermination;
+@property(readwrite, assign) BOOL dumpLeaksOnTermination;
+@property(readwrite, assign) BOOL removeOldLeakDumpsOnTermination;
/**
* Dumps the result of running leaks to the file '/tmp/sp.leaks.<pid>.tmp'.
diff --git a/Source/SPLogger.m b/Source/SPLogger.m
index 8870ed49..83c5b49c 100644
--- a/Source/SPLogger.m
+++ b/Source/SPLogger.m
@@ -53,6 +53,9 @@ static SPLogger *logger = nil;
@implementation SPLogger
+@synthesize dumpLeaksOnTermination;
+@synthesize removeOldLeakDumpsOnTermination;
+
/*
* Returns the shared logger object.
*/
@@ -90,8 +93,10 @@ static SPLogger *logger = nil;
- (id)init
{
if ((self = [super init])) {
- dumpLeaksOnTermination = NO;
initializedSuccessfully = YES;
+
+ [self setDumpLeaksOnTermination:NO];
+ [self setRemoveOldLeakDumpsOnTermination:YES];
}
return self;
@@ -119,19 +124,9 @@ static SPLogger *logger = nil;
[logString release];
}
-- (void)setDumpLeaksOnTermination
-{
- dumpLeaksOnTermination = YES;
-}
-
- (void)dumpLeaks
{
- if (dumpLeaksOnTermination) {
-
- // Remove old leaks logs
- int cnt, cnt2, i;
- int isSPLeaksLog();
- struct direct **files;
+ if ([self dumpLeaksOnTermination]) {
char *lgn;
struct passwd *pw;
@@ -145,34 +140,42 @@ static SPLogger *logger = nil;
hdir = TRUE;
}
- cnt = scandir("/tmp", &files, isSPLeaksLog, NULL);
-
- char fpath[32], fpath2[32], fpath3[64];
-
- for (i = 0; i < cnt; i++)
- {
- snprintf(fpath, sizeof(fpath), "/tmp/%s", files[i]->d_name);
+ // If required remove old logs
+ if ([self removeOldLeakDumpsOnTermination]) {
- if (remove(fpath) != 0) {
- printf("Unable to remove Sequel Pro leaks log '%s'\n", files[i]->d_name);
- }
- }
-
- free(&files);
-
- if (hdir) {
- snprintf(fpath2, sizeof(fpath2), "%s/Desktop", pw->pw_dir);
-
- cnt2 = scandir(fpath2, &files, isSPLeaksLog, NULL);
+ int cnt, cnt2, i;
+ int isSPLeaksLog();
+ struct direct **files;
+
+ cnt = scandir("/tmp", &files, isSPLeaksLog, NULL);
- for (i = 0; i < cnt2; i++)
+ char fpath[32], fpath2[32], fpath3[64];
+
+ for (i = 0; i < cnt; i++)
{
- snprintf(fpath3, sizeof(fpath3), "%s/%s", fpath2, files[i]->d_name);
+ snprintf(fpath, sizeof(fpath), "/tmp/%s", files[i]->d_name);
- if (remove(fpath3) != 0) {
+ if (remove(fpath) != 0) {
printf("Unable to remove Sequel Pro leaks log '%s'\n", files[i]->d_name);
}
}
+
+ free(&files);
+
+ if (hdir) {
+ snprintf(fpath2, sizeof(fpath2), "%s/Desktop", pw->pw_dir);
+
+ cnt2 = scandir(fpath2, &files, isSPLeaksLog, NULL);
+
+ for (i = 0; i < cnt2; i++)
+ {
+ snprintf(fpath3, sizeof(fpath3), "%s/%s", fpath2, files[i]->d_name);
+
+ if (remove(fpath3) != 0) {
+ printf("Unable to remove Sequel Pro leaks log '%s'\n", files[i]->d_name);
+ }
+ }
+ }
}
size_t len;