diff options
author | Mathieu Othacehe <othacehe@gnu.org> | 2020-08-26 18:35:14 +0200 |
---|---|---|
committer | Mathieu Othacehe <othacehe@gnu.org> | 2020-08-26 18:35:14 +0200 |
commit | 17dddeeee560527a8f30d37761949d658056cb09 (patch) | |
tree | 15b0b19c55787f556eb9b42c28d173bddc5435db /guix/ssh.scm | |
parent | 331a09654eb7e9f6212b7e8469077fa7393e8b11 (diff) | |
parent | 6a9581741e4ee81226aeb2f1c997df76670a6aab (diff) | |
download | guix-patches-17dddeeee560527a8f30d37761949d658056cb09.tar guix-patches-17dddeeee560527a8f30d37761949d658056cb09.tar.gz |
Merge remote-tracking branch 'origin/master' into core-updates
Diffstat (limited to 'guix/ssh.scm')
-rw-r--r-- | guix/ssh.scm | 99 |
1 files changed, 50 insertions, 49 deletions
diff --git a/guix/ssh.scm b/guix/ssh.scm index b9e6ff8564..24db171374 100644 --- a/guix/ssh.scm +++ b/guix/ssh.scm @@ -20,7 +20,7 @@ #:use-module (guix store) #:use-module (guix inferior) #:use-module (guix i18n) - #:use-module ((guix utils) #:select (&fix-hint)) + #:use-module ((guix diagnostics) #:select (&fix-hint formatted-message)) #:use-module (gcrypt pk-crypto) #:use-module (ssh session) #:use-module (ssh auth) @@ -88,14 +88,12 @@ actual key does not match." ;; provided its Ed25519 key when we where expecting its RSA key. XXX: ;; Guile-SSH 0.10.1 doesn't know about ed25519 keys and 'get-key-type' ;; returns #f in that case. - (raise (condition - (&message - (message (format #f (G_ "server at '~a' returned host key \ + (raise (formatted-message (G_ "server at '~a' returned host key \ '~a' of type '~a' instead of '~a' of type '~a'~%") (session-get session 'host) (public-key->string server) (get-key-type server) - key type)))))))) + key type))))) (define* (open-ssh-session host #:key user port identity host-key @@ -148,12 +146,10 @@ Throw an error on failure." (match (authenticate-server session) ('ok #f) (reason - (raise (condition - (&message - (message (format #f (G_ "failed to authenticate \ + (raise (formatted-message (G_ "failed to authenticate \ server at '~a': ~a") (session-get session 'host) - reason)))))))) + reason))))) ;; Use public key authentication, via the SSH agent if it's available. (match (userauth-public-key/auto! session) @@ -173,10 +169,8 @@ server at '~a': ~a") host (get-error session))))))))))) (x ;; Connection failed or timeout expired. - (raise (condition - (&message - (message (format #f (G_ "SSH connection to '~a' failed: ~a~%") - host (get-error session)))))))))) + (raise (formatted-message (G_ "SSH connection to '~a' failed: ~a~%") + host (get-error session))))))) (define* (remote-inferior session #:optional become-command) "Return a remote inferior for the given SESSION. If BECOME-COMMAND is @@ -187,11 +181,9 @@ given, use that to invoke the remote Guile REPL." (when (eof-object? (peek-char pipe)) (let ((status (channel-get-exit-status pipe))) (close-port pipe) - (raise (condition - (&message - (message (format #f (G_ "remote command '~{~a~^ ~}' failed \ + (raise (formatted-message (G_ "remote command '~{~a~^ ~}' failed \ with status ~a") - repl-command status))))))) + repl-command status)))) (port->inferior pipe))) (define* (inferior-remote-eval exp session #:optional become-command) @@ -291,6 +283,11 @@ can be written." ;; consumed. (define import `(begin + (eval-when (load expand eval) + (unless (resolve-module '(guix) #:ensure #f) + (write `(module-error)) + (exit 7))) + (use-modules (guix) (srfi srfi-34) (rnrs io ports) (rnrs bytevectors)) @@ -313,6 +310,9 @@ can be written." (consume-input (current-input-port)) (list 'protocol-error (nix-protocol-error-message c)))) (with-store store + (write '(importing)) ;we're ready + (force-output) + (setvbuf (current-input-port) 'none) (import-paths store (current-input-port)) '(success)))) @@ -409,24 +409,11 @@ to the system ACL file if it has not yet been authorized." "Send the subset of FILES from LOCAL (a local store) that's missing to REMOTE, a remote store. When RECURSIVE? is true, send the closure of FILES. Return the list of store items actually sent." - (define (inferior-remote-eval* exp session) - (guard (c ((inferior-exception? c) - (match (inferior-exception-arguments c) - (('quit 7) - (report-module-error (remote-store-host remote))) - (_ - (report-inferior-exception c (remote-store-host remote)))))) - (inferior-remote-eval exp session))) - ;; Compute the subset of FILES missing on SESSION and send them. (let* ((files (if recursive? (requisites local files) files)) (session (channel-get-session (store-connection-socket remote))) - (missing (inferior-remote-eval* + (missing (inferior-remote-eval `(begin - (eval-when (load expand eval) - (unless (resolve-module '(guix) #:ensure #f) - (exit 7))) - (use-modules (guix) (srfi srfi-1) (srfi srfi-26)) @@ -439,6 +426,13 @@ Return the list of store items actually sent." (path-info-nar-size (query-path-info local item))) missing)) (port (store-import-channel session))) + ;; Make sure everything alright on the remote side. + (match (read port) + (('importing) + #t) + (sexp + (handle-import/export-channel-error sexp remote))) + (format log-port (N_ "sending ~a store item (~h MiB) to '~a'...~%" "sending ~a store items (~h MiB) to '~a'...~%" count) count @@ -513,6 +507,29 @@ to the length of FILES.)" (&message (message (format #f fmt args ...)))))))) +(define (handle-import/export-channel-error sexp remote) + "Report an error corresponding to SEXP, the EOF object or an sexp read from +REMOTE." + (match sexp + ((? eof-object?) + (report-guile-error (remote-store-host remote))) + (('module-error . _) + (report-module-error (remote-store-host remote))) + (('connection-error file code . _) + (raise-error (G_ "failed to connect to '~A' on remote host '~A': ~a") + file (remote-store-host remote) (strerror code))) + (('invalid-items items . _) + (raise-error (N_ "no such item on remote host '~A':~{ ~a~}" + "no such items on remote host '~A':~{ ~a~}" + (length items)) + (remote-store-host remote) items)) + (('protocol-error status message . _) + (raise-error (G_ "protocol error on remote host '~A': ~a") + (remote-store-host remote) message)) + (_ + (raise-error (G_ "failed to retrieve store items from '~a'") + (remote-store-host remote))))) + (define* (retrieve-files* files remote #:key recursive? (log-port (current-error-port)) (import (const #f))) @@ -533,24 +550,8 @@ from REMOTE. When RECURSIVE? is true, retrieve the closure of FILES." (import port)) (lambda () (close-port port)))) - ((? eof-object?) - (report-guile-error (remote-store-host remote))) - (('module-error . _) - (report-module-error (remote-store-host remote))) - (('connection-error file code . _) - (raise-error (G_ "failed to connect to '~A' on remote host '~A': ~a") - file (remote-store-host remote) (strerror code))) - (('invalid-items items . _) - (raise-error (N_ "no such item on remote host '~A':~{ ~a~}" - "no such items on remote host '~A':~{ ~a~}" - (length items)) - (remote-store-host remote) items)) - (('protocol-error status message . _) - (raise-error (G_ "protocol error on remote host '~A': ~a") - (remote-store-host remote) message)) - (_ - (raise-error (G_ "failed to retrieve store items from '~a'") - (remote-store-host remote)))))) + (sexp + (handle-import/export-channel-error sexp remote))))) (define* (retrieve-files local files remote #:key recursive? (log-port (current-error-port))) |