调用 FSDeleteObject 时的竞争条件
我已经实现了一个“安全保存”操作,如下所示:
- 将一些数据保存到临时文件
A
- 将
A
的内容复制到最终目标B
- 删除
A
我在第 3 步遇到了竞争条件,当尝试使用 删除文件时,Mac OS X 偶尔会返回错误 -47 (
。我完全有信心我是唯一修改此文件的人,并怀疑操作系统在我尝试删除该文件时正在执行某些操作(例如后台缓存任务),从而导致错误。fBsyErr
) FSDeleteObject
这是一个间歇性问题:通常 FSDeleteObject
调用工作得很好。在我收到错误代码的情况下,当操作系统完成使用该文件时,我希望“在稍后的时间点”安全地删除该文件。
尝试删除这个麻烦的临时文件时最好采取什么措施?
I have implemented a "safe save" operation that goes something like this:
- Save some data to temporary file
A
- Copy contents of
A
to final destinationB
- Delete
A
I have a race condition at step 3 where Mac OS X will occasionally come back with error -47 (fBsyErr
) when trying to delete the file using FSDeleteObject
. I am completely confident I am the only one modifying this file and suspect the OS is doing something (e.g., background caching tasks) at the time I try to delete the file, resulting in the error.
This is an intermittent issue: normally the FSDeleteObject
call works just fine. In those cases where I get the error code back I'd like to safely delete the file "at a later point in time" when the OS is finished playing with it.
What would be the best course of action to take in trying to delete this troublesome temporary file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是正在发生的事情:
每个问题都有一系列的解决方法,对两者来说最好的方法是使用
unlink
Here's what's happening:
Each problem has a series of workarounds, the best for both is to use
unlink