unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#69324] [PATCH] scripts: package: Make an argument for '--delete-generations' mandatory
@ 2024-02-23 12:06 Tomás Ortín via Guix-patches via
  0 siblings, 0 replies; only message in thread
From: Tomás Ortín via Guix-patches via @ 2024-02-23 12:06 UTC (permalink / raw)
  To: 69324

* 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@jpoiret.xyz>
  ;;; Copyright © 2022 Arun Isaac <arunisaac@systemreboot.net>
  ;;; Copyright © 2022 Antero Mejr <antero@mailbox.org>
+;;; Copyright © 2024 Tomás Ortín Fernández <tomasortin@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@stevesprang.com>
  ;;; Copyright © 2022 Taiju HIGASHI <higashi@taiju.info>
  ;;; Copyright © 2022 Liliana Marie Prikler <liliana.prikler@gmail.com>
+;;; Copyright © 2024 Tomás Ortín Fernández <tomasortin@mailbox.org>
  ;;;
  ;;; This file is part of GNU Guix.
  ;;;
@@ -1850,7 +1851,7 @@ (define* (display-search-results matches port
  \f
  (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





^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-23 12:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-23 12:06 [bug#69324] [PATCH] scripts: package: Make an argument for '--delete-generations' mandatory Tomás Ortín via Guix-patches via

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).