guix_mirror_bot pushed a commit to branch misc-world-rebuild
in repository guix.

commit 7c2858b49adbca7c1b1850edf08d0272af40597a
Author: Patrick Norton <[email protected]>
AuthorDate: Thu Jan 1 09:04:27 2026 -0500

    guix: build: utils: Add delete-all-but.
    
    * guix/build/utils.scm (delete-all-but): New variable.
    
    Change-Id: I15e1d632a97236b8d18cec3be993c81e138dff04
    Reviewed-by: Maxim Cournoyer <[email protected]>
    Reviewed-by: Cayetano Santos <[email protected]>
    Reviewed-by: Gabriel Wicki <[email protected]>
    Signed-off-by: Nguyễn Gia Phong <[email protected]>
---
 guix/build/utils.scm | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index 19203dc36a..3702608dfd 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -78,6 +78,7 @@
             make-file-writable
             copy-recursively
             delete-file-recursively
+            delete-all-but
             file-name-predicate
             find-files
             false-if-file-not-found
@@ -523,6 +524,14 @@ errors."
                       ;; Don't follow symlinks.
                       lstat)))
 
+(define (delete-all-but directory . preserve)
+  "Delete DIRECTORY recursively except for the files in PRESERVE immediately
+found under it."
+  (with-directory-excursion directory
+    (let* ((pred (negate (cut member <> (cons* "." ".." preserve))))
+           (items (scandir "." pred)))
+      (for-each (cut delete-file-recursively <>) items))))
+
 (define (file-name-predicate regexp)
   "Return a predicate that returns true when passed a file name whose base
 name matches REGEXP."

Reply via email to