Feature request: Use temp file when superseding file

Bug #1934664 reported by Pierre Neidhardt
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
New
Undecided
Unassigned

Bug Description

In https://old.reddit.com/r/Common_Lisp/comments/o1zw50/reliable_file_write_via_temp_file/ it's pointed out that CCL automatically writes to a temp file when superseding a file with `(open ... :if-exists :supersede)`.

See this example: https://old.reddit.com/r/Common_Lisp/comments/o1zw50/reliable_file_write_via_temp_file/h43tfy8/

This is very useful in case of errors: the original file gets restored and thus we don't end up compromising the file integraty. Would be nice if SBCL did this as well.

Revision history for this message
Stas Boukarev (stassats) wrote :

What happens when you run out of space because of that?

Revision history for this message
Pierre Neidhardt (ambrevar) wrote : Re: [Bug 1934664] Re: Feature request: Use temp file when superseding file

Good question.

I had a look at the doc, no rationale seems to be given:
https://ccl.clozure.com/docs/ccl.html#streams

So I looked at the source. `open` calls to `make-file-stream`, but
there is no comment or documentation there as to why they create a temp
file and how they deal with full file systems.

So I guess this is an unresolved problem with CCL.

Revision history for this message
Pierre Neidhardt (ambrevar) wrote :

Good question.

I had a look at the doc, no rationale seems to be given:
https://ccl.clozure.com/docs/ccl.html#streams

So I looked at the source. `open` calls to `make-file-stream`, but
there is no comment or documentation there as to why they create a temp
file and how they deal with full file systems.

So I guess this is an unresolved problem with CCL.

Revision history for this message
Richard M Kreuter (kreuter) wrote :

ISTM there are distinguishable topics discussed in this bug report vs. the cited reddit thread:

1. whether, after an aborting close, the original file & contents can be found under its initial name,

2. whether a new file exists under some unique name until the stream is closed.

For item 1. the IF-EXISTS values :RENAME and :RENAME-AND-DELETE will rename an existing file out of the way during OPEN, and will try to restore the old file into place during an aborting close. (But note that they'll always use the same "out of the way" name, so their "restore" operation won't work if there are concurrent threads or processes trying to do this for the same pathname. I guess that's either a bug or limitation in those OPEN modes on SBCL.)

For 2, there are approaches, as mentioned in the reddit thread, but I recommend you study their documentation and implementation carefully before using them in different contexts. For instance, have a look at what this does when run repeatedly:

sbcl --noinform --no-userinit --no-sysinit --non-interactive --eval '(require :uiop)' --eval '(uiop:with-staging-pathname (var "/tmp/foo") (print var) (terpri))'

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.