Fixes <https://bugs.gnu.org/33603>.
Reported by Maxim Cournoyer <maxim.cournoyer@gmail.com>.
* guix/serialization.scm (port-conversion-strategy): New variable.
(restore-file): Parameterize it.
* tests/nar.scm ("restore-file with non-UTF8 locale"): New test.
* guix/serialization.scm (write-contents-from-port): New procedure.
(write-contents): Write in terms of 'write-contents-from-port'.
(filter/sort-directory-entries, write-file-tree): New procedures.
(write-file): Rewrite in terms of 'write-file-tree'.
* tests/nar.scm ("write-file-tree + restore-file"): New test.
Previously 'process-stderr' would always pass a bytevector of MAX-LEN to
then daemon in the %stderr-read case (i.e., 'import-paths'), instead of
LEN (where LEN <= MAX-LEN).
In practice the extra bytes didn't cause a protocol violation or
anything because they happen at the end of the stream, which typically
contains the canonical sexp of the signature, and the extra zeros were
just ignored.
* guix/serialization.scm (write-bytevector): Add optional 'l' parameter
and honor it.
* guix/store.scm (process-stderr): Pass LEN to 'write-bytevector'.
* guix/serialization.scm (write-bytevector): New procedure.
(write-string): Rewrite in terms of 'write-bytevector'.
* guix/store.scm (write-arg): Add 'bytevector' case.
(add-data-to-store): New procedure, from former 'add-text-to-store'.
(add-text-to-store): Rewrite in terms of 'add-data-to-store'.
* tests/store.scm ("add-data-to-store"): New test.
* guix/serialization.scm (read-maybe-utf8-string): Use
'set-port-encoding!' and 'set-port-conversion-strategy!' instead of
setting '%default-port-encoding' and
'%default-port-conversion-strategy'. This accounts for Guile commit
d574d96, which changes bytevector input ports to use ISO-8859-1.
* guix/serialization.scm (read-maybe-utf8-string): New procedure.
* guix/store.scm (process-stderr): Use it for the build log and errors.
* tests/store.scm ("current-build-output-port, UTF-8",
"current-build-output-port, UTF-8 + garbage"): New tests.
Fixes <http://bugs.gnu.org/19756>.
Reported by <sleep_walker@suse.cz>.
* guix/serialization.scm (currently-restored-file): New variable.
(get-bytevector-n*): New procedure.
(read-int, read-long-long, read-string, read-latin1-string,
read-contents): Use it instead of 'get-bytevector-n'.
(restore-file): Parameterize 'currently-restored-file' and set it.
* tests/nar.scm ("restore-file with incomplete input"): New test.
* guix/serialization.scm (read-latin1-string): Use 'get-bytevector-n'
instead of 'get-string-n'. Use 'list->string' etc. to convert the
bytevector to a string.