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

Geo Carncross geocar at gmail.com
Mon Nov 26 19:33:50 UTC 2007


On Nov 26, 2007 12:01 PM, Mark Hoemmen <mhoemmen at cs.berkeley.edu> wrote:
> > Maybe having a non-standard :temporary-pathname key (which defaulted
> > to the pathname, with :name and/or :type chosen randomly) would be the
> > right thing to do.
> >
> > The temporary file, however, shouldn't "look" like a regular file-
> > give it a name like (format nil "temp,~a.~a.tmp" (get-universal-time)
> > (incf *some-process-counter*)) so that a cleaner can be written easily
> > (if anyone ever wants to).
>
> POSIX has safer functions to handle this sort of thing.  I've got some
> CFFI + Lisp glue to invoke them, if you're interested.  I've used it
> in my Lisp initialization script before:  a hackish way to figure out
> the file extension for FASLs is to compile a temporary file.

Using O_CREAT|O_EXCL makes it safe on a single machine, and using a
combination of gethostname(), time(NULL), and getpid() will make it
safe on NFS (at least safe from itself).

I have no idea how to safely chose filenames in Windows in the
presence of DFS. Perhaps Windows DFS shares, like Windows 95 will
simply have it possible that :supersede will do what it presently
does, so I'm not really that worried.

I was mostly referring to garbage collection in the sense of; if the
system crashes there will be a bunch of temp,13945193.412389.localhost
files floating around the filesystem. They can be safely deleted any
time their mtime is older than the system boot, but this isn't ECL's
job, nor necessarily the job of the application, but the job of the
person running the machine- it may be interesting to them that a bunch
of 2GB .localhost files are in /mnt/q whenever the server "reboots
itself", if that makes any sense.

> Should we take this discussion off-list and do some hacking?

It's fairly straightforward, but a cursory examination suggests it
would be fairly deep as well. At least src/c/file.d would require the
requisite logic, and src/h/object.h would need ecl_stream modified to
include the temporary filename as well as the desired filename.

I presently have this snippet in a lot of little lisp projects (and C
projects) that go through these contortions, but requiring FFI on ECL
means that it's presently quite expensive (pulling in the compiler
everywhere I need to write to a single file safely).  Because of the
potential size of the patch, I was hoping to get some official
approval before hacking.

I'd also be happy locating all of the necessary changes inside
RENAME-FILE by giving it :IF-EXISTS and :IF-DOES-NOT-EXIST keys that
chose the appropriate logic. Paired with a SI:POSIX-FSYNC routine,
this'd allow me to avoid the FFI on ECL, although it wouldn't be
*quite* so elegant (IMO) from lisp-space.




More information about the ecl-devel mailing list