Re: sychronizeFile Problem
Re: sychronizeFile Problem
- Subject: Re: sychronizeFile Problem
- From: John Nairn <email@hidden>
- Date: Mon, 10 Oct 2005 13:02:49 -0600
On Oct 10, 2005, at 12:35 PM, Alastair Houghton wrote:
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.)
Initially I simply saved the file with [xmlText writeToFile:tempPath
atomically:NO], but then switched to the synchronizeFile option to
see if it would help.
Any ideas if the following is known to be true:
1. tempPath is valid and the file does get written
2. the C++ code is valid and always works when a file is available
3. Yes the task is launched in the same thread immediately after
saving the file.
and one new result I forgot to mention:
The code always work if the NSTask launches the c++ tool with reads
the output in background using launch arguments such as:
/Users/jnairn/code/MyTool -options pathToTempFile
but sometimes fails if I try to submit the job as a background task
using
/bin/csh -c 'Users/jnairn/code/MyTool -options pathToTempFile >&
pathToOutputFile &'
The job gets submitted, but the submitted job fails.
---------------
John Nairn (1-801-581-3413, FAX:1-801-581-4816)
Web Page: http://www.mse.utah.edu/~nairn
_______________________________________________
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