为了确定文件的大小,我一直使用:
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
unsigned long long size = [fileAttributes fileSize];
但是,方法attributesOfItemAtPath:error:
不会遍历符号链接(symbolic link)。苹果如此建议:
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.
如果沙箱不会阻止我访问指向的文件,那就太好了:
deny file-read-xattr
/path/to/the/original/file
所以,我的问题是:如何获取 OS X 沙箱下符号链接(symbolic link)指向的文件的大小?
最佳答案
这似乎是一个错误。如果用户专门将符号链接(symbolic link)拖动到应用程序,则这是用户意图的明确声明,并且您希望能够访问符号链接(symbolic link)和目标。事实上,我可以访问原始文件并读取其内容,但不能访问其属性。所以我提交了错误报告#13143810。
编辑:我的错误报告已作为 #12991152 的重复项而关闭,该报告实际上是“开放的”。
关于macos - 确定 OS X 沙箱下符号链接(symbolic link)指向的文件的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14601863/