Adriaan van Os wrote:
But anyway, my suggestion wasn't meant too seriously.
Still, the problem at hand is an interesting one. How do you replace an existing file on disk with a new one (assuming sequential IO) ? Some possibilities:
- delete the old one, then write a new one with the same name
Not recommended. If it crashes underway, you might lose everything. (Assuming the new contents are derived from the old ones. Otherwise, you basically want to rewrite a file, and if you don't care aboutfile ownership/permissions, deleting and recreating is roughly equivalent.)
- write a new file (using some unique name), remove the old one,
rename the new one
That's what I usually do, especially for text files where in-place updating (except for appending) is not possible.
In fact, if you omit the removing, since moving with overwriting is an atomic operation (in GPC use `FileMove' with `True' as the 2nd argument, because `Rename' refuses to overwrite, BP compatible), it will guarantee that at any point in time the name refers to a valid (complete) file.
- open the file for writing, write to it, close it with a "crunch"
option 4. open the file for writing, write to it, set the end-of-file to the point-of-current-access, close it.
So crunching would be equivalent in GPC (and BP) to `Truncate' and `Close'.
Frank