Does -[NSFileManager attributesOfItemAtPath:error:] traverse symlinks?
Does -[NSFileManager attributesOfItemAtPath:error:] traverse symlinks?
- Subject: Does -[NSFileManager attributesOfItemAtPath:error:] traverse symlinks?
- From: Charles Srstka <email@hidden>
- Date: Thu, 3 Sep 2009 15:59:28 -0500
Okay, the documentation for -[NSFileManager
attributesOfItemAtPath:error:] states the following:
In Mac OS X v 10.6 and earlier, if the last component of the path is
a symbolic link (the value of the NSFileType key in the attributes
dictionary isNSFileTypeSymbolicLink), it will be traversed. This
behavior may change in a future version of the Mac OS X.
However, the header states this:
/* attributesOfItemAtPath:error: returns an NSDictionary of key/
value pairs containing the attributes of the item (file, directory,
symlink, etc.) at the path in question. If this method returns
'nil', an NSError will be returned by reference in the 'error'
parameter. This method does not traverse a terminal symlink.
This method replaces fileAttributesAtPath:traverseLink:.
*/
So the docs say it will traverse the link, and the header says it
won't. In my testing, the header appears to be correct - the
dictionary I get back contains the attributes of the symlink, not the
original file. This is good, since this is actually the behavior that
I want, but the discrepancy between documentation and actual behavior
makes me nervous that this could change in the future and that I
should not rely on it (especially since the documentation flat-out
states as much).
I was wondering if any of the Apple insiders here could provide any
Word of God on this. Is this simply an error in the documentation, and
can I rely on this method to get the file attributes of a symbolic
link? Or am I better off implementing my own equivalent method as a
category on NSFileManager, using lstat and Carbon to get the relevant
information and then populating the appropriate fields of an
NSDictionary, in order to get deterministic behavior?
(apologies if this has already been asked - I did a search but
couldn't find anything.)
Thanks,
Charles
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden