From debbugs-submit-bounces@debbugs.gnu.org Sat Feb 22 20:23:35 2025 Received: (at submit) by debbugs.gnu.org; 23 Feb 2025 01:23:35 +0000 Received: from localhost ([127.0.0.1]:58151 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tm0iU-000864-Ra for submit@debbugs.gnu.org; Sat, 22 Feb 2025 20:23:35 -0500 Received: from lists.gnu.org ([2001:470:142::17]:39304) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tm0iR-00085p-Of for submit@debbugs.gnu.org; Sat, 22 Feb 2025 20:23:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tm0iM-000876-9b for guix-patches@gnu.org; Sat, 22 Feb 2025 20:23:26 -0500 Received: from qs51p00im-qukt01080301.me.com ([17.57.155.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tm0iK-0000ad-9Q for guix-patches@gnu.org; Sat, 22 Feb 2025 20:23:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; bh=poAOmTqI56tzS8O0yn364Gvtq1XSZbraNKAohoqtspE=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:x-icloud-hme; b=A1dkf8cQifqW/JXAhI/uB+x0c3r3+F22is0gyMW0TQRh01WrezhiSxrPLq6SXs8wF 50SbtLPKRlUimt8gmmuEjOKOuwSlsj+N5iQnOeVaArVze9SxzZBTv6Mi7cQHa2O8MJ E/c+trgPBhFN0wpIzjJthNaQpK6Mbp/9W6xTYxJE38XV9VZXlupgXtG+d+wH/IASH4 8EyXJJhSNDjSQmao0TIjB+D9uNUg/SwQL9HArtDg8JyMP7rjcr73kzk7Y5Dwo9J13W 4usTGS0YpBw1buU4jsRsASVbIMp3F//fv6aW72BcV8pM1OrTuYtfHnZKRazdufyEjM 3RpavqJtP3hRQ== Received: from wongworks.lan (qs51p00im-dlb-asmtp-mailmevip.me.com [17.57.155.28]) by qs51p00im-qukt01080301.me.com (Postfix) with ESMTPSA id D86925F00173; Sun, 23 Feb 2025 01:23:18 +0000 (UTC) From: Andrew Wong To: guix-patches@gnu.org Subject: [PATCH] build/utils: Add delete-all-but Date: Sat, 22 Feb 2025 20:18:58 -0500 Message-ID: <0b8d4eb4212609048cf81f2e3e6e3da83c1caf46.1740273538.git.wongandj@icloud.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-Debbugs-Cc: Andreas Enge , Janneke Nieuwenhuizen , Ludovic Courtès , Zheng Junjie Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: hoxzyO-ZrR8HdaAzRcC-78DA2kzndnw4 X-Proofpoint-ORIG-GUID: hoxzyO-ZrR8HdaAzRcC-78DA2kzndnw4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-22_11,2025-02-20_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 phishscore=0 malwarescore=0 clxscore=1015 adultscore=0 suspectscore=0 spamscore=0 mlxlogscore=671 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2502230008 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 Received-SPF: pass client-ip=17.57.155.20; envelope-from=wongandj@icloud.com; helo=qs51p00im-qukt01080301.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit Cc: Andrew Wong X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) * guix/build/utils.scm (delete-all-but): New procedure. Change-Id: I82db4b63c45d88ef0529adb760182495c28dae9e --- delete-all-but is defined and used within package definitions a total of 11 times according to a simple grep; it makes sense to move it to a common location. However, changing (guix build utils) is a heavy change, so perhaps there is a better branch to merge this to than master. guix/build/utils.scm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/guix/build/utils.scm b/guix/build/utils.scm index 94714bf397..b74c1ad7d8 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -10,6 +10,7 @@ ;;; Copyright © 2021, 2022 Maxime Devos ;;; Copyright © 2021 Brendan Tildesley ;;; Copyright © 2023 Carlo Zancanaro +;;; Copyright © 2025 Andrew Wong ;;; ;;; This file is part of GNU Guix. ;;; @@ -77,6 +78,7 @@ (define-module (guix build utils) make-file-writable copy-recursively delete-file-recursively + delete-all-but file-name-predicate find-files false-if-file-not-found @@ -522,6 +524,29 @@ (define* (delete-file-recursively dir ;; Don't follow symlinks. lstat))) +(define (delete-all-but paths-kept) + "Delete all paths in DIR except for those listed in PATHS-KEPT, without +following symblinks. Report but don't ignore errors." + (let ((paths-kept (map (cut canonicalize-path <>) + paths-kept))) + (file-system-fold + (lambda (current-path current-stat result) ;enter? + (not (member (canonicalize-path current-path) paths-kept string=?))) + (lambda (file file-stat result) ;leaf + (if (not (any (cut string-prefix? (canonicalize-path file) <>) + paths-kept)) + (warn-on-error (delete-file file) file))) + (const #t) ;down + (lambda (dir dir-stat result) ;up + (if (not (any (cut string-prefix? (canonicalize-path dir) <>) + paths-kept)) + (warn-on-error (rmdir dir) dir))) + (const #t) ;skip + (lambda (file stat errno result) ;error + (format (current-error-port) + "warning: failed to delete ~a: ~a~%" file (strerror errno))) + #t (getcwd) lstat))) + (define (file-name-predicate regexp) "Return a predicate that returns true when passed a file name whose base name matches REGEXP." base-commit: cd20619cfcb32c2631fb602729512740bc510550 -- 2.48.1 From debbugs-submit-bounces@debbugs.gnu.org Thu Jun 05 04:10:22 2025 Received: (at control) by debbugs.gnu.org; 5 Jun 2025 08:10:22 +0000 Received: from localhost ([127.0.0.1]:58448 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uN5g6-0004Z1-Iy for submit@debbugs.gnu.org; Thu, 05 Jun 2025 04:10:22 -0400 Received: from p-east3-cluster7-host10-snip4-1.eps.apple.com ([57.103.84.222]:45786 helo=outbound.qs.icloud.com) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uN5g3-0004YW-Fb for control@debbugs.gnu.org; Thu, 05 Jun 2025 04:10:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; bh=O2oJhrBVOexwbpD93KOl5/31phtyj3SkTdOkHFijJgs=; h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type:x-icloud-hme; b=fLgSOVdVV+lJSu47rC92kJbEBYg4dsfh9j+kp4fi6dBeRaI+CxZRByJhiDDgKMOBJ qG7kYxNPmsxcQ96PBTtB3XjfhMC11y3NzVR0tqJ5FxEDockgAytL33cley9k5fJ7qO I0KAs6nyI3r4IU5NptjGxThYQe7+ELdJu+nOISq5xayreykKGzjd3KuipopG6BRPCO xuHhRhil9gt5NmUpEWVmbjqSzjR20aOJdQddY+wnE0y1GYFMj2uq9vtkjRn6fHjMuu ukFc6arhdCGUi97PUZrFxkW3C0PYlRzLWPe+2usLWEjrVNnO04bKho9qXiM+rRfgiQ qi+oSpQMFAySA== Received: from outbound.qs.icloud.com (localhost [127.0.0.1]) by outbound.qs.icloud.com (Postfix) with ESMTPS id 1AE8118000B5 for ; Thu, 5 Jun 2025 08:10:11 +0000 (UTC) Received: from [192.168.86.109] (qs-asmtp-me-k8s.p00.prod.me.com [17.57.155.37]) by outbound.qs.icloud.com (Postfix) with ESMTPSA id 47BC318001A2 for ; Thu, 5 Jun 2025 08:10:11 +0000 (UTC) Message-ID: Date: Thu, 5 Jun 2025 04:10:10 -0400 MIME-Version: 1.0 User-Agent: Icedove Daily Content-Language: en-US To: control@debbugs.gnu.org From: Andrew Wong Subject: Close Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Proofpoint-GUID: Tp9gQXSYkzRt0cyfbuxkhQQU1l7_-orU X-Proofpoint-ORIG-GUID: Tp9gQXSYkzRt0cyfbuxkhQQU1l7_-orU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-05_02,2025-06-03_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 bulkscore=0 suspectscore=0 mlxlogscore=361 phishscore=0 clxscore=1015 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.22.0-2503310001 definitions=main-2506050071 X-Spam-Score: 1.2 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: close 76492 close 76910 Content analysis details: (1.2 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (wongandj[at]icloud.com) 1.2 RCVD_IN_BL_SPAMCOP_NET RBL: Received via a relay in bl.spamcop.net [Blocked - see ] 0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [57.103.84.222 listed in sa-trusted.bondedsender.org] 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [57.103.84.222 listed in bl.score.senderscore.com] X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.2 (/) close 76492 close 76910