diff --git a/Source/NSDistributedLock.m b/Source/NSDistributedLock.m index 2c9479fcd..23820f89e 100644 --- a/Source/NSDistributedLock.m +++ b/Source/NSDistributedLock.m @@ -33,12 +33,12 @@ @implementation NSDistributedLock -+ (NSDistributedLock*)lockWithPath: (NSString*)aPath ++ (NSDistributedLock*) lockWithPath: (NSString*)aPath { - return [[[self alloc] initWithPath: aPath] autorelease]; + return [[[self alloc] initWithPath: aPath] autorelease]; } -- (void)breakLock +- (void) breakLock { NSFileManager *fileManager; @@ -51,14 +51,14 @@ lockTime = nil; } -- (void)dealloc +- (void) dealloc { [lockPath release]; [lockTime release]; [super dealloc]; } -- (NSDistributedLock*)initWithPath: (NSString*)aPath +- (NSDistributedLock*) initWithPath: (NSString*)aPath { NSFileManager *fileManager; NSString *lockDir; @@ -72,33 +72,33 @@ if ([fileManager fileExistsAtPath: lockDir isDirectory: &isDirectory] == NO) { NSLog(@"part of the path to the lock file '%@' is missing\n", lockPath); - [self dealloc]; + [self release]; return nil; } if (isDirectory == NO) { NSLog(@"part of the path to the lock file '%@' is not a directory\n", lockPath); - [self dealloc]; + [self release]; return nil; } if ([fileManager isWritableFileAtPath: lockDir] == NO) { NSLog(@"parent directory of lock file '%@' is not writable\n", lockPath); - [self dealloc]; + [self release]; return nil; } if ([fileManager isExecutableFileAtPath: lockDir] == NO) { NSLog(@"parent directory of lock file '%@' is not accessible\n", lockPath); - [self dealloc]; + [self release]; return nil; } return self; } -- (NSDate*)lockDate +- (NSDate*) lockDate { NSFileManager *fileManager; NSDictionary *attributes; @@ -108,7 +108,7 @@ return [attributes objectForKey: NSFileModificationDate]; } -- (BOOL)tryLock +- (BOOL) tryLock { NSFileManager *fileManager; NSMutableDictionary *attributes; @@ -145,7 +145,7 @@ } } -- (void)unlock +- (void) unlock { NSFileManager *fileManager; NSDictionary *attributes; diff --git a/Source/NSUserDefaults.m b/Source/NSUserDefaults.m index 5eeead412..980d8c1d8 100644 --- a/Source/NSUserDefaults.m +++ b/Source/NSUserDefaults.m @@ -621,36 +621,44 @@ static NSMutableString *processName = nil; return; } -- (BOOL)synchronize +- (BOOL) synchronize { NSMutableDictionary *newDict = nil; if (tickingTimer == nil) { - [NSTimer scheduledTimerWithTimeInterval:30 - target:self - selector:@selector(__timerTicked:) - userInfo:nil - repeats:NO]; + tickingTimer = [NSTimer scheduledTimerWithTimeInterval: 30 + target: self + selector: @selector(__timerTicked:) + userInfo: nil + repeats: NO]; } // Get file lock - break any lock that is more than five minute old. if ([defaultsDatabaseLock tryLock] == NO) - if ([[defaultsDatabaseLock lockDate] timeIntervalSinceNow] < -300.0) { - [defaultsDatabaseLock breakLock]; - if ([defaultsDatabaseLock tryLock] == NO) - return NO; + if ([[defaultsDatabaseLock lockDate] timeIntervalSinceNow] < -300.0) + { + [defaultsDatabaseLock breakLock]; + if ([defaultsDatabaseLock tryLock] == NO) + { + return NO; + } + } + else + { + return NO; + } } - else - return NO; DESTROY(dictionaryRep); // Read the persistent data from the stored database if ([[NSFileManager defaultManager] fileExistsAtPath: defaultsDatabase]) - newDict = [[NSMutableDictionary allocWithZone:[self zone]] - initWithContentsOfFile:defaultsDatabase]; + { + newDict = [[NSMutableDictionary allocWithZone: [self zone]] + initWithContentsOfFile: defaultsDatabase]; + } else { NSLog(@"Creating defaults database file %@", defaultsDatabase); @@ -659,9 +667,11 @@ static NSMutableString *processName = nil; attributes: nil]; } - if (!newDict) - newDict = [[NSMutableDictionary allocWithZone:[self zone]] - initWithCapacity:1]; + if (!newDict) + { + newDict = [[NSMutableDictionary allocWithZone: [self zone]] + initWithCapacity: 1]; + } if (changedDomains) { // Synchronize both dictionaries @@ -670,16 +680,20 @@ static NSMutableString *processName = nil; while ((obj = [enumerator nextObject])) { - dict = [persDomains objectForKey:obj]; - if (dict) // Domane was added or changet - [newDict setObject:dict forKey:obj]; + dict = [persDomains objectForKey: obj]; + if (dict) // Domain was added or changet + { + [newDict setObject: dict forKey: obj]; + } else // Domain was removed - [newDict removeObjectForKey:obj]; + { + [newDict removeObjectForKey: obj]; + } } [persDomains release]; persDomains = newDict; // Save the changes - if (![persDomains writeToFile:defaultsDatabase atomically:YES]) + if (![persDomains writeToFile: defaultsDatabase atomically: YES]) { [defaultsDatabaseLock unlock]; return NO; @@ -698,9 +712,10 @@ static NSMutableString *processName = nil; object: nil]; } else - [newDict release]; + { + [newDict release]; + } } - return YES; }