NSDistributedLock from Frith-MacDonald

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2613 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fedor 1997-11-03 01:40:03 +00:00
parent 1e85219e08
commit 2b1d0b3d15
7 changed files with 132 additions and 11 deletions

View file

@ -27,6 +27,7 @@
#include <gnustep/base/preface.h>
#include <Foundation/NSFileManager.h>
#include <Foundation/NSException.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSLock.h>
/* determine directory reading files */
@ -275,11 +276,84 @@ static NSFileManager* defaultManager = nil;
return NO;
}
- (BOOL)removeFileAtPath:(NSString*)path
handler:handler
- (BOOL)removeFileAtPath: (NSString*)path
handler: handler
{
// TODO
return NO;
NSArray *contents;
if (handler)
[handler fileManager: self willProcessPath: path];
contents = [self directoryContentsAtPath: path];
if (contents == nil)
{
if (unlink([path fileSystemRepresentation]) < 0)
{
BOOL result;
if (handler)
{
NSMutableDictionary *info;
info = [[NSMutableDictionary alloc] initWithCapacity: 3];
[info setObject: path forKey: @"Path"];
[info setObject: [NSString stringWithCString: strerror(errno)]
forKey: @"Error"];
result = [handler fileManager: self
shouldProceedAfterError: info];
[info release];
}
else
result = NO;
return result;
}
else
return YES;
}
else
{
int i;
contents = [self directoryContentsAtPath: path];
for (i = 0; i < [contents count]; i++)
{
NSAutoreleasePool *arp;
NSString *item;
NSString *next;
BOOL result;
arp = [[NSAutoreleasePool alloc] init];
item = [contents objectAtIndex: i];
next = [path stringByAppendingPathComponent: item];
result = [self removeFileAtPath: next handler: handler];
[arp release];
if (result == NO)
return NO;
}
if (rmdir([path fileSystemRepresentation]) < 0)
{
BOOL result;
if (handler)
{
NSMutableDictionary *info;
info = [[NSMutableDictionary alloc] initWithCapacity: 3];
[info setObject: path forKey: @"Path"];
[info setObject: [NSString stringWithCString: strerror(errno)]
forKey: @"Error"];
result = [handler fileManager: self
shouldProceedAfterError: info];
[info release];
}
else
result = NO;
return result;
}
else
return YES;
}
}
- (BOOL)createFileAtPath:(NSString*)path contents:(NSData*)contents