0

I have implemented a "safe save" operation that goes something like this:

  1. Save some data to temporary file A
  2. Copy contents of A to final destination B
  3. 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?

4

1 回答 1

0

是正在发生的事情:

  1. FSDeleteObject暂时失败的最常见原因fBsyErr是 Spotlight 正在索引文件。如果您修改文件,将其关闭,然后立即尝试使用 删除它FSDeleteObject,则 Spotlight 索引器很可能会打开它并且您会得到fBsyErr.
  2. 一些第三方防病毒扫描程序也可能触发此问题。当您关闭修改过的文件时,防病毒扫描程序会立即开始检查它是​​否有病毒。如果您尝试删除文件时它仍在检查,FSDeleteObject则会失败并显示fBsyErr.

每个问题都有一系列的解决方法,最好的方法是使用unlink

于 2010-02-11T23:21:44.677 回答