macos - 确定 OS X 沙箱下符号链接(symbolic link)指向的文件的大小

标签 macos cocoa sandbox nsfilemanager

为了确定文件的大小,我一直使用:

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 is NSFileTypeSymbolicLink—you can use the destinationOfSymbolicLinkAtPath: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/

相关文章:

macos - Cloudera CDH Mac

python 3。导入错误 : no module named 'myfile'

cocoa - 强制 Cocoa 文本字段结束编辑

ios - 如何为 MIDI 事件准确设置时间戳?

image - 加载图片到Webview + Safari时内存持续增加

ios - GameCenter沙盒和Beta测试

objective-c - 行间距在 Core Text 中是如何工作的? (为什么它与 NSLayoutManager 不同?)

java - 从2.2.0版本开始,JMX控制台中不显示Spring执行器指标

forms - 检测到错误 - Paypal

windows - 如何在 Windows 的沙箱中运行不受信任的代码?