run-program with :if-ouput-exists :append assumes existing file

Bug #1958569 reported by Ingo Krabbe
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Unassigned

Bug Description

* (run-program "/bin/rm" '("/tmp/test"))
#<SB-IMPL::PROCESS :EXITED 0>
* (run-program "/bin/cat" '("/etc/passwd") :output "/tmp/test" :if-output-exists :append)

debugger invoked on a FILE-DOES-NOT-EXIST in thread
#<THREAD "main thread" RUNNING {1004A18433}>:
  The file #P"/tmp/test" does not exist: No such file or directory

restarts (invokable by number or by possibly-abbreviated name):
  0: [CREATE ] Reopen with :if-does-not-exist :create
  1: [CONTINUE ] Retry opening.
  2: [USE-VALUE] Try opening a different file.
  3: [ABORT ] Exit debugger, returning to top level.

(SB-IMPL::FILE-PERROR #P"/tmp/test" 2 FILE-DOES-NOT-EXIST)
0] 0
#<SB-IMPL::PROCESS :EXITED 0>
* (run-program "/bin/cat" '("/etc/passwd") :output "/tmp/test" :if-output-exists :append)
#<SB-IMPL::PROCESS :EXITED 0>
*

Solution: Add :if-does-not-exist :create, when opening the output file in append mode.

SBCL 2.1.4.129.pick.4-88e0ded29

Revision history for this message
Ingo Krabbe (ikrabbe-ask) wrote :

The patch is a git diff taken from the current master

Revision history for this message
Ingo Krabbe (ikrabbe-ask) wrote :

With the patch applied against the master I get
SBCL 2.2.0.148-3d74cee17-WIP

* (run-program "/bin/rm" '("/tmp/test"))
#<SB-IMPL::PROCESS :EXITED 0>
* (run-program "/bin/cat" '("/etc/passwd") :output "/tmp/test" :if-output-exists :append)
#<SB-IMPL::PROCESS :EXITED 0>

the expected behavior

Changed in sbcl:
assignee: nobody → Ingo Krabbe (ikrabbe-ask)
Stas Boukarev (stassats)
Changed in sbcl:
status: New → Fix Committed
assignee: Ingo Krabbe (ikrabbe-ask) → nobody
Revision history for this message
Ingo Krabbe (ikrabbe-ask) wrote :

Ok, the final patch used here is far simpler than my fix, but actually does what is expected, so it is the correct solution. Thank you!

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

Your fix was not entirely correct, as it passes NIL in other cases, which would make it simply return.

Revision history for this message
Ingo Krabbe (ikrabbe-ask) wrote : Re: [Bug 1958569] Re: run-program with :if-ouput-exists :append assumes existing file

On Fri, 21 Jan 2022 16:25:06 -0000
Stas Boukarev <email address hidden> wrote:

> Your fix was not entirely correct, as it passes NIL in other cases,
> which would make it simply return.
>

Ah, yes I haven't read the exact meanings and defaults from the manual.
Going this way is perfect.

"if-does-not-exist---one of :error, :create, or nil. The default is
:error if direction is :input or if-exists is :overwrite or :append;
:create if direction is :output or :io, and if-exists is neither
:overwrite nor :append; or nil when direction is :probe."

--

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

Bug attachments

Remote bug watches

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