From d9307267b3b4a87391e33daacef162745f057c3d Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 27 Jan 2013 17:18:55 +0100 Subject: guix-package: When rolling back to nothingness, point to the empty profile. Suggested by Andreas Enge at . * guix-package.in (roll-back): Check whether PROFILE is valid using `file-exists?'. When NUMBER is zero, just emit a notice. When PREVIOUS-NUMBER is zero and PREVIOUS-PROFILE does not exist, build the empty profile, and link to it. * tests/guix-package.sh: Add tests. * doc/guix.texi (Invoking guix-package): Document the new behavior. --- guix-package.in | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'guix-package.in') diff --git a/guix-package.in b/guix-package.in index 37a1df0c11..caddae1392 100644 --- a/guix-package.in +++ b/guix-package.in @@ -220,14 +220,26 @@ all of PACKAGES, a list of name/version/output/path tuples." (symlink previous-profile pivot) (rename-file pivot profile))) - (cond ((zero? number) + (cond ((not (file-exists? profile)) ; invalid profile (format (current-error-port) - (_ "error: `~a' is not a valid profile~%") + (_ "error: profile `~a' does not exist~%") profile)) - ((or (zero? previous-number) + ((zero? number) ; empty profile + (format (current-error-port) + (_ "nothing to do: already at the empty profile~%"))) + ((or (zero? previous-number) ; going to emptiness (not (file-exists? previous-profile))) - (leave (_ "error: no previous profile; not rolling back~%"))) - (else (switch-link))))) + (let*-values (((drv-path drv) + (profile-derivation (%store) '())) + ((prof) + (derivation-output-path + (assoc-ref (derivation-outputs drv) "out")))) + (when (not (build-derivations (%store) (list drv-path))) + (leave (_ "failed to build the empty profile~%"))) + + (symlink prof previous-profile) + (switch-link))) + (else (switch-link))))) ; anything else ;;; -- cgit v1.2.3