mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Fix directory creation to use low level methods which consider the presence
of an existing directory to be an error, rather than the NSFileManager methods that consider it a success. The logic of distributed locking requires us to fail if a directory already exists.
This commit is contained in:
parent
a5a2e85423
commit
ed721bf4da
4 changed files with 80 additions and 29 deletions
32
Tests/base/NSDistributedLock/basic.m
Normal file
32
Tests/base/NSDistributedLock/basic.m
Normal file
|
@ -0,0 +1,32 @@
|
|||
#import "ObjectTesting.h"
|
||||
#import <Foundation/NSDistributedLock.h>
|
||||
#import <Foundation/NSFileManager.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
START_SET("basic")
|
||||
|
||||
NSString *path;
|
||||
NSDistributedLock *lock1;
|
||||
NSDistributedLock *lock2;
|
||||
|
||||
test_NSObject(@"NSDistributedLock",
|
||||
[NSArray arrayWithObject: [NSDistributedLock new]]);
|
||||
|
||||
path = [[NSFileManager defaultManager] currentDirectoryPath];
|
||||
path = [path stringByAppendingPathComponent: @"MyLock"];
|
||||
lock1 = [NSDistributedLock lockWithPath: path];
|
||||
lock2 = [NSDistributedLock lockWithPath: path];
|
||||
|
||||
PASS(lock1 != lock2, "locks with the same path differ");
|
||||
|
||||
PASS(YES == [lock1 tryLock], "we can lock the first lock");
|
||||
|
||||
PASS(NO == [lock2 tryLock], "the locks are exclusive");
|
||||
|
||||
[lock1 unlock];
|
||||
PASS(YES == [lock2 tryLock], "unlocking first lock allows second lock");
|
||||
|
||||
END_SET("basic")
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue