mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
a few new methods
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@36311 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ffe89d6757
commit
970638b746
4 changed files with 114 additions and 4 deletions
|
@ -1,3 +1,10 @@
|
|||
2012-03-08 Sebastian Reitenbach <sebastia@l00-bugdead-prods.de>
|
||||
|
||||
* Headers/Foundation/NSFileManager.h:
|
||||
* Source/NSFileManager.m:
|
||||
* Tests/base/NSFileManager/general.m:
|
||||
Implement methods forcoping/moving file URLs
|
||||
|
||||
2012-03-05 Larry Campbell <lcampbel@akamai.com>
|
||||
|
||||
* Source/NSFileManager.m: Fix for ([-contentsEqualAtPath:andPath:])
|
||||
|
|
|
@ -228,6 +228,14 @@ typedef uint32_t OSType;
|
|||
error: (NSError**)error;
|
||||
- (BOOL) removeItemAtPath: (NSString*)path
|
||||
error: (NSError**)error;
|
||||
- (BOOL) copyItemAtURL: (NSURL*)src
|
||||
toURL: (NSURL*)dst
|
||||
error: (NSError**)error;
|
||||
- (BOOL) moveItemAtURL: (NSURL*)src
|
||||
toURL: (NSURL*)dst
|
||||
error: (NSError**)error;
|
||||
- (BOOL) removeItemAtURL: (NSURL*)path
|
||||
error: (NSError**)error;
|
||||
#endif
|
||||
|
||||
- (BOOL) changeCurrentDirectoryPath: (NSString*)path;
|
||||
|
|
|
@ -1126,6 +1126,27 @@ static NSStringEncoding defaultEncoding;
|
|||
return YES;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the a file or directory specified by the <i>src</i> URL to the
|
||||
* location specified by the <i>dst</i> URL. If the <i>src</i> is a directory,
|
||||
* it is copied recursively with all of its contents.<br />
|
||||
* Errors are returned in the <i>error</i> variable.
|
||||
* Returns YES on success, NO otherwise.
|
||||
*/
|
||||
- (BOOL) copyItemAtURL: (NSURL*)src
|
||||
toURL: (NSURL*)dst
|
||||
error: (NSError**)error
|
||||
{
|
||||
return [self copyItemAtPath: [src path] toPath: [dst path] error: error];
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the item specified by the <i>src</i> path to the
|
||||
* location specified by the <i>dst</i> path. If the <i>src</i> is a directory,
|
||||
* it is copied recursively with all of its contents.<br />
|
||||
* Errors are returned in the <i>error</i> variable.
|
||||
* Returns YES on success, NO otherwise.
|
||||
*/
|
||||
- (BOOL) copyItemAtPath: (NSString*)src
|
||||
toPath: (NSString*)dst
|
||||
error: (NSError**)error
|
||||
|
@ -1233,6 +1254,25 @@ static NSStringEncoding defaultEncoding;
|
|||
return NO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a file or directory specified by <i>src</i> to
|
||||
* its destination specified by <i>dst</i>, errors are
|
||||
* returned in <i>error</i>.<br />
|
||||
* Returns YES on success, NO otherwise.
|
||||
*/
|
||||
- (BOOL) moveItemAtURL: (NSURL*)src
|
||||
toURL: (NSURL*)dst
|
||||
error: (NSError**)error
|
||||
{
|
||||
return [self moveItemAtPath: [src path] toPath: [dst path] error: error];
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a file or directory specified by <i>src</i> to
|
||||
* its destination specified by <i>dst</i>, errors are
|
||||
* returned in <i>error</i>.<br />
|
||||
* Returns YES on success, NO otherwise.
|
||||
*/
|
||||
- (BOOL) moveItemAtPath: (NSString*)src
|
||||
toPath: (NSString*)dst
|
||||
error: (NSError**)error
|
||||
|
@ -1476,6 +1516,26 @@ static NSStringEncoding defaultEncoding;
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Removes the file or directory specified by the <i>url</i>
|
||||
* to be removed. If the <i>url</i> points to a directory,
|
||||
* the directory is deleted recursively.<br />
|
||||
* Returns YES on success, otherwise NO.
|
||||
*/
|
||||
- (BOOL) removeItemAtURL: (NSURL*)url
|
||||
error: (NSError**)error
|
||||
{
|
||||
return [self removeItemAtPath: [url path] error: error];
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the file or directory specified by the <i>path</i>
|
||||
* to be removed. If the <i>path</i> points to a directory,
|
||||
* the directory is deleted recursively.<br />
|
||||
* Returns YES on success, otherwise NO.
|
||||
*/
|
||||
- (BOOL) removeItemAtPath: (NSString*)path
|
||||
error: (NSError**)error
|
||||
{
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
#import <Foundation/NSError.h>
|
||||
#import <Foundation/NSURL.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
|
@ -225,14 +228,46 @@ NSLog(@"'%@', '%@'", NSUserName(), [attr fileOwnerAccountName]);
|
|||
"NSFileManager can create intermediate directories on URL");
|
||||
PASS([mgr fileExistsAtPath: dirInDir isDirectory: &isDir] && isDir == YES,
|
||||
"NSFileManager create directory and intermediate directory on URL");
|
||||
|
||||
[mgr createDirectoryAtPath: @"sub1"
|
||||
withIntermediateDirectories: YES
|
||||
attributes: nil
|
||||
error: &err];
|
||||
[mgr createDirectoryAtPath: @"sub2"
|
||||
withIntermediateDirectories: YES
|
||||
attributes: nil
|
||||
error: &err];
|
||||
[mgr copyItemAtURL: [NSURL fileURLWithPath: @"sub1"]
|
||||
toURL: [NSURL fileURLWithPath: @"sub2/sub1"]
|
||||
error: &err];
|
||||
PASS([mgr fileExistsAtPath: @"sub2/sub1" isDirectory: &isDir]
|
||||
&& isDir == YES, "NSFileManager copy item at URL");
|
||||
[mgr copyItemAtPath: @"sub2" toPath: @"sub1/sub2" error: &err];
|
||||
PASS([mgr fileExistsAtPath: @"sub1/sub2/sub1" isDirectory: &isDir]
|
||||
&& isDir == YES, "NSFileManager copy item at Path");
|
||||
[mgr moveItemAtURL: [NSURL fileURLWithPath: @"sub2/sub1"]
|
||||
toURL: [NSURL fileURLWithPath: @"sub1/moved"]
|
||||
error: &err];
|
||||
PASS([mgr fileExistsAtPath: @"sub1/moved" isDirectory: &isDir]
|
||||
&& isDir == YES, "NSFileManager move item at URL");
|
||||
[mgr moveItemAtPath:@"sub1/sub2" toPath:@"sub2/moved" error: &err];
|
||||
PASS([mgr fileExistsAtPath: @"sub2/moved" isDirectory: &isDir]
|
||||
&& isDir == YES, "NSFileManager move item at Path");
|
||||
[mgr removeItemAtURL: [NSURL fileURLWithPath: @"sub1"]
|
||||
error: &err];
|
||||
PASS([mgr fileExistsAtPath: @"sub1" isDirectory: &isDir] == NO,
|
||||
"NSFileManager remove item at URL");
|
||||
[mgr removeItemAtPath: @"sub2" error: &err];
|
||||
PASS([mgr fileExistsAtPath: @"sub2" isDirectory: &isDir] == NO,
|
||||
"NSFileManager remove item at Path");
|
||||
|
||||
PASS_EXCEPTION([mgr removeFileAtPath: @"." handler: nil];,
|
||||
NSInvalidArgumentException,
|
||||
"NSFileManager -removeFileAtPath: @\".\" throws exception");
|
||||
NSInvalidArgumentException,
|
||||
"NSFileManager -removeFileAtPath: @\".\" throws exception");
|
||||
|
||||
PASS_EXCEPTION([mgr removeFileAtPath: @".." handler: nil];,
|
||||
NSInvalidArgumentException,
|
||||
"NSFileManager -removeFileAtPath: @\"..\" throws exception");
|
||||
NSInvalidArgumentException,
|
||||
"NSFileManager -removeFileAtPath: @\"..\" throws exception");
|
||||
/* clean up */
|
||||
[mgr changeCurrentDirectoryPath: [[[mgr currentDirectoryPath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]];
|
||||
exists = [mgr fileExistsAtPath: dir isDirectory: &isDir];
|
||||
|
|
Loading…
Reference in a new issue