master: Delete work files without pre-testing for existence

snuglas via Sbcl-commits <[email protected]> Tue, 14 Jul 2026 15:19:04 +0000
Newsgroups gmane.lisp.steel-bank.cvs
Message-ID <[email protected]>
The branch "master" has been updated in SBCL:
       via  83c7aafa1944032dc49ae46c95b2c69242361988 (commit)
      from  6927ec50b9de0149b087bccfddc3cf5e2679288d (commit)

- Log -----------------------------------------------------------------
commit 83c7aafa1944032dc49ae46c95b2c69242361988
Author: Douglas Katzman <[email protected]>
Date:   Tue Jul 14 15:18:42 2026 +0000

    Delete work files without pre-testing for existence
---
 src/cold/shared.lisp | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/cold/shared.lisp b/src/cold/shared.lisp
index 41eecf18e..9b6e7b3aa 100644
--- a/src/cold/shared.lisp
+++ b/src/cold/shared.lisp
@@ -596,6 +596,13 @@
 
 ;;;; tools to compile SBCL sources to create the cross-compiler
 
+(defun delete-if-exists (pathname)
+  ;; The used to be expressed as (WHEN (PROBE-FILE X) (DELETE-FILE X))
+  ;; which is potentially 100x more costly in terms of filesystem operations
+  ;; depending on how many times PROBE-FILE decided to invoke lstat.
+  (handler-case (delete-file pathname)
+    (file-error (c) (declare (ignore c)) t)))
+
 ;;; a wrapper for compilation/assembly, used mostly to centralize
 ;;; the procedure for finding full filenames from "stems"
 ;;;
@@ -653,8 +660,7 @@
     ;; delete any preexisting object file in order to avoid confusing
     ;; ourselves later should we happen to bail out of compilation
     ;; with an error.
-    (when (and (not *compile-for-effect-only*) (probe-file obj))
-      (delete-file obj))
+    (unless *compile-for-effect-only* (delete-if-exists obj))
 
     ;; Original comment:
     ;;
@@ -683,8 +689,7 @@
     ;; and some compilers (e.g. OpenMCL) will complain if they're
     ;; asked to write over a file that exists already (and isn't
     ;; recognizeably a fasl file), so
-    (when (probe-file tmp-obj)
-      (delete-file tmp-obj))
+    (delete-if-exists tmp-obj)
 
     ;; Try to use the compiler to generate a new temporary object file.
     (flet ((report-recompile-restart (stream)
@@ -742,10 +747,9 @@
 
     ;; If we get to here, compilation succeeded, so it's OK to rename
     ;; the temporary output file to the permanent object file.
-    (cond ((not *compile-for-effect-only*)
-           (rename-file-a-la-unix tmp-obj obj))
-          ((probe-file tmp-obj)
-           (delete-file tmp-obj)))      ; clean up the trash
+    (if *compile-for-effect-only*
+        (delete-if-exists tmp-obj)
+        (rename-file-a-la-unix tmp-obj obj))
 
     ;; nice friendly traditional return value
     (pathname obj)))

-----------------------------------------------------------------------


hooks/post-receive
-- 
SBCL