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?
Here's what's happening:
Each problem has a series of workarounds, the best for both is to use
unlink