1
0
mirror of https://git.savannah.gnu.org/git/guix.git synced 2026-07-01 08:14:08 +02:00

guix: build: utils: Add delete-all-but.

* guix/build/utils.scm (delete-all-but): New variable.

Change-Id: I15e1d632a97236b8d18cec3be993c81e138dff04
Reviewed-by: Maxim Cournoyer <maxim@guixotic.coop>
Reviewed-by: Cayetano Santos <csantosb@inventati.org>
Reviewed-by: Gabriel Wicki <gabriel@erlikon.ch>
Signed-off-by: Nguyễn Gia Phong <cnx@loang.net>
This commit is contained in:
Patrick Norton
2026-01-01 09:04:27 -05:00
committed by Andreas Enge
parent 0c06fc7e9b
commit d5b0ad8b46
+9
View File
@@ -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."