wanted: SUPERSEDE / OVERWRITE restart for :IF-EXISTS :ERROR
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
| SBCL |
Wishlist
|
Nic M |
Bug Description
(progn (open "/tmp/foo" :direction :output :if-exists :supersede)
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 : | #1 |
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 : | #2 |
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 (...)
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-
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) |
Luís Oliveira (luismbo) wrote : Re: [Bug 806398] Re: wanted: SUPERSEDE / OVERWRITE restart for :IF-EXISTS :ERROR | #3 |
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.
Changed in sbcl: | |
assignee: | Luís Oliveira (luismbo) → Nic M (nicdevel) |
Nic M (nicdevel) wrote : | #4 |
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-
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
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?