From patchwork Fri Feb 23 12:06:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VG9tw6FzIE9ydMOtbg==?= X-Patchwork-Id: 60911 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 5967227BBEA; Fri, 23 Feb 2024 12:27:05 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 3759227BBE2 for ; Fri, 23 Feb 2024 12:26:59 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdUdU-00025I-Lj; Fri, 23 Feb 2024 07:26:40 -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 1rdUcV-00089v-Vw for guix-patches@gnu.org; Fri, 23 Feb 2024 07:25:40 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdUcV-0000Z9-L7 for guix-patches@gnu.org; Fri, 23 Feb 2024 07:25:39 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rdUcs-0000qA-OM for guix-patches@gnu.org; Fri, 23 Feb 2024 07:26:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#69324] [PATCH] scripts: package: Make an argument for '--delete-generations' mandatory Resent-From: =?utf-8?b?VG9tw6FzIE9ydMOtbg==?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 23 Feb 2024 12:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 69324 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 69324@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.17086911163102 (code B ref -1); Fri, 23 Feb 2024 12:26:02 +0000 Received: (at submit) by debbugs.gnu.org; 23 Feb 2024 12:25:16 +0000 Received: from localhost ([127.0.0.1]:35473 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdUc6-0000ns-W5 for submit@debbugs.gnu.org; Fri, 23 Feb 2024 07:25:16 -0500 Received: from lists.gnu.org ([209.51.188.17]:51966) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdUKq-0008Qn-U2 for submit@debbugs.gnu.org; Fri, 23 Feb 2024 07:07:26 -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 1rdUKS-0005ze-Sx for guix-patches@gnu.org; Fri, 23 Feb 2024 07:07:00 -0500 Received: from mout-p-102.mailbox.org ([2001:67c:2050:0:465::102]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1rdUKN-0003z2-By for guix-patches@gnu.org; Fri, 23 Feb 2024 07:07:00 -0500 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4Th7yz1vLDz9smk for ; Fri, 23 Feb 2024 13:06:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1708689995; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=goDFmOhnrVlO6ep7DC3M9ouGOa0HDenPpXJtChv3UZA=; b=fUWEd6W9JiFlPUV5Jq8yraB3TNlH0i1geOPgIsJEevivfeIWr8w9xNPXehjQoPyWtMvs4O +vDG4ZylxKuGDKUdCDQJR9z+zykegzMeK3DaiFX1BlEBcsV3XbzDGO4udS7dgONWq8vvoA IdEOWBhqgE9RlZAIvY3BPXQnLZ+M1xwnQoV5t3EC2ZmoXz5fZMPZlVXYQaFK9GKGe/Vs9T kXHYcX75eqzi4hLbhQ/wRIsCBMXrzEajfoiD06bBznVQCTaw352qu987/Jjosk+xdI4wTO c+SsgSq6BfTVMr/bdKSqeOMQbBaLrcmc5KA6pf+M/J8yxExwgpeJ6WCMh2aA7g== Message-ID: Date: Fri, 23 Feb 2024 13:06:33 +0100 MIME-Version: 1.0 Content-Language: en-US X-MBO-RS-META: 5sgcwahikwzo1z3b3pmod9qik4pc6tnt X-MBO-RS-ID: df11a68019b56da78d8 Received-SPF: pass client-ip=2001:67c:2050:0:465::102; envelope-from=tomasortin@mailbox.org; helo=mout-p-102.mailbox.org X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: =?utf-8?b?VG9tw6FzIE9ydMOtbg==?= X-ACL-Warn: , =?utf-8?q?Tom=C3=A1s_Ort=C3=ADn_via_Guix-patches?= X-Patchwork-Original-From: =?utf-8?q?Tom=C3=A1s_Ort=C3=ADn_via_Guix-patches?= via From: =?utf-8?b?VG9tw6FzIE9ydMOtbg==?= Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/scripts/package.scm (delete-matching-generations): Ensure 'pattern' is always a string * guix/ui.scm (string->generations): Add '..' as syntax to delete all previous generations * guix/ui.scm (matching-generations): Handle case of empty pattern Recently, I've been bitten by mistyping 'guix package -d' without specifying any pattern. To my surprise, this results in all previous generations being deleted without any kind of confirmation. This is a quite easy mistake to make, so it seems like a footgun. This change makes it mandatory to specify an argument to 'guix package --delete-generations'. Complete deletion of old generations is now required to be explicit. In line with the existing pattern syntax, 'guix package --delete-generations ..' now deletes all previous generations. Change-Id: Ia51b33886a25661cea47aef56966cf1a3bfa7658 --- guix/scripts/package.scm | 4 +++- guix/ui.scm | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) (define (maybe-integer) (let ((x (string->number str))) (and (integer? x) @@ -1869,6 +1870,7 @@ (define (string->generations str) ((maybe-comma-separated-integers) => identity) + ((string= ".." str) '(>= 0)) ((string-match "^([0-9]+)\\.\\.([0-9]+)$" str) => (lambda (match) @@ -1987,7 +1989,10 @@ (define* (matching-generations str profile filter-by-duration) (else (raise - (formatted-message (G_ "invalid syntax: ~a~%") str))))) + (formatted-message (G_ "invalid syntax: ~a~%") + (if (string= "" str) + "pattern missing" + str)))))) (define (display-generation profile number) "Display a one-line summary of generation NUMBER of PROFILE." base-commit: aefc7428203203ae88c64cc4769113453c01a185 diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index a489e06e73..c4a096fafe 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -13,6 +13,7 @@ ;;; Copyright © 2022 Josselin Poiret ;;; Copyright © 2022 Arun Isaac ;;; Copyright © 2022 Antero Mejr +;;; Copyright © 2024 Tomás Ortín Fernández ;;; ;;; This file is part of GNU Guix. ;;; @@ -109,7 +110,8 @@ (define (delete-matching-generations store profile pattern) a string denoting a set of generations: the empty list means \"all generations but the current one\", a number designates a generation, and other patterns denote ranges as interpreted by 'matching-generations'." - (let ((current (generation-number profile))) + (let ((current (generation-number profile)) + (pattern (if pattern pattern ""))) ; ensure pattern is a string (cond ((not (file-exists? profile)) ; XXX: race condition (raise (condition (&profile-not-found-error (profile profile))))) diff --git a/guix/ui.scm b/guix/ui.scm index 962d291d2e..723f53946a 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -19,6 +19,7 @@ ;;; Copyright © 2018 Steve Sprang ;;; Copyright © 2022 Taiju HIGASHI ;;; Copyright © 2022 Liliana Marie Prikler +;;; Copyright © 2024 Tomás Ortín Fernández ;;; ;;; This file is part of GNU Guix. ;;; @@ -1850,7 +1851,7 @@ (define* (display-search-results matches port (define (string->generations str) "Return the list of generations matching a pattern in STR. This function -accepts the following patterns: \"1\", \"1,2,3\", \"1..9\", \"1..\", \"..9\"." +accepts the following patterns: \"1\", \"1,2,3\", \"1..9\", \"1..\", \"..9\", \"..\"."