A client closing the connection while reading from a /nar URL would
leave an open file descriptor in the server. This patch fixes it.
* guix/scripts/publish.scm (swallow-EPIPE): New macro.
(http-write): Use it around 'write-file' call.
* guix/scripts/publish.scm (narinfo-string): Catch 'system-error' around
'load-derivation' call; return BASE-INFO upon ENOENT. This allows us
to return the narinfo even if DERIVER is missing. Before that, the
exception would be uncaught, leading to 500 Internal Error on the
client side.
Previously, before replying to a /nar/* request, 'guix publish' would first
build up the whole nar into memory (as a consequence of
<http://bugs.gnu.org/21093>), which obviously doesn't scale.
* guix/scripts/publish.scm (render-nar): Return STORE-PATH instead of a
procedure that calls 'write-file'.
(sans-content-length): New procedure.
(http-write): For 'x-nix-archive', don't call '%http-write'. Instead, call
'write-file' right from here, using BODY as the file name.
* guix/scripts/publish.scm (%http-write): New variable.
(http-write): New procedure.
(concurrent-http-server): New variable.
(run-publish-server): Use it.
* guix/scripts/publish.scm (show-help, %options): Add --listen.
(getaddrinfo*): New procedure.
(%default-options): Add 'address'.
(open-server-socket): Replace 'addr' and 'port' with 'address', a
sockaddr.
(guix-publish): Adjust accordingly. Augment "publishing" message with
the actual address.
* doc/guix.texi (Invoking guix publish): Document it.
* guix/scripts/publish.scm (show-help): Add --user.
(%options): Likewise.
(run-publish-server): Change 'port' parameter to 'socket'. Pass
#:socket instead of #:addr and #:port to 'run-server'. Update caller
accordingly.
(open-server-socket, gather-user-privileges): New procedures.
(guix-publish): Use them. Force %PRIVATE-KEY and %PUBLIC-KEY early
on. Warn when running as root.
* doc/guix.texi (Invoking guix publish): Document --user.