Re: Path comparison and case sensitivity
Re: Path comparison and case sensitivity
- Subject: Re: Path comparison and case sensitivity
- From: Alastair Houghton <email@hidden>
- Date: Wed, 6 Jan 2010 10:25:59 +0000
On 6 Jan 2010, at 05:39, Ken Thomases wrote:
> On Jan 5, 2010, at 6:51 PM, Rob Keniger wrote:
>
>> Should Cocoa applications always assume that the filesystem is case-insensitive when comparing path strings? Surely this could lead to problems if the user has formatted a volume with a case-sensitive file system?
>
> Don't compare paths. Use APIs like FSCompareFSRefs() or call -[NSFileManager attributesOfItemAtPath:error:] and compare the NSFileDeviceIdentifier and NSFileSystemFileNumber keys (this is the Cocoa equivalent of calling stat(2) and comparing st_dev and st_ino).
Or you can canonicalise your paths first so that their components match whatever is on the disk. Then you can compare them. This is probably more work than the above though.
Depending on how you do it, this may result in different behaviour to the above suggestions; by which I mean, comparing st_dev and st_ino will tell you whether you have the same file, but what it doesn't tell you is whether the path used to get at it was different because of symlinks.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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