From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nikita Karetnikov Subject: Re: guix-package --roll-back Date: Sat, 29 Dec 2012 18:09:52 -0500 Message-ID: <874nj4sbfe.fsf@karetnikov.org> References: <871uejyq9z.fsf@karetnikov.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:53104) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tp5XM-0004uL-PT for bug-guix@gnu.org; Sat, 29 Dec 2012 18:09:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tp5XJ-0005um-No for bug-guix@gnu.org; Sat, 29 Dec 2012 18:09:52 -0500 Received: from [2a01:7e00::f03c:91ff:fedf:181] (port=35987 helo=cooksoni.karetnikov.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tp5XJ-0005tp-FM for bug-guix@gnu.org; Sat, 29 Dec 2012 18:09:49 -0500 In-Reply-To: <871uejyq9z.fsf@karetnikov.org> (Nikita Karetnikov's message of "Sat, 22 Dec 2012 02:49:28 +0400") List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org To: bug-guix@gnu.org --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Hi, I've slightly changed the 'roll-back' function. Now it prints an informative message. And it's also possible to call it from a command-line. # ./pre-inst-env guix-package --roll-back guix-package: switching from generation 6 to 5 The only problem I see is the following line. (error "there are no other profiles.") It will print an ugly backtrace if there are no other profiles. I'm trying to understand how to handle it in a non-ugly way. Any comments are appreciated. Nikita --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename=guix-package.diff Content-Transfer-Encoding: quoted-printable =2D-- guix-package-orig 2012-12-29 22:19:46.000000000 +0000 +++ guix-package 2012-12-29 22:42:41.000000000 +0000 @@ -13,6 +13,7 @@ !# ;;; Guix --- Nix package management from Guile. -*- coding: utf-8 = -*- ;;; Copyright (C) 2012 Ludovic Court=C3=A8s +;;; Copyright (C) 2012 Nikita Karetnikov ;;; ;;; This file is part of Guix. ;;; @@ -87,13 +88,14 @@ (_ (error "unsupported manifest format" manifest)))) =20 +(define (profile-rx profile) + "Return a regular expression that matches PROFILE's name and number." + (make-regexp (string-append "^" (regexp-quote (basename profile)) + "-([0-9]+)"))) + (define (latest-profile-number profile) "Return the identifying number of the latest generation of PROFILE. PROFILE is the name of the symlink to the current generation." =2D (define %profile-rx =2D (make-regexp (string-append "^" (regexp-quote (basename profile)) =2D "-([0-9]+)"))) =2D (define* (scandir name #:optional (select? (const #t)) (entry)) + (cut regexp-exec (profile-rx profile) <>)) (#f ; no profile directory 0) (() ; no profiles @@ -137,7 +139,7 @@ ((profiles ...) ; former profiles around (let ((numbers (map (compose string->number (cut match:substring <> 1) =2D (cut regexp-exec %profile-rx <>)) + (cut regexp-exec (profile-rx profile) <>= )) profiles))) (fold (lambda (number highest) (if (> number highest) @@ -177,6 +179,31 @@ packages) #:modules '((guix build union)))) =20 +(define (profile-number profile) + "Return PROFILE's number. PROFILE should be an absolute filename." + (match:substring (regexp-exec (profile-rx profile) + (basename (readlink profile))) 1)) + +(define (roll-back) + "Roll back to the previous profile." + (let* ((current-profile-number + (string->number (profile-number %current-profile))) + (previous-profile-number (number->string (1- current-profile-numb= er))) + (previous-profile + (string-append %current-profile "-" + previous-profile-number "-link"))) + + (define (switch) + "Switch to the previous generation." + (simple-format #t "guix-package: switching from generation ~a to ~a~= %" + current-profile-number previous-profile-number) + (delete-file %current-profile) + (symlink previous-profile %current-profile)) + + (if (=3D current-profile-number 1) + (error "there are no other profiles.") ; XXX: handle this error + (switch)))) + ;;; ;;; Command-line options. @@ -201,6 +228,8 @@ (display (_ " -n, --dry-run show what would be done without actually doing it= ")) (display (_ " + --roll-back roll back to the previous generation")) + (display (_ " -b, --bootstrap use the bootstrap Guile to build the profile")) (display (_ " --verbose produce verbose output")) @@ -236,6 +265,10 @@ (option '(#\r "remove") #t #f (lambda (opt name arg result) (alist-cons 'remove arg result))) + (option '("roll-back") #f #f + (lambda args + (roll-back) + (exit 0))) (option '(#\p "profile") #t #f (lambda (opt name arg result) (alist-cons 'profile arg --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQIcBAEBAgAGBQJQ33hWAAoJEM+IQzI9IQ38GUMP/AibicOaMDd4eqRjtOC06gCE bH/LkUwNkS6Is6+XLi2ejP1lFlPwYquNP9evf5FJOP3kP1hGtGL2pH/RS7lgyZ5B I3RTLWiSy5HQ/KBTTxGuUXTuG9RbbfqXFg1GpVPav7ltkoyGvFETrmT+NuRJiAP6 Dn/9cwOc/oK9HOxtqf895E/OnN5s7ak78xzy1fE2vcmIl3/iffBxbvsxcu6kyCXi veyKJxHSpwzJn57JE7UooYgSvz4mnZjAR6xXofBacbv8NzXSVwqDFY3JoBgFm0q8 VU6jQiHyhjZ0XkAk5b3Usz477jvYiR1lMKcP1eR2ZkolTG2ZmhGeQhXJWoJVaRoh +Pn9d/EeE9qkq2nwSRrb+Tiy+efbF3LCW7jnbj0+fBgSwraUnu2srEmPoKncv+uv I2MRXQAiGH1rVlzdzfoYDs3TzfEZKOMjwXsY1LKTM6SE1XS8La9/1PvT3Yc3iymW +lzmO2LAwXyh5u6Glo8bXZX3HxmiD0mhVRVJLOBWKBxLEqzOBBCfZPnr+4IeK4DG lErrUXu4jWPWSHIv8oNR9wtzFNVTi2+iw2lsyusiLBNAUI/1qgGxgXjice8tb9ZG LTEEYhsK1EhIPGHedIoGA2K0SPFfMTH/4mO7CL09iSKCGgC1aDS2xRj4jUV2ihhu 9NscocIwb3iYTIJo/i+E =7Yvk -----END PGP SIGNATURE----- --==-=-=--