diff options
| author | Patrick Norton <patrick.147.norton@gmail.com> | 2026-01-01 09:04:27 -0500 |
|---|---|---|
| committer | Nguyễn Gia Phong <cnx@loang.net> | 2026-08-31 11:00:19 +0900 |
| commit | 7fb8a151ff6699e7a6b9ed3144e3930b702a7814 (patch) | |
| tree | 2f77523fafe1dab27b295e8aadb2682cb4506cd1 | |
| parent | 02f91c40f6849f10da6f860145349087546f5757 (diff) | |
guix: build: utils: Add delete-all-but.
* guix/build/utils.scm (delete-all-but): New variable.
Merges: https://codeberg.org/guix/guix/pulls/5312
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>
| -rw-r--r-- | guix/build/utils.scm | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/guix/build/utils.scm b/guix/build/utils.scm index 99d4626acf9..2d88b865b01 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm | |||
| @@ -78,6 +78,7 @@ | |||
| 78 | make-file-writable | 78 | make-file-writable |
| 79 | copy-recursively | 79 | copy-recursively |
| 80 | delete-file-recursively | 80 | delete-file-recursively |
| 81 | delete-all-but | ||
| 81 | file-name-predicate | 82 | file-name-predicate |
| 82 | find-files | 83 | find-files |
| 83 | false-if-file-not-found | 84 | false-if-file-not-found |
| @@ -523,6 +524,14 @@ errors." | |||
| 523 | ;; Don't follow symlinks. | 524 | ;; Don't follow symlinks. |
| 524 | lstat))) | 525 | lstat))) |
| 525 | 526 | ||
| 527 | (define (delete-all-but directory . preserve) | ||
| 528 | "Delete DIRECTORY recursively except for the files in PRESERVE immediately | ||
| 529 | found under it." | ||
| 530 | (with-directory-excursion directory | ||
| 531 | (let* ((pred (negate (cut member <> (cons* "." ".." preserve)))) | ||
| 532 | (items (scandir "." pred))) | ||
| 533 | (for-each (cut delete-file-recursively <>) items)))) | ||
| 534 | |||
| 526 | (define (file-name-predicate regexp) | 535 | (define (file-name-predicate regexp) |
| 527 | "Return a predicate that returns true when passed a file name whose base | 536 | "Return a predicate that returns true when passed a file name whose base |
| 528 | name matches REGEXP." | 537 | name matches REGEXP." |
