Add [NSURL -checkResourceIsReachableAndReturnError:].

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33245 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2011-06-04 15:08:37 +00:00
parent 8ccabb5ee6
commit 586d1786f9
3 changed files with 49 additions and 2 deletions

View file

@ -42,6 +42,7 @@ function may be incorrect
#import "Foundation/NSCoder.h"
#import "Foundation/NSData.h"
#import "Foundation/NSDictionary.h"
#import "Foundation/NSError.h"
#import "Foundation/NSException.h"
#import "Foundation/NSFileManager.h"
#import "Foundation/NSLock.h"
@ -1344,6 +1345,43 @@ static NSUInteger urlAlign;
return _baseURL;
}
- (BOOL) checkResourceIsReachableAndReturnError: (NSError **)error
{
NSString *errorStr = nil;
if ([self isFileURL])
{
NSFileManager *mgr = [NSFileManager defaultManager];
NSString *path = [self path];
if ([mgr fileExistsAtPath: path])
{
if (![mgr isReadableFileAtPath: path])
{
errorStr = @"File not readable";
}
}
else
{
errorStr = @"File does not exist";
}
}
else
{
errorStr = @"No file URL";
}
if ((errorStr != nil) && (error != NULL))
{
*error = [NSError errorWithDomain: @"NSURLError"
code: 0
userInfo: [NSDictionary
dictionaryWithObjectsAndKeys: errorStr,
NSLocalizedDescriptionKey, nil]];
}
return (errorStr != nil);
}
/**
* Returns the fragment portion of the receiver or nil if there is no
* fragment supplied in the URL.<br />