guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

04/06: guix package: Never remove the current generation and warn about


From: Ludovic Courtès
Subject: 04/06: guix package: Never remove the current generation and warn about it.
Date: Mon, 06 Apr 2015 19:56:10 +0000

civodul pushed a commit to branch master
in repository guix.

commit d26eb84d140af8d2119509d7da440b4f035608c5
Author: Ludovic Courtès <address@hidden>
Date:   Mon Apr 6 21:26:12 2015 +0200

    guix package: Never remove the current generation and warn about it.
    
    Fixes <http://bugs.gnu.org/19978>.
    Reported by address@hidden (Taylan Ulrich Bayırlı/Kammer).
    
    * guix/scripts/package.scm (delete-matching-generations): Warn when
      CURRENT is in NUMBERS, and always remove it before calling
      'delete-generations'.
    * tests/guix-package.sh: Add --switch-generation=2 invocation before
      --delete-generations=3 invocation.
      Add --delete-generations=1.. test case.
---
 guix/scripts/package.scm |   13 ++++++++++---
 tests/guix-package.sh    |   11 +++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 7074243..3a7afb7 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -254,9 +254,16 @@ denote ranges as interpreted by 'matching-derivations'."
                                  #:duration-relation >)
            =>
            (lambda (numbers)
-             (if (null-list? numbers)
-                 (exit 1)
-                 (delete-generations (%store) profile numbers))))
+             (when (memv current numbers)
+               (warning (_ "not removing generation ~a, which is current~%")
+                        current))
+
+             ;; Make sure we don't inadvertently remove the current
+             ;; generation.
+             (let ((numbers (delv current numbers)))
+               (if (null-list? numbers)
+                   (exit 1)
+                   (delete-generations (%store) profile numbers)))))
           (else
            (leave (_ "invalid syntax: ~a~%") pattern)))))
 
diff --git a/tests/guix-package.sh b/tests/guix-package.sh
index 94cf927..a4c0425 100644
--- a/tests/guix-package.sh
+++ b/tests/guix-package.sh
@@ -161,6 +161,9 @@ then
     guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap
     guix package --search-paths -p "$profile" | grep LIBRARY_PATH
 
+    # Roll back so we can delete #3 below.
+    guix package -p "$profile" --switch-generation=2
+
     # Delete the third generation and check that it was actually deleted.
     guix package -p "$profile" --delete-generations=3
     test -z "`guix package -p "$profile" -l 3`"
@@ -212,6 +215,14 @@ if guix package -p "$profile" --delete-generations=12m;
 then false; else true; fi
 test "`readlink_base "$profile"`" = "$generation"
 
+# The following command should not delete the current generation, even though
+# it matches the given pattern (see <http://bugs.gnu.org/19978>.)  And since
+# there's nothing else to delete, it should just fail.
+guix package --list-generations -p "$profile"
+if guix package --bootstrap -p "$profile" --delete-generations=1..
+then false; else true; fi
+test "`readlink_base "$profile"`" = "$generation"
+
 # Make sure $profile is a GC root at this point.
 real_profile="`readlink -f "$profile"`"
 if guix gc -d "$real_profile"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]