GNU bug report logs - #69324
[PATCH] scripts: package: Make an argument for '--delete-generations' mandatory

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guix-patches; Reported by: Tomás Ortín <tomasortin@HIDDEN>; Keywords: patch; dated Fri, 23 Feb 2024 12:26:02 UTC; Maintainer for guix-patches is guix-patches@HIDDEN.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 23 Feb 2024 12:25:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Feb 23 07:25:16 2024
Received: from localhost ([127.0.0.1]:35473 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rdUc6-0000ns-W5
	for submit <at> 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 <tomasortin@HIDDEN>) id 1rdUKq-0008Qn-U2
 for submit <at> 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 <tomasortin@HIDDEN>)
 id 1rdUKS-0005ze-Sx
 for guix-patches@HIDDEN; 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 <tomasortin@HIDDEN>)
 id 1rdUKN-0003z2-By
 for guix-patches@HIDDEN; 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 <guix-patches@HIDDEN>; 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: <cbff10f8-5eaa-b46a-851c-7de79f8fec23@HIDDEN>
Date: Fri, 23 Feb 2024 13:06:33 +0100
MIME-Version: 1.0
Content-Language: en-US
From: =?UTF-8?B?VG9tw6FzIE9ydMOtbg==?= <tomasortin@HIDDEN>
Subject: [PATCH] scripts: package: Make an argument for '--delete-generations'
 mandatory
To: guix-patches@HIDDEN
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-MBO-RS-META: 5sgcwahikwzo1z3b3pmod9qik4pc6tnt
X-MBO-RS-ID: df11a68019b56da78d8
Received-SPF: pass client-ip=2001:67c:2050:0:465::102;
 envelope-from=tomasortin@HIDDEN; 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-Spam-Score: -1.3 (-)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

* 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(-)

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 <dev@HIDDEN>
  ;;; Copyright © 2022 Arun Isaac <arunisaac@HIDDEN>
  ;;; Copyright © 2022 Antero Mejr <antero@HIDDEN>
+;;; Copyright © 2024 Tomás Ortín Fernández <tomasortin@HIDDEN>
  ;;;
  ;;; 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 <scs@HIDDEN>
  ;;; Copyright © 2022 Taiju HIGASHI <higashi@HIDDEN>
  ;;; Copyright © 2022 Liliana Marie Prikler <liliana.prikler@HIDDEN>
+;;; Copyright © 2024 Tomás Ortín Fernández <tomasortin@HIDDEN>
  ;;;
  ;;; 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\", \"..\"."
    (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
-- 
2.41.0





Acknowledgement sent to Tomás Ortín <tomasortin@HIDDEN>:
New bug report received and forwarded. Copy sent to guix-patches@HIDDEN. Full text available.
Report forwarded to guix-patches@HIDDEN:
bug#69324; Package guix-patches. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 23 Feb 2024 12:30:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.