I need to create hard links at runtime for file at paths longer than 255 characters (this is a workaround for an infuriating Excel/Word 2011 limitation). But since the same file may be opened later again, I don't want to recreate the hard link if I already have it at the path I created it the first time (I have a scheme to create such a -short- path using a UUID). Which means I need to check wether the file already 'cached' as a hard link is still indeed a hard link to the file I am opening for the user. So I need to check wether 2 paths are hard links to the same file. And I realize there is a potential race condition when testing for this, but the hard links are entirely managed by my app.
Here's the modern way to do it:
NSError* error;
id fileID1, fileID2;
if (![url1 getResourceValue:&fileID1 forKey:NSURLFileResourceIdentifierKey error:&error])
/* handle error */;
if (![url2 getResourceValue:&fileID2 forKey:NSURLFileResourceIdentifierKey error:&error])
/* handle error */;
if ([fileID1 isEqual:fileID2])
/* URLs point to the same file (inode) */;
NSURLFileResourceIdentifierKey
is exactly made for this purpose.