[Ecls-list] open :supersede and rename-file advise

Mark Hoemmen mark.hoemmen at gmail.com
Mon Nov 26 16:17:27 UTC 2007


On 11/26/07, Geo Carncross <geocar at gmail.com> wrote:
> Under unix, robust applications tend to write to new files in the following way:
>
>   fd = open(tempfile, O_EXCL|O_CREAT, 0600);
>   ... write to fd ...
>   if (fsync(fd) == -1) goto fail;
>   if (close(fd) == -1) goto fail; /* NFS can fail here */
>   if (rename(tempfile, realfile) == -1) goto fail;
>
> This has the benefit of having no points where "realfile" has
> incomplete or invalid data.

It's important here, I think, to put TEMPFILE in the same directory as
REALFILE, rather than using TMPDIR.  You could have problems if TMPDIR
defaults to /tmp or something like it, and the desired file to create
is large.  /tmp or /var/tmp are typically on small partitions, so
users may think they have enough space to create a file (say in their
home directory), but find that the file write fails unexpectedly.
Furthermore, filling up /tmp or /var/tmp tends to cause a lot of
problems for running applications (e.g., batch schedulers tend to fail
in ways that are mysterious for the uninitiated).

mfh




More information about the ecl-devel mailing list