Mac 上文件删除有时会失败
技术问答 1497 和这个问题(其答案从技术说明中复制)表明,当得到<来自 FSDeleteObject
的 code>fBsyErr,正确的解决方法是在 10.5+ 上调用 FSUnlinkObject
。
FSDeleteObject
和 FSUnlinkObject
这两个 API 之间的技术差异是什么 (除了注意到 FSUnlinkObject
没有出现在文档中)?为什么unlink
应该作为后备API而不是主要API?
Technical Q&A 1497
and this question (whose answer copied from the tech note) indicate that, when getting fBsyErr
from FSDeleteObject
, the proper workaround is to call FSUnlinkObject
on 10.5+.
What is the technical difference between the two APIs FSDeleteObject
and FSUnlinkObject
(other than noting that FSUnlinkObject
does not appear in the documentation)? Why should unlink
be the fallback and not the primary API?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜想
FSDeleteObject
首先出现是因为它延续了 Mac OS 与 Unix 合并之前很久就存在的一系列文件删除功能,而取消文件链接是一个 Unix 概念。I'd guess that
FSDeleteObject
came first because it continues a line of file-deletion functions that existed long before the Mac OS merged with Unix, whereas unlinking a file is a Unix concept.您链接的苹果文档非常清楚地解释了其中的差异。 FSUnlinkObject 与 unlink() 具有相同的语义 - 允许删除打开的文件。 FSDeleteObject 不允许删除打开的文件,并在您尝试这样做时返回该错误代码。
The Apple document you linked explains the difference quite clearly. FSUnlinkObject has the same semantics as unlink() - deleting open files is allowed. FSDeleteObject does not allow deleting open files and returns that error code when you attempt to do so.