From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nikita Karetnikov Subject: Re: guix-package --roll-back Date: Wed, 09 Jan 2013 14:04:28 -0500 Message-ID: <87fw2ai3e1.fsf@karetnikov.org> References: <871uejyq9z.fsf@karetnikov.org> <874nj4sbfe.fsf@karetnikov.org> <87y5gf8sm1.fsf@gnu.org> <87hamy4yaj.fsf@karetnikov.org> <87pq1m5nxy.fsf@gnu.org> <87obh43j7r.fsf@karetnikov.org> <87vcbbqvw1.fsf@gnu.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]:53971) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tt0wu-0001Br-Ef for bug-guix@gnu.org; Wed, 09 Jan 2013 14:04:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tt0wp-0000mR-4D for bug-guix@gnu.org; Wed, 09 Jan 2013 14:04:28 -0500 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: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: bug-guix@gnu.org --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, I'm attaching a slightly modified version. > Yeah, that=E2=80=99s expected. Basically, if you do > guix-package -p /dev/null --roll-back > it should fail with an error message saying that there is no previous > profile or something like that. 'profile-number' will fail if I call it with a bogus file name. For instance: scheme@(guile-user)> (profile-number "/foo/bar") ERROR: In procedure readlink: ERROR: In procedure readlink: No such file or directory What should I use to handle this error? Please show an example. The ones from the manual aren't helpful. I don't understand how to add a command-line option that should accept an optional argument. I commented out my attempts. 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 2013-01-09 18:28:03.000000000 +0000 +++ guix-package 2013-01-09 18:38:23.000000000 +0000 @@ -13,6 +13,7 @@ !# ;;; GNU Guix --- Functional package management for GNU ;;; Copyright =C2=A9 2012, 2013 Ludovic Court=C3=A8s +;;; Copyright =C2=A9 2013 Nikita Karetnikov ;;; ;;; This file is part of GNU Guix. ;;; @@ -39,6 +40,7 @@ #:use-module (ice-9 ftw) #:use-module (ice-9 format) #:use-module (ice-9 match) + #:use-module (ice-9 optargs) #:use-module (ice-9 regex) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) @@ -88,13 +90,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 @@ -138,7 +141,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) @@ -178,6 +181,41 @@ packages) #:modules '((guix build union)))) =20 +(define (profile-number profile) + "Return PROFILE's number. An absolute file name must be used." + (and=3D> (regexp-exec (profile-rx profile) + (basename (readlink profile))) + (cut match:substring <> 1))) + +(define* (roll-back #:optional profile) + "Roll back to the previous profile." + (let* ((current-profile-number + (string->number (profile-number (or profile %current-profile)))) + (previous-profile-number (number->string (1- current-profile-numb= er))) + (previous-profile + (string-append (or profile %current-profile) "-" + previous-profile-number "-link")) + (manifest (string-append previous-profile "/manifest"))) + + (define (switch-link) + ;; Switch to the previous generation. + (let ((tmp-profile (string-append (dirname (or profile %current-prof= ile)) + "/tmp-" + (basename previous-profile)))) + + (simple-format #t "guix-package: switching from generation ~a to ~= a~%" + current-profile-number previous-profile-number) + (symlink previous-profile tmp-profile) + (rename-file tmp-profile (or profile %current-profile)))) + + (if (equal? (map (cut file-exists? <>) + (list previous-profile manifest)) + '(#t #t)) + (switch-link) + (leave (_ (string-append + "guix-package: previous profile doesn't exist; " + "not rolling back~%")))))) + ;;; ;;; Command-line options. @@ -202,6 +240,8 @@ (display (_ " -n, --dry-run show what would be done without actually doing it= ")) (display (_ " + --roll-back roll back to the previous generation")) + (display (_ " --bootstrap use the bootstrap Guile to build the profile")) (display (_ " --verbose produce verbose output")) @@ -236,6 +276,25 @@ (option '(#\r "remove") #t #f (lambda (opt name arg result) (alist-cons 'remove arg result))) + + ;; (option '("roll-back") #f #t + ;; (lambda (opt name arg result) + ;; (roll-back (or arg #f)) + ;; (exit 0))) + + ;; (lambda (opt name arg result) + ;; (alist-cons 'roll-back arg result))) + + ;; (lambda (opt name arg result) + ;; (cons `(query roll-back ,(or arg #f)) + ;; result))) + + ;; (lambda (opt name arg result) + ;; (alist-cons 'roll-back (or arg #f) result))) + + ;; (lambda (opt name arg result) + ;; (alist-cons 'roll-back (or arg "") result))) + (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) iQIcBAEBAgAGBQJQ7b9bAAoJEM+IQzI9IQ38kI8P/3OONACGqgGiUqMrnX9VPGjt 6kTBdtWPBUW5MEJaqAvT1+xh/jCueunUDKOy/UIGKj8dOuq25+MRbPb6N9D1ApTA aKSmBpXsKva41xCYChwkPgeD5+jfHGoELFttikGPVvMmglO5uvlae8THabYqZcJZ u0LL4LUWnTTjkkovvKWuUmfbR6jNjjfex1V9F9bzARzMeMHTF1FnaRpY+Oh+Sgma 9PW9rvEsl8OFiNf84AkmxL9RtBt9dQnktjE/i6PtShiTHJm9SK53bzQdBYzbo8Ht dW3mAmRWiQ1Me8+ROKDS9stVQxpi0ynTxnjldrERFAQvxBb6bUeKgDmE70RGGpAs 9kR2uv+pVvydAncpY7cnJJNwuwIko9xI2miyTjIAxz1cnFUWdkcveuwhvTvRMtBS Ztz1m3l0+4sMUH8dqXX7H0uB5YJrdACGMLYEAFzCR8T/U5tNAota3PvcrST3qVdl 2HFblxbxFG1HcVi+JwZdwc+ekvSE6m+xMPRHgkAQ9dqPBTvcEhV5qboxp3HlXGLF CA3FjYKRTPmgIlGb2TgTpA2c+dKncQIbRS6RnDW2coirdJR2er7lDkNM8g56hxBv SbBV9whLQAHS2DKT5Kp/lYO2MbMoVZiudrZAIz7k/mim+pXU1tQTGzj8Lh7x1Rau 9Yho66ug1f9AlUkGOn0f =7bf1 -----END PGP SIGNATURE----- --==-=-=--