sychronizeFile Problem
sychronizeFile Problem
- Subject: sychronizeFile Problem
- From: John Nairn <email@hidden>
- Date: Mon, 10 Oct 2005 09:42:24 -0600
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.
BOOL status=[fm createFileAtPath:tempPath contents:[NSData data]
attributes:nil];
if(status)
{ NSFileHandle *fileHdl=[NSFileHandle
fileHandleForWritingAtPath:tempPath];
if(fileHdl)
{ [fileHdl writeData:[xmlText
dataUsingEncoding:NSUTF8StringEncoding]];
[fileHdl synchronizeFile];
[fileHdl closeFile];
}
else
status=NO;
}
---------------
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