Re: sychronizeFile Problem
Re: sychronizeFile Problem
- Subject: Re: sychronizeFile Problem
- From: Alastair Houghton <email@hidden>
- Date: Mon, 10 Oct 2005 19:35:11 +0100
On 10 Oct 2005, at 16:42, John Nairn wrote:
My code writes a temporary file to the disk and then launches a c++
tool as a separate NSTask. The first thing the task does is to read
that temporary file. About half the time the task works, but the
other half it fails saying no such file exists. I can check the
disk and the file is there. The problem is that the file is not
there in time for the task. I tried to "synchronizeFile" (see code
snippet below), which according to Apple does the following
"Causes all in-memory data and attributes of the file
represented by the receiver to be written to permanent storage.
This method should be invoked by programs that require the
file to always be in a known state. An invocation of this
method does not return until memory is flushed."
but it still fails. Perhaps memory is flushed, but not the volume?
I could not find method to flush the volume (like I used to use in
Carbon) to insure the file will be ready for the NSTask.
On *IX, including OS X, the file should be visible immediately after
creation, so the problem is not related to -synchronizeFile. In
fact, you shouldn't call that method because it is expensive and
unnecessary; the only reason to use -synchronizeFile (or its
equivalent, fsync()) is if you are writing e.g. a DBMS and you need
to ensure that your log file is flushed to disk.
The problem is much more likely to be related to the contents of the
"tempPath" variable, or a bug in your C++ program. (I am, of course,
assuming that you start your NSTask from the same thread that creates
the file; if you have a separate thread doing that, it could also be
that there is a race.)
Kind regards,
Alastair.
--
http://www.alastairs-place.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden