To determine the size of a file, I have always used:
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
unsigned long long size = [fileAttributes fileSize];
However, the method attributesOfItemAtPath:error:
does not traverse symbolic links. Apple so suggests:
If the item at the path is a symbolic link—that is, the value of the
NSFileType
key in the attributes dictionary isNSFileTypeSymbolicLink
—you can use thedestinationOfSymbolicLinkAtPath:error:
method to retrieve the path of the item pointed to by the link.
This would be great, if the sandbox does not prevent me from accessing the pointed file:
deny file-read-xattr
/path/to/the/original/file
So, my question is: how can I obtain the size of a file pointed by a symbolic link under the OS X sandbox?
It seems to be a bug. If the user has specifically dragged a symlink to the app, that's a clear statement of user intent and you'd expect to have access to the symlink and the target. In fact, I can access the original file and read its contents, but not its attributes. So I filed the bug report #13143810.
EDIT: My bug report has been closed as duplicate of #12991152, which is actually "open."