Tidied indentation.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3662 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-02-05 11:44:38 +00:00
parent 3d9f74723d
commit 3f9a08c193
2 changed files with 51 additions and 36 deletions

View file

@ -33,12 +33,12 @@
@implementation NSDistributedLock @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; NSFileManager *fileManager;
@ -51,14 +51,14 @@
lockTime = nil; lockTime = nil;
} }
- (void)dealloc - (void) dealloc
{ {
[lockPath release]; [lockPath release];
[lockTime release]; [lockTime release];
[super dealloc]; [super dealloc];
} }
- (NSDistributedLock*)initWithPath: (NSString*)aPath - (NSDistributedLock*) initWithPath: (NSString*)aPath
{ {
NSFileManager *fileManager; NSFileManager *fileManager;
NSString *lockDir; NSString *lockDir;
@ -72,33 +72,33 @@
if ([fileManager fileExistsAtPath: lockDir isDirectory: &isDirectory] == NO) if ([fileManager fileExistsAtPath: lockDir isDirectory: &isDirectory] == NO)
{ {
NSLog(@"part of the path to the lock file '%@' is missing\n", lockPath); NSLog(@"part of the path to the lock file '%@' is missing\n", lockPath);
[self dealloc]; [self release];
return nil; return nil;
} }
if (isDirectory == NO) if (isDirectory == NO)
{ {
NSLog(@"part of the path to the lock file '%@' is not a directory\n", NSLog(@"part of the path to the lock file '%@' is not a directory\n",
lockPath); lockPath);
[self dealloc]; [self release];
return nil; return nil;
} }
if ([fileManager isWritableFileAtPath: lockDir] == NO) if ([fileManager isWritableFileAtPath: lockDir] == NO)
{ {
NSLog(@"parent directory of lock file '%@' is not writable\n", lockPath); NSLog(@"parent directory of lock file '%@' is not writable\n", lockPath);
[self dealloc]; [self release];
return nil; return nil;
} }
if ([fileManager isExecutableFileAtPath: lockDir] == NO) if ([fileManager isExecutableFileAtPath: lockDir] == NO)
{ {
NSLog(@"parent directory of lock file '%@' is not accessible\n", NSLog(@"parent directory of lock file '%@' is not accessible\n",
lockPath); lockPath);
[self dealloc]; [self release];
return nil; return nil;
} }
return self; return self;
} }
- (NSDate*)lockDate - (NSDate*) lockDate
{ {
NSFileManager *fileManager; NSFileManager *fileManager;
NSDictionary *attributes; NSDictionary *attributes;
@ -108,7 +108,7 @@
return [attributes objectForKey: NSFileModificationDate]; return [attributes objectForKey: NSFileModificationDate];
} }
- (BOOL)tryLock - (BOOL) tryLock
{ {
NSFileManager *fileManager; NSFileManager *fileManager;
NSMutableDictionary *attributes; NSMutableDictionary *attributes;
@ -145,7 +145,7 @@
} }
} }
- (void)unlock - (void) unlock
{ {
NSFileManager *fileManager; NSFileManager *fileManager;
NSDictionary *attributes; NSDictionary *attributes;

View file

@ -621,36 +621,44 @@ static NSMutableString *processName = nil;
return; return;
} }
- (BOOL)synchronize - (BOOL) synchronize
{ {
NSMutableDictionary *newDict = nil; NSMutableDictionary *newDict = nil;
if (tickingTimer == nil) if (tickingTimer == nil)
{ {
[NSTimer scheduledTimerWithTimeInterval:30 tickingTimer = [NSTimer scheduledTimerWithTimeInterval: 30
target:self target: self
selector:@selector(__timerTicked:) selector: @selector(__timerTicked:)
userInfo:nil userInfo: nil
repeats:NO]; repeats: NO];
} }
// Get file lock - break any lock that is more than five minute old. // Get file lock - break any lock that is more than five minute old.
if ([defaultsDatabaseLock tryLock] == NO) if ([defaultsDatabaseLock tryLock] == NO)
if ([[defaultsDatabaseLock lockDate] timeIntervalSinceNow] < -300.0)
{ {
[defaultsDatabaseLock breakLock]; if ([[defaultsDatabaseLock lockDate] timeIntervalSinceNow] < -300.0)
if ([defaultsDatabaseLock tryLock] == NO) {
return NO; [defaultsDatabaseLock breakLock];
if ([defaultsDatabaseLock tryLock] == NO)
{
return NO;
}
}
else
{
return NO;
}
} }
else
return NO;
DESTROY(dictionaryRep); DESTROY(dictionaryRep);
// Read the persistent data from the stored database // Read the persistent data from the stored database
if ([[NSFileManager defaultManager] fileExistsAtPath: defaultsDatabase]) if ([[NSFileManager defaultManager] fileExistsAtPath: defaultsDatabase])
newDict = [[NSMutableDictionary allocWithZone:[self zone]] {
initWithContentsOfFile:defaultsDatabase]; newDict = [[NSMutableDictionary allocWithZone: [self zone]]
initWithContentsOfFile: defaultsDatabase];
}
else else
{ {
NSLog(@"Creating defaults database file %@", defaultsDatabase); NSLog(@"Creating defaults database file %@", defaultsDatabase);
@ -659,9 +667,11 @@ static NSMutableString *processName = nil;
attributes: nil]; attributes: nil];
} }
if (!newDict) if (!newDict)
newDict = [[NSMutableDictionary allocWithZone:[self zone]] {
initWithCapacity:1]; newDict = [[NSMutableDictionary allocWithZone: [self zone]]
initWithCapacity: 1];
}
if (changedDomains) if (changedDomains)
{ // Synchronize both dictionaries { // Synchronize both dictionaries
@ -670,16 +680,20 @@ static NSMutableString *processName = nil;
while ((obj = [enumerator nextObject])) while ((obj = [enumerator nextObject]))
{ {
dict = [persDomains objectForKey:obj]; dict = [persDomains objectForKey: obj];
if (dict) // Domane was added or changet if (dict) // Domain was added or changet
[newDict setObject:dict forKey:obj]; {
[newDict setObject: dict forKey: obj];
}
else // Domain was removed else // Domain was removed
[newDict removeObjectForKey:obj]; {
[newDict removeObjectForKey: obj];
}
} }
[persDomains release]; [persDomains release];
persDomains = newDict; persDomains = newDict;
// Save the changes // Save the changes
if (![persDomains writeToFile:defaultsDatabase atomically:YES]) if (![persDomains writeToFile: defaultsDatabase atomically: YES])
{ {
[defaultsDatabaseLock unlock]; [defaultsDatabaseLock unlock];
return NO; return NO;
@ -698,9 +712,10 @@ static NSMutableString *processName = nil;
object: nil]; object: nil];
} }
else else
[newDict release]; {
[newDict release];
}
} }
return YES; return YES;
} }