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

Bug #806398 reported by Tobias C. Rittweiler
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Wishlist
Unassigned

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
Revision history for this message
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
Revision history for this message
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)
Revision history for this message
Luís Oliveira (luismbo) wrote : Re: [Bug 806398] Re: wanted: SUPERSEDE / OVERWRITE restart for :IF-EXISTS :ERROR

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)
Changed in sbcl:
assignee: Luís Oliveira (luismbo) → Nic M (nicdevel)
Revision history for this message
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

Jan Moringen (scymtym)
Changed in sbcl:
assignee: Nic M (nicdevel) → nobody
status: In Progress → Fix Committed
Changed in sbcl:
status: Fix Committed → Fix Released
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.