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

Previous Next

Package: guix-patches;

Reported by: Tomás Ortín <tomasortin <at> mailbox.org>

Date: Fri, 23 Feb 2024 12:26:02 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 69324 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#69324; Package guix-patches. (Fri, 23 Feb 2024 12:26:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tomás Ortín <tomasortin <at> mailbox.org>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Fri, 23 Feb 2024 12:26:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tomás Ortín <tomasortin <at> mailbox.org>
To: guix-patches <at> gnu.org
Subject: [PATCH] scripts: package: Make an argument for '--delete-generations'
 mandatory
Date: Fri, 23 Feb 2024 13:06:33 +0100
* 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 <at> jpoiret.xyz>
 ;;; Copyright © 2022 Arun Isaac <arunisaac <at> systemreboot.net>
 ;;; Copyright © 2022 Antero Mejr <antero <at> mailbox.org>
+;;; Copyright © 2024 Tomás Ortín Fernández <tomasortin <at> mailbox.org>
 ;;;
 ;;; 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 <at> stevesprang.com>
 ;;; Copyright © 2022 Taiju HIGASHI <higashi <at> taiju.info>
 ;;; Copyright © 2022 Liliana Marie Prikler <liliana.prikler <at> gmail.com>
+;;; Copyright © 2024 Tomás Ortín Fernández <tomasortin <at> mailbox.org>
 ;;;
 ;;; 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





Information forwarded to guix-patches <at> gnu.org:
bug#69324; Package guix-patches. (Wed, 13 Nov 2024 12:34:02 GMT) Full text and rfc822 format available.

Message #8 received at 69324 <at> debbugs.gnu.org (full text, mbox):

From: Tomás Ortín <tomasortin <at> mailbox.org>
To: 69324 <at> debbugs.gnu.org
Date: Wed, 13 Nov 2024 14:33:23 +0200
I see the patch has not been merged, is the reason the implementation or 
the UX change itself?




This bug report was last modified 246 days ago.

Previous Next


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