guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] guix package: Add '--switch-generation' option.


From: Ludovic Courtès
Subject: Re: [PATCH] guix package: Add '--switch-generation' option.
Date: Tue, 07 Oct 2014 18:00:07 +0200
User-agent: Gnus/5.130011 (Ma Gnus v0.11) Emacs/24.3 (gnu/linux)

Alex Kost <address@hidden> skribis:

> Thanks, I've added a couple of tests.  The new patches are attached.

Thanks for the quick reply.

> Further improvements (documentation may be unsatisfactory)?

> From 9493421a4e094be6686ff6f28749946d491f81cd Mon Sep 17 00:00:00 2001
> From: Alex Kost <address@hidden>
> Date: Tue, 7 Oct 2014 11:50:44 +0400
> Subject: [PATCH 1/2] profiles: Add procedures for switching generations.
>
> * guix/scripts/package.scm (switch-to-previous-generation): Move to...
> * guix/profiles.scm: ... here. Use 'switch-to-generation'.
>   (relative-generation): New procedure.
>   (previous-generation-number): Use it.
>   (switch-to-generation): New procedure.

[...]

> +(define* (relative-generation profile shift #:optional
> +                              (current (generation-number profile)))
> +  "Return PROFILE's generation shifted from the CURRENT generation by SHIFT.
> +SHIFT is a positive or negative number.
> +Return #f if there is no such generation."

[...]

> +(define (switch-to-generation profile number)
> +  "Atomically switch PROFILE to the generation NUMBER."
> +  (let ((current (generation-number profile))
> +        (file    (generation-file-name profile number)))
> +    (cond ((not (file-exists? profile))
> +           (format (current-error-port)
> +                   (_ "profile '~a' does not exist~%")
> +                   profile))
> +          ((not (file-exists? file))
> +           (format (current-error-port)
> +                   (_ "generation ~a does not exist~%")
> +                   number))
> +          (else
> +           (format #t (_ "switching from generation ~a to ~a~%")
> +                   current number)
> +           (switch-symlinks profile file)))))

Could this procedure raise an exception instead of writing messages?
The reason is that I’d like UI code to remain in (guix scripts package),
in the Emacs code, and in guix-web, with (guix profiles) remaining
generic.

It’d be enough for me to just call ‘switch-symlinks’ and let it throw
‘system-error’ if something’s wrong.  The exception will be caught, the
user will see a “No such file” error, and ‘guix package’ with exit with
non-zero (this is done by ‘call-with-error-handling’.)

It’s less informative than what you did, though.  The other option would
be to define specific error condition types and throw them from here.

WDYT?

My apologies for being sloppy and not catching it earlier!

> From 0d89e5466741d8f80a1ac27502cb6cd600afb796 Mon Sep 17 00:00:00 2001
> From: Alex Kost <address@hidden>
> Date: Tue, 7 Oct 2014 12:05:06 +0400
> Subject: [PATCH 2/2] guix package: Add '--switch-generation' option.
>
> * guix/scripts/package.scm: Add '--switch-generation' option.
>   (guix-package): Adjust accordingly.
> * tests/guix-package.sh: Test it.
> * doc/guix.texi (Invoking guix package): Document it.

[...]

> +              (('switch-generation . pattern)
> +               (let* ((number (string->number pattern))
> +                      (number (and number
> +                                   (case (string-ref pattern 0)
> +                                     ((#\+ #\-)
> +                                      (relative-generation profile number))
> +                                     (else number)))))
> +                 (if number
> +                     (switch-to-generation profile number)
> +                     (format (current-error-port)
> +                             "Cannot switch to generation '~a'~%" pattern)))

Use ‘leave’ instead of ‘format’ here, with lower-case “cannot”.

The rest is perfect.

Thanks for your patience,
Ludo’.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]