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

@ -1,12 +1,17 @@
2011-06-04 Fred Kiefer <FredKiefer@gmx.de>
* Headers/Foundation/NSURL.h,
* Source/NSURL.m: Add -checkResourceIsReachableAndReturnError:
2011-06-03 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSString.m: [(-getLineStart:end:contentsEnd:forRange:)]
Fix off-by-one error iun reported contents end for DOS style lines.
Fix off-by-one error in reported contents end for DOS style lines.
2011-06-02 Riccardo Mottola <rm@gnu.org>
* Source/NSTimeZone.m: Disable use of tzname on OpenBSD too.
2011-06-02 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSTimeZone.m: Allow for quotes around zone name in

View file

@ -34,6 +34,7 @@ extern "C" {
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
@class NSError;
@class NSNumber;
/**
@ -68,6 +69,9 @@ GS_EXPORT NSString* const NSURLFileScheme;
- (NSString*) absoluteString;
- (NSURL*) absoluteURL;
- (NSURL*) baseURL;
#if OS_API_VERSION(100600,GS_API_LATEST)
- (BOOL) checkResourceIsReachableAndReturnError: (NSError **)error;
#endif
- (NSString*) fragment;
- (NSString*) host;
- (BOOL) isFileURL;

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 />