From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: guix-package --roll-back Date: Sun, 30 Dec 2012 16:30:46 +0100 Message-ID: <87y5gf8sm1.fsf@gnu.org> References: <871uejyq9z.fsf@karetnikov.org> <874nj4sbfe.fsf@karetnikov.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:41211) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TpKqw-0006g3-8w for bug-guix@gnu.org; Sun, 30 Dec 2012 10:31:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TpKqe-0001Y4-Eb for bug-guix@gnu.org; Sun, 30 Dec 2012 10:31:06 -0500 Received: from mail4-relais-sop.national.inria.fr ([192.134.164.105]:56310) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TpKqe-0001Xq-8Y for bug-guix@gnu.org; Sun, 30 Dec 2012 10:30:48 -0500 In-Reply-To: <874nj4sbfe.fsf@karetnikov.org> (Nikita Karetnikov's message of "Sat, 29 Dec 2012 18:09:52 -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: Nikita Karetnikov Cc: bug-guix@gnu.org Hi! Looks like a good start! Nikita Karetnikov skribis: > +(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]+)"))) OK. > +(define (profile-number profile) > + "Return PROFILE's number. PROFILE should be an absolute filename." Two spaces after period. Please write =E2=80=9Cfile name=E2=80=9D. > + (match:substring (regexp-exec (profile-rx profile) > + (basename (readlink profile))) 1)) Instead write: (and=3D> (regexp-exec ...) (cut match:substring <> 1)) So that the thing returns #f when there are is no associated profile number. OTOH, does that ever occur? > +(define (roll-back) > + "Roll back to the previous profile." Please add a =E2=80=98profile=E2=80=99 parameter, as for the other function= s. It should be possible to run: $ guix-package -p foo --roll-back > + (let* ((current-profile-number > + (string->number (profile-number %current-profile))) > + (previous-profile-number (number->string (1- current-profile-nu= mber))) > + (previous-profile > + (string-append %current-profile "-" > + previous-profile-number "-link"))) > + > + (define (switch) > + "Switch to the previous generation." For internal procedures, just use regular comments instead of docstrings. > + (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)) It should be based on rename(2) to be atomic. See the =E2=80=98switchLink= =E2=80=99 function in Nix for how to do it. > + (if (=3D current-profile-number 1) > + (error "there are no other profiles.") ; XXX: handle this error Here you you use (leave (_ "no other profiles; not rolling back")). > + (option '("roll-back") #f #f > + (lambda args > + (roll-back) > + (exit 0))) Instead of calling =E2=80=98roll-back=E2=80=99, just do like the other acti= ons: (alist-cons 'roll-back #t result) Then =E2=80=98roll-back=E2=80=99 can be called from =E2=80=98process-action= s=E2=80=99, with the right profile passed as an argument. Perhaps other actions should be ignored when rolling back. At any rate, you may need to split =E2=80=98process-act= ions=E2=80=99 into several procedures, for readability. Can you add a test case in =E2=80=98tests/guix-package.sh=E2=80=99? Thanks! Ludo=E2=80=99.