• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Does -[NSFileManager attributesOfItemAtPath:error:] traverse symlinks?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Does -[NSFileManager attributesOfItemAtPath:error:] traverse symlinks?
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: Handling NSApplicationDefined events
  • Next by Date: NSUserDefaults
  • Previous by thread: Re: NSControlTextDidChangeNotification - What key pressed?
  • Next by thread: Re: Does -[NSFileManager attributesOfItemAtPath:error:] traverse symlinks?
  • Index(es):
    • Date
    • Thread