bugGNUstep - Bugs: bug #35692, [NSFileManager...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #35692: [NSFileManager attributesOfItemAtPath:error:] populates the supplied error even if there is no error at all

Submitted by:  Sergei Golovin <svg>
Submitted on:  Fri 02 Mar 2012 01:04:53 PM UTC  
 
Category: Base/FoundationSeverity: 3 - Normal
Item Group: BugStatus: Fixed
Privacy: PublicAssigned to: None
Open/Closed: Closed

Sat 03 Mar 2012 08:43:10 AM UTC, comment #1:

Thanks very much ...

I couldn't actually apply your patches, because you placed them in the text of the web page rather than as an attachment, and the web browser I use alters the spacing etc so an patch inline in the text won't apply. Also, I noticed an error in the patch that it would attempt to set a nil value in *error even if error was NULL.
So I rewrote/modified manually and applied a similar fix.

But, it's really great that you supplied a test case ... that's very useful. I wish more people wold do it ... thanks.

Richard Frith-Macdonald <CaS>
Project Member
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],
----------------------------------------------------------------

Sergei Golovin <svg>

 

Attached Files
file #25243:  NSFileManager_attributesOfItemAtPath_error.patch added by svg (493B - text/x-patch - The patches)
file #25244:  NSFileManager_general.patch added by svg (1KiB - text/x-patch - The patches)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by CaS (Posted a comment)
  • -unavailable- added by svg (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sat 03 Mar 2012 08:43:10 AM UTCCaSStatusNone=>Fixed
      Open/ClosedOpen=>Closed
    Fri 02 Mar 2012 01:08:02 PM UTCsvgAttached File-=>Added NSFileManager_attributesOfItemAtPath_error.patch, #25243
      Attached File-=>Added NSFileManager_general.patch, #25244

    Back to the top


    Powered by Savane 3.1-cleanup1