Gracefully handle failure to install the current locale.

* guix/ui.scm (install-locale): New procedure.
* guix-build.in, guix-download.in, guix-gc.in, guix-import.in,
  guix-package.in: Use it instead of (setlocale LC_ALL "").
This commit is contained in:
Ludovic Courtès 2013-01-29 23:59:27 +01:00
parent bdcf35a6b2
commit 473b03b3c6
6 changed files with 16 additions and 5 deletions

View File

@ -220,7 +220,7 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n"))
name version) name version)
(leave (_ "~A: unknown package~%") name)))))) (leave (_ "~A: unknown package~%") name))))))
(setlocale LC_ALL "") (install-locale)
(textdomain "guix") (textdomain "guix")
(setvbuf (current-output-port) _IOLBF) (setvbuf (current-output-port) _IOLBF)
(setvbuf (current-error-port) _IOLBF) (setvbuf (current-error-port) _IOLBF)

View File

@ -134,7 +134,7 @@ and the hash of its contents.\n"))
(alist-cons 'argument arg result)) (alist-cons 'argument arg result))
%default-options)) %default-options))
(setlocale LC_ALL "") (install-locale)
(textdomain "guix") (textdomain "guix")
(setvbuf (current-output-port) _IOLBF) (setvbuf (current-output-port) _IOLBF)
(setvbuf (current-error-port) _IOLBF) (setvbuf (current-error-port) _IOLBF)

View File

@ -155,7 +155,7 @@ interpreted."
(alist-cons 'argument arg result)) (alist-cons 'argument arg result))
%default-options)) %default-options))
(setlocale LC_ALL "") (install-locale)
(textdomain "guix") (textdomain "guix")
(setvbuf (current-output-port) _IOLBF) (setvbuf (current-output-port) _IOLBF)
(setvbuf (current-error-port) _IOLBF) (setvbuf (current-error-port) _IOLBF)

View File

@ -115,7 +115,7 @@ Import and convert the Nix expression ATTRIBUTE of NIXPKGS.\n"))
(alist-cons 'argument arg result)) (alist-cons 'argument arg result))
%default-options)) %default-options))
(setlocale LC_ALL "") (install-locale)
(textdomain "guix") (textdomain "guix")
(setvbuf (current-output-port) _IOLBF) (setvbuf (current-output-port) _IOLBF)
(setvbuf (current-error-port) _IOLBF) (setvbuf (current-error-port) _IOLBF)

View File

@ -598,7 +598,7 @@ Install, remove, or upgrade PACKAGES in a single transaction.\n"))
#t)) #t))
(_ #f)))) (_ #f))))
(setlocale LC_ALL "") (install-locale)
(textdomain "guix") (textdomain "guix")
(setvbuf (current-output-port) _IOLBF) (setvbuf (current-output-port) _IOLBF)
(setvbuf (current-error-port) _IOLBF) (setvbuf (current-error-port) _IOLBF)

View File

@ -26,6 +26,7 @@
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:export (_ #:export (_
N_ N_
install-locale
leave leave
show-version-and-exit show-version-and-exit
show-bug-report-information show-bug-report-information
@ -45,6 +46,16 @@
(define _ (cut gettext <> %gettext-domain)) (define _ (cut gettext <> %gettext-domain))
(define N_ (cut ngettext <> <> <> %gettext-domain)) (define N_ (cut ngettext <> <> <> %gettext-domain))
(define (install-locale)
"Install the current locale settings."
(catch 'system-error
(lambda _
(setlocale LC_ALL ""))
(lambda args
(format (current-error-port)
(_ "warning: failed to install locale: ~a~%")
(strerror (system-error-errno args))))))
(define-syntax-rule (leave fmt args ...) (define-syntax-rule (leave fmt args ...)
"Format FMT and ARGS to the error port and exit." "Format FMT and ARGS to the error port and exit."
(begin (begin