wanted: SUPERSEDE / OVERWRITE restart for :IF-EXISTS :ERROR

Bug #806398 reported by Tobias C. Rittweiler on 2011-07-06
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Wishlist
Nic M

Bug Description

(progn (open "/tmp/foo" :direction :output :if-exists :supersede)
                 (open "/tmp/foo" :direction :output :if-exists :error))

It would be nice if there was a restart to supersede / overwrite the existing file.

Changed in sbcl:
importance: Undecided → Wishlist
status: New → Triaged
tags: added: easy feature
Luís Oliveira (luismbo) wrote :

Here's a first stab at this. I think implementing the restart as a recursive call is nice because (a) it shows up in the stack trace and (b) it's straightforward to implement. However, cluttering OPEN with a &REST ARGS is a bit unfortunate. Any better ideas?

tags: added: review
Changed in sbcl:
assignee: nobody → Luís Oliveira (luismbo)
Changed in sbcl:
assignee: Luís Oliveira (luismbo) → Nikodemus Siivola (nikodemus)
status: Triaged → In Progress
Nikodemus Siivola (nikodemus) wrote :

Luis, do you want me to mangle this into shape, or do you want comments to finish it yourself?

Assuming the latter.

I would mildly prefer this to be implement this as

  (return-from open
    (tagbody :restart
       (let* ((pathname ...) ...)
          (flet ((open-error (...)
                     (%open-error ...additional args and defaults...
                                           (lambda (&key ...)
                                              ...set values based on keys...
                                              (go :restart)))
             ...body-of-open...))))

instead of a recursive call. Where %OPEN-ERROR would be an out of line function with a big RESTART-CASE in it, and all errors in OPEN going to it through OPEN-ERROR -- using :TEST clause in the RESTART-CASE to decide which restarts to activate.

While in the area, other useful restarts might be to switch to:

  :IF-EXISTS :APPEND
  :IF-DOES-NOT-EXIST :CREATE

and to return NIL instead of the stream, simply retry without doing anything else, USE-VALUE for a different pathname, and finally to create missing directories...

...but that might count as heroic effort. :)

However, if the error signaling and restarts are moved out of line, it would not clutter OPEN and such heroic effort can be later expanded much more easily.

Changed in sbcl:
assignee: Nikodemus Siivola (nikodemus) → Luís Oliveira (luismbo)

On Thu, Dec 8, 2011 at 2:47 PM, Nikodemus Siivola
<email address hidden> wrote:
> Luis, do you want me to mangle this into shape, or do you want comments
> to finish it yourself?

The latter. Thanks for your comments. I'll give it another go.

Nic M (nicdevel) on 2013-04-22
Changed in sbcl:
assignee: Luís Oliveira (luismbo) → Nic M (nicdevel)
Nic M (nicdevel) wrote :

This patch is my attempt to realize the solution outlined by nikodemus above. It is work in progress and I welcome all comments as I am still working on CL skills.

I have questions on :TEST, would it be better to FILE-EXISTS-ERROR and FILE-DOES-NOT-EXIST-ERROR conditions instead of SIMPLE-FILE-ERROR?

Also, :APPEND and :SUPERSEDE restarts do not appear to work even though the values are passed back to the restarts. I am missing something.

Thanks, Nic Mollel

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

Other bug subscribers