Fri 02 Mar 2012 01:04:53 PM UTC, original submission:
The method doesn't check by the if statement the return value
of the previously called [[GSAttrDictionaryClass
attributesAt:traverseLink:] :
----------------------------------------------------------------
NSDictionary *d;
d = [GSAttrDictionaryClass attributesAt:
[self fileSystemRepresentationWithPath: path] traverseLink: NO];
if (error != NULL) // <= lack of check of the value 'd'
{
*error = [NSError _last];
}
return d;
----------------------------------------------------------------
The value 'd' is returned as 'nil' if there has been an error.
So here is the patch:
----------------------------------------------------------------
Index: Source/NSFileManager.m
===================================================================
--- Source/NSFileManager.m (revision 34863)
+++ Source/NSFileManager.m (working copy)
@@ -1876,10 +1876,14 @@
d = [GSAttrDictionaryClass attributesAt:
[self fileSystemRepresentationWithPath: path] traverseLink: NO];
- if (error != NULL)
+ if ( d == nil && error != NULL)
{
*error = [NSError _last];
}
+ else
+ {
+ *error = nil;
+ }
return d;
}
----------------------------------------------------------------
And another patch for tests:
----------------------------------------------------------------
Index: Tests/base/NSFileManager/general.m
===================================================================
--- Tests/base/NSFileManager/general.m (revision 34863)
+++ Tests/base/NSFileManager/general.m (working copy)
@@ -35,6 +35,7 @@
{
NSDictionary *attr;
BOOL isDir;
+ NSError *err;
PASS([mgr createDirectoryAtPath: dir attributes: nil],
"NSFileManager can create a directory");
PASS([mgr fileExistsAtPath: dir isDirectory: &isDir] &&
@@ -48,6 +49,13 @@
PASS([NSUserName() isEqual: [attr fileOwnerAccountName]],
"newly created file is owned by current user");
NSLog(@"'%@', '%@'", NSUserName(), [attr fileOwnerAccountName]);
+ attr = [mgr attributesOfItemAtPath: dir error: &err];
+ PASS(attr != nil && err == nil,
+ "[NSFileManager attributesOfItemAtPath:error:] returns non-nil for attributes and nil for error in the case of existing file");
+ attr = [mgr attributesOfItemAtPath: [dir stringByAppendingPathComponent: @"thispathMUSTNOTexistatyoursystem"]
+ error: &err];
+ PASS(attr == nil && err != nil,
+ "[NSFileManager attributesOfItemAtPath:error:] returns nil for attributes and non-nil for error in the case of non-existent file");
}
PASS([mgr changeCurrentDirectoryPath: dir],
----------------------------------------------------------------
|