From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nikita Karetnikov Subject: guix-package --roll-back Date: Fri, 21 Dec 2012 17:49:29 -0500 Message-ID: <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]:42062) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TmBPF-0006sq-E1 for bug-guix@gnu.org; Fri, 21 Dec 2012 17:49:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TmBPB-0006NZ-1Q for bug-guix@gnu.org; Fri, 21 Dec 2012 17:49:29 -0500 Received: from [2a01:7e00::f03c:91ff:fedf:181] (port=35971 helo=cooksoni.karetnikov.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TmBPA-0006M8-O9 for bug-guix@gnu.org; Fri, 21 Dec 2012 17:49:24 -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: bug-guix@gnu.org --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Hi, What do you think? (I'll send the output of 'git format-patch' when I implement the command-line part.) By the way, could you explain how the following works? (match (scandir (dirname profile) (cut regexp-exec %profile-rx <>)) ...) How does 'regexp-exec' get its second argument? (I know how 'cut' works, but I don't understand this particular snippet.) 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-16 17:38:40.000000000 +0000 +++ guix-package 2012-12-21 22:28:08.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. ;;; @@ -47,7 +48,8 @@ #:use-module (srfi srfi-37) #:use-module (distro) #:use-module (distro packages guile) =2D #:export (guix-package)) + #:export (guix-package) + #:export (roll-back)) =20 (define %store (open-connection)) @@ -87,13 +89,13 @@ (_ (error "unsupported manifest format" manifest)))) =20 +(define (profile-rx profile) + (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,25 @@ 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 + (string-append %current-profile "-" + (number->string (- current-profile-number 1)) + "-link"))) + (if (=3D current-profile-number 1) + (error "there are no other profiles.") + (delete-file %current-profile)) + + (symlink previous-profile %current-profile))) + ;;; ;;; Command-line options. --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQIcBAEBAgAGBQJQ1Od+AAoJEM+IQzI9IQ38370QAI311g9Z/C6lAzu0lyi1O4wS AJSiPIrZmuSMzaiQ2qyE/zmseNhTpDqYhVF5jGolvh1ceHD02MfIJzqXf9893MCq lesrkBDCYdbDXqI3D3eo49ReHNkPzBgxGZaFWa8cyjYq4rd+BGlSbp9FCkqlRGfQ vVebBbqKTj3DdbvKT60WQyexIVse7PH7yp4f4LS6Q0QqcD2drYThULh0agsE05nV pIXBye0oTespVZi5HXmUqUElfH5v1XZbYC+LVfFMvy5bx4M/QW5ZfotO2Xry/mb1 R9hT0fdoy50EoBjCKU1ZyKvaUCz/Vg+e5n4j+Rk6XZdoHRZLHIBBNAJBBToMdUdH lwn2xvMnpcLsk7gpOFk4o/jBVe5MHk9uO4BrRf8bPSn3Dcg9aEFK5QtVmd+d1FiN S3ptQRBpUE1BXBjxUhETKejo0c4J+pQGPjx83u3BX7e+8pi6GN65DCScgL4h1HSh EslECgnJL4qFnJ/tboxpnYSX/nJ63abeZ4kyTnwdCoNE2M5+3pqOBEqe9egy0DEt d0gMIPt1F4GLTUthS1o271r8wVOt+CoF0FtSgjO8YMmXjgrQBUov8Bg/QFqQApjM kg0NHddn+4lWF7KJ60Bs8wqK2+LY23QjiQCRjN2F/1l0N268+VFsarakafh90hes lJImUIT6gUKbGZBWa7Ez =93FU -----END PGP SIGNATURE----- --==-=-=--