unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Nikita Karetnikov <nikita@karetnikov.org>
Cc: bug-guix@gnu.org
Subject: Re: guix-package --roll-back
Date: Sun, 30 Dec 2012 16:30:46 +0100	[thread overview]
Message-ID: <87y5gf8sm1.fsf@gnu.org> (raw)
In-Reply-To: <874nj4sbfe.fsf@karetnikov.org> (Nikita Karetnikov's message of "Sat, 29 Dec 2012 18:09:52 -0500")

Hi!

Looks like a good start!

Nikita Karetnikov <nikita@karetnikov.org> 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 “file name”.

> +  (match:substring (regexp-exec (profile-rx profile)
> +                                (basename (readlink profile))) 1))

Instead write:

  (and=> (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 ‘profile’ parameter, as for the other functions.

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-number)))
> +         (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 ‘switchLink’
function in Nix for how to do it.

> +    (if (= 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 ‘roll-back’, just do like the other actions:

  (alist-cons 'roll-back #t result)

Then ‘roll-back’ can be called from ‘process-actions’, 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 ‘process-actions’
into several procedures, for readability.

Can you add a test case in ‘tests/guix-package.sh’?

Thanks!

Ludo’.

  parent reply	other threads:[~2012-12-30 15:31 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-21 22:49 guix-package --roll-back Nikita Karetnikov
2012-12-29 23:09 ` Nikita Karetnikov
2012-12-29 23:13   ` Andreas Enge
2012-12-30 15:30   ` Ludovic Courtès [this message]
2013-01-01 13:57     ` Nikita Karetnikov
2013-01-01 22:58       ` Ludovic Courtès
2013-01-03  5:42     ` Nikita Karetnikov
2013-01-03 14:41       ` Ludovic Courtès
2013-01-04 18:18         ` Nikita Karetnikov
2013-01-05 19:20           ` Ludovic Courtès
2013-01-09 19:04             ` Nikita Karetnikov
2013-01-10 15:01               ` Nikita Karetnikov
2013-01-10 22:26               ` Ludovic Courtès
2013-01-11  5:48                 ` Nikita Karetnikov
2013-01-11 13:39                   ` Ludovic Courtès
2013-01-12 21:03                     ` Nikita Karetnikov
2013-01-13 20:40                       ` Ludovic Courtès
2013-01-16 21:34                 ` Nikita Karetnikov
2013-01-17 21:47                   ` Ludovic Courtès
2013-01-21  5:50                     ` Nikita Karetnikov
2013-01-22 21:37                       ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y5gf8sm1.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=bug-guix@gnu.org \
    --cc=nikita@karetnikov.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).