Opened 9 years ago

Last modified 8 years ago

#748 new defect

with-open-file leaves temp files on element-type errors

Reported by: rs Owned by: rme
Priority: normal Milestone:
Component: ANSI CL Compliance Version: trunk
Keywords: Cc:

Description

tested in 1.5-r13651

(with-open-file (out "/tmp/oho" 
		     :direction :output :if-exists :supersede :if-does-not-exist :create
		     :element-type :character)
  (format out "Hello"))

leaves a file named like "92483986.tem" in /tmp

Change History (2)

comment:1 Changed 8 years ago by rme

  • Owner set to rme

comment:2 Changed 8 years ago by rme

It's bad to litter the file system with temporary files, but I have to think some more about what the right thing to do would be for this particular circumstance.

Suppose that /tmp/oho already exists, and contains some data.

When one evaluates this (with-open-file ...) form, we see that the user requests that the file be superseded. Per the spec entry for OPEN...

The existing file is superseded; that is, a new file with the same name as the old one is created. If possible, the implementation should not destroy the old file until the new stream is closed.

...we keep the original contents of /tmp/oho around by renaming it to a temporary file name (like 1284534753847.tem or something). This file will get deleted later when the stream is closed (by cl:close). We then create an empty new file named /tmp/oho.

Now, if something goes wrong further along in the process of opening the file (this is all in ccl::make-file-stream, by the way), the file with the unfriendly name containing the old contents of /tmp/oho will stick around (close will never get to delete it, because we never returned a stream from open).

If there's an error creating the stream, we probably want /tmp/oho to have its original contents.

I don't know if this functionality (opening with :supersede) can even be implemented safely. There seem to be numerous race conditions.

Note: See TracTickets for help on using tickets.