2015-03-17 14:21:31 +00:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
|
|
|
|
;;; Copyright © 2015 David Thompson <davet@gnu.org>
|
2020-10-20 20:32:02 +00:00
|
|
|
|
;;; Copyright © 2020 by Amar M. Singh <nly@disroot.org>
|
2021-05-11 13:01:00 +00:00
|
|
|
|
;;; Copyright © 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
|
2015-03-17 14:21:31 +00:00
|
|
|
|
;;;
|
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
;;; your option) any later version.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
|
;;;
|
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
2016-01-21 22:45:52 +00:00
|
|
|
|
;; Avoid interference.
|
|
|
|
|
(unsetenv "http_proxy")
|
|
|
|
|
|
2015-03-17 14:21:31 +00:00
|
|
|
|
(define-module (test-publish)
|
|
|
|
|
#:use-module (guix scripts publish)
|
|
|
|
|
#:use-module (guix tests)
|
|
|
|
|
#:use-module (guix config)
|
|
|
|
|
#:use-module (guix utils)
|
Switch to Guile-Gcrypt.
This removes (guix hash) and (guix pk-crypto), which now live as part of
Guile-Gcrypt (version 0.1.0.)
* guix/gcrypt.scm, guix/hash.scm, guix/pk-crypto.scm,
tests/hash.scm, tests/pk-crypto.scm: Remove.
* configure.ac: Test for Guile-Gcrypt. Remove LIBGCRYPT and
LIBGCRYPT_LIBDIR assignments.
* m4/guix.m4 (GUIX_ASSERT_LIBGCRYPT_USABLE): Remove.
* README: Add Guile-Gcrypt to the dependencies; move libgcrypt as
"required unless --disable-daemon".
* doc/guix.texi (Requirements): Likewise.
* gnu/packages/bash.scm, guix/derivations.scm, guix/docker.scm,
guix/git.scm, guix/http-client.scm, guix/import/cpan.scm,
guix/import/cran.scm, guix/import/crate.scm, guix/import/elpa.scm,
guix/import/gnu.scm, guix/import/hackage.scm,
guix/import/texlive.scm, guix/import/utils.scm, guix/nar.scm,
guix/pki.scm, guix/scripts/archive.scm,
guix/scripts/authenticate.scm, guix/scripts/download.scm,
guix/scripts/hash.scm, guix/scripts/pack.scm,
guix/scripts/publish.scm, guix/scripts/refresh.scm,
guix/scripts/substitute.scm, guix/store.scm,
guix/store/deduplication.scm, guix/tests.scm, tests/base32.scm,
tests/builders.scm, tests/challenge.scm, tests/cpan.scm,
tests/crate.scm, tests/derivations.scm, tests/gem.scm,
tests/nar.scm, tests/opam.scm, tests/pki.scm,
tests/publish.scm, tests/pypi.scm, tests/store-deduplication.scm,
tests/store.scm, tests/substitute.scm: Adjust imports.
* gnu/system/vm.scm: Likewise.
(guile-sqlite3&co): Rename to...
(gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT.
(expression->derivation-in-linux-vm)[config]: Remove.
(iso9660-image)[config]: Remove.
(qemu-image)[config]: Remove.
(system-docker-image)[config]: Remove.
* guix/scripts/pack.scm: Adjust imports.
(guile-sqlite3&co): Rename to...
(gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT.
(self-contained-tarball)[build]: Call 'make-config.scm' without
#:libgcrypt argument.
(squashfs-image)[libgcrypt]: Remove.
[build]: Call 'make-config.scm' without #:libgcrypt.
(docker-image)[config, json]: Remove.
[build]: Add GUILE-GCRYPT to the extensions Remove (guix config) from
the imported modules.
* guix/self.scm (specification->package): Remove "libgcrypt", add
"guile-gcrypt".
(compiled-guix): Remove #:libgcrypt.
[guile-gcrypt]: New variable.
[dependencies]: Add it.
[*core-modules*]: Remove #:libgcrypt from 'make-config.scm' call.
Add #:extensions.
[*config*]: Remove #:libgcrypt from 'make-config.scm' call.
(%dependency-variables): Remove %libgcrypt.
(make-config.scm): Remove #:libgcrypt.
* build-aux/build-self.scm (guile-gcrypt): New variable.
(make-config.scm): Remove #:libgcrypt.
(build-program)[fake-gcrypt-hash]: New variable.
Add (gcrypt hash) to the imported modules. Adjust load path
assignments.
* gnu/packages/package-management.scm (guix)[propagated-inputs]: Add
GUILE-GCRYPT.
[arguments]: In 'wrap-program' phase, add GUILE-GCRYPT to the search
path.
2018-08-31 15:07:07 +00:00
|
|
|
|
#:use-module (gcrypt hash)
|
2015-03-17 14:21:31 +00:00
|
|
|
|
#:use-module (guix store)
|
2016-07-20 14:54:31 +00:00
|
|
|
|
#:use-module (guix derivations)
|
|
|
|
|
#:use-module (guix gexp)
|
2015-03-17 14:21:31 +00:00
|
|
|
|
#:use-module (guix base32)
|
|
|
|
|
#:use-module (guix base64)
|
2016-07-18 21:58:34 +00:00
|
|
|
|
#:use-module ((guix records) #:select (recutils->alist))
|
2015-03-17 14:21:31 +00:00
|
|
|
|
#:use-module ((guix serialization) #:select (restore-file))
|
Switch to Guile-Gcrypt.
This removes (guix hash) and (guix pk-crypto), which now live as part of
Guile-Gcrypt (version 0.1.0.)
* guix/gcrypt.scm, guix/hash.scm, guix/pk-crypto.scm,
tests/hash.scm, tests/pk-crypto.scm: Remove.
* configure.ac: Test for Guile-Gcrypt. Remove LIBGCRYPT and
LIBGCRYPT_LIBDIR assignments.
* m4/guix.m4 (GUIX_ASSERT_LIBGCRYPT_USABLE): Remove.
* README: Add Guile-Gcrypt to the dependencies; move libgcrypt as
"required unless --disable-daemon".
* doc/guix.texi (Requirements): Likewise.
* gnu/packages/bash.scm, guix/derivations.scm, guix/docker.scm,
guix/git.scm, guix/http-client.scm, guix/import/cpan.scm,
guix/import/cran.scm, guix/import/crate.scm, guix/import/elpa.scm,
guix/import/gnu.scm, guix/import/hackage.scm,
guix/import/texlive.scm, guix/import/utils.scm, guix/nar.scm,
guix/pki.scm, guix/scripts/archive.scm,
guix/scripts/authenticate.scm, guix/scripts/download.scm,
guix/scripts/hash.scm, guix/scripts/pack.scm,
guix/scripts/publish.scm, guix/scripts/refresh.scm,
guix/scripts/substitute.scm, guix/store.scm,
guix/store/deduplication.scm, guix/tests.scm, tests/base32.scm,
tests/builders.scm, tests/challenge.scm, tests/cpan.scm,
tests/crate.scm, tests/derivations.scm, tests/gem.scm,
tests/nar.scm, tests/opam.scm, tests/pki.scm,
tests/publish.scm, tests/pypi.scm, tests/store-deduplication.scm,
tests/store.scm, tests/substitute.scm: Adjust imports.
* gnu/system/vm.scm: Likewise.
(guile-sqlite3&co): Rename to...
(gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT.
(expression->derivation-in-linux-vm)[config]: Remove.
(iso9660-image)[config]: Remove.
(qemu-image)[config]: Remove.
(system-docker-image)[config]: Remove.
* guix/scripts/pack.scm: Adjust imports.
(guile-sqlite3&co): Rename to...
(gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT.
(self-contained-tarball)[build]: Call 'make-config.scm' without
#:libgcrypt argument.
(squashfs-image)[libgcrypt]: Remove.
[build]: Call 'make-config.scm' without #:libgcrypt.
(docker-image)[config, json]: Remove.
[build]: Add GUILE-GCRYPT to the extensions Remove (guix config) from
the imported modules.
* guix/self.scm (specification->package): Remove "libgcrypt", add
"guile-gcrypt".
(compiled-guix): Remove #:libgcrypt.
[guile-gcrypt]: New variable.
[dependencies]: Add it.
[*core-modules*]: Remove #:libgcrypt from 'make-config.scm' call.
Add #:extensions.
[*config*]: Remove #:libgcrypt from 'make-config.scm' call.
(%dependency-variables): Remove %libgcrypt.
(make-config.scm): Remove #:libgcrypt.
* build-aux/build-self.scm (guile-gcrypt): New variable.
(make-config.scm): Remove #:libgcrypt.
(build-program)[fake-gcrypt-hash]: New variable.
Add (gcrypt hash) to the imported modules. Adjust load path
assignments.
* gnu/packages/package-management.scm (guix)[propagated-inputs]: Add
GUILE-GCRYPT.
[arguments]: In 'wrap-program' phase, add GUILE-GCRYPT to the search
path.
2018-08-31 15:07:07 +00:00
|
|
|
|
#:use-module (gcrypt pk-crypto)
|
2017-03-22 08:50:06 +00:00
|
|
|
|
#:use-module ((guix pki) #:select (%public-key-file %private-key-file))
|
Use "guile-zlib" and "guile-lzlib" instead of (guix config).
* Makefile.am (MODULES): Remove guix/zlib.scm and guix/lzlib.scm,
(SCM_TESTS): remove tests/zlib.scm, tests/lzlib.scm.
* build-aux/build-self.scm (make-config.scm): Remove unused %libz variable.
* configure.ac: Remove LIBZ and LIBLZ variables and check instead for
Guile-zlib and Guile-lzlib.
* doc/guix.texi ("Requirements"): Remove zlib requirement and add Guile-zlib
and Guile-lzlib instead.
* gnu/packages/package-management.scm (guix)[native-inputs]: Add "guile-zlib"
and "guile-lzlib",
[inputs]: remove "zlib" and "lzlib",
[propagated-inputs]: ditto,
[arguments]: add "guile-zlib" and "guile-lzlib" to Guile load path.
* guix/config.scm.in (%libz, %liblz): Remove them.
* guix/lzlib.scm: Remove it.
* guix/man-db.scm: Use (zlib) instead of (guix zlib).
* guix/profiles.scm (manual-database): Do not stub (guix config) in imported
modules list, instead add "guile-zlib" to the extension list.
* guix/scripts/publish.scm: Use (zlib) instead of (guix zlib) and (lzlib)
instead of (guix lzlib),
(string->compression-type, effective-compression): do not check for zlib and
lzlib availability.
* guix/scripts/substitute.scm (%compression-methods): Do not check for lzlib
availability.
* guix/self.scm (specification->package): Add "guile-zlib" and "guile-lzlib"
and remove "zlib" and "lzlib",
(compiled-guix): remove "zlib" and "lzlib" arguments and add guile-zlib and
guile-lzlib to the dependencies, also do not pass "zlib" and "lzlib" to
"make-config.scm" procedure,
(make-config.scm): remove "zlib" and "lzlib" arguments as well as %libz and
%liblz variables.
* guix/utils.scm (lzip-port): Use (lzlib) instead of (guix lzlib) and do not
check for lzlib availability.
* guix/zlib.scm: Remove it.
* m4/guix.m4 (GUIX_LIBZ_LIBDIR, GUIX_LIBLZ_FILE_NAME): Remove them.
* tests/lzlib.scm: Use (zlib) instead of (guix zlib) and (lzlib)
instead of (guix lzlib), and do not check for zlib and lzlib availability.
* tests/publish.scm: Ditto.
* tests/substitute.scm: Do not check for lzlib availability.
* tests/utils.scm: Ditto.
* tests/zlib.scm: Remove it.
2020-07-27 14:36:39 +00:00
|
|
|
|
#:use-module (zlib)
|
|
|
|
|
#:use-module (lzlib)
|
2020-12-27 11:10:15 +00:00
|
|
|
|
#:autoload (zstd) (call-with-zstd-input-port)
|
2016-06-08 16:59:25 +00:00
|
|
|
|
#:use-module (web uri)
|
2015-03-17 14:21:31 +00:00
|
|
|
|
#:use-module (web client)
|
|
|
|
|
#:use-module (web response)
|
|
|
|
|
#:use-module (rnrs bytevectors)
|
2016-07-18 21:58:34 +00:00
|
|
|
|
#:use-module (ice-9 binary-ports)
|
2015-03-17 14:21:31 +00:00
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
|
#:use-module (srfi srfi-26)
|
|
|
|
|
#:use-module (srfi srfi-64)
|
2019-11-23 21:27:28 +00:00
|
|
|
|
#:use-module (ice-9 threads)
|
2016-06-08 16:59:25 +00:00
|
|
|
|
#:use-module (ice-9 format)
|
2015-03-17 14:21:31 +00:00
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
|
#:use-module (ice-9 rdelim))
|
|
|
|
|
|
|
|
|
|
(define %store
|
|
|
|
|
(open-connection-for-tests))
|
|
|
|
|
|
2020-12-27 11:10:15 +00:00
|
|
|
|
(define (zstd-supported?)
|
|
|
|
|
(resolve-module '(zstd) #t #f #:ensure #f))
|
|
|
|
|
|
2015-03-17 14:21:31 +00:00
|
|
|
|
(define %reference (add-text-to-store %store "ref" "foo"))
|
|
|
|
|
|
|
|
|
|
(define %item (add-text-to-store %store "item" "bar" (list %reference)))
|
|
|
|
|
|
|
|
|
|
(define (http-get-body uri)
|
|
|
|
|
(call-with-values (lambda () (http-get uri))
|
|
|
|
|
(lambda (response body) body)))
|
|
|
|
|
|
2016-07-18 21:58:34 +00:00
|
|
|
|
(define (http-get-port uri)
|
2016-07-27 10:43:12 +00:00
|
|
|
|
(let ((socket (open-socket-for-uri uri)))
|
|
|
|
|
;; Make sure to use an unbuffered port so that we can then peek at the
|
|
|
|
|
;; underlying file descriptor via 'call-with-gzip-input-port'.
|
2019-01-07 09:57:18 +00:00
|
|
|
|
(setvbuf socket 'none)
|
2016-07-27 10:43:12 +00:00
|
|
|
|
(call-with-values
|
|
|
|
|
(lambda ()
|
|
|
|
|
(http-get uri #:port socket #:streaming? #t))
|
|
|
|
|
(lambda (response port)
|
2019-01-07 09:57:18 +00:00
|
|
|
|
;; Don't (setvbuf port 'none) because of <http://bugs.gnu.org/19610>
|
2016-08-02 15:31:45 +00:00
|
|
|
|
;; (PORT might be a custom binary input port).
|
2016-07-27 10:43:12 +00:00
|
|
|
|
port))))
|
2016-07-18 21:58:34 +00:00
|
|
|
|
|
2015-03-17 14:21:31 +00:00
|
|
|
|
(define (publish-uri route)
|
|
|
|
|
(string-append "http://localhost:6789" route))
|
|
|
|
|
|
2016-08-02 15:48:21 +00:00
|
|
|
|
(define-syntax-rule (with-separate-output-ports exp ...)
|
|
|
|
|
;; Since ports aren't thread-safe in Guile 2.0, duplicate the output and
|
|
|
|
|
;; error ports to make sure the two threads don't end up stepping on each
|
|
|
|
|
;; other's toes.
|
|
|
|
|
(with-output-to-port (duplicate-port (current-output-port) "w")
|
|
|
|
|
(lambda ()
|
|
|
|
|
(with-error-to-port (duplicate-port (current-error-port) "w")
|
|
|
|
|
(lambda ()
|
|
|
|
|
exp ...)))))
|
|
|
|
|
|
2015-03-17 14:21:31 +00:00
|
|
|
|
;; Run a local publishing server in a separate thread.
|
2016-08-02 15:48:21 +00:00
|
|
|
|
(with-separate-output-ports
|
|
|
|
|
(call-with-new-thread
|
|
|
|
|
(lambda ()
|
|
|
|
|
(guix-publish "--port=6789" "-C0")))) ;attempt to avoid port collision
|
2016-07-18 21:58:34 +00:00
|
|
|
|
|
|
|
|
|
(define (wait-until-ready port)
|
|
|
|
|
;; Wait until the server is accepting connections.
|
|
|
|
|
(let ((conn (socket PF_INET SOCK_STREAM 0)))
|
|
|
|
|
(let loop ()
|
|
|
|
|
(unless (false-if-exception
|
|
|
|
|
(connect conn AF_INET (inet-pton AF_INET "127.0.0.1") port))
|
|
|
|
|
(loop)))))
|
2015-03-17 14:21:31 +00:00
|
|
|
|
|
2017-05-18 19:19:49 +00:00
|
|
|
|
(define (wait-for-file file)
|
|
|
|
|
;; Wait until FILE shows up.
|
|
|
|
|
(let loop ((i 20))
|
|
|
|
|
(cond ((file-exists? file)
|
|
|
|
|
#t)
|
|
|
|
|
((zero? i)
|
|
|
|
|
(error "file didn't show up" file))
|
|
|
|
|
(else
|
|
|
|
|
(pk 'wait-for-file file)
|
|
|
|
|
(sleep 1)
|
|
|
|
|
(loop (- i 1))))))
|
|
|
|
|
|
2018-01-22 09:46:34 +00:00
|
|
|
|
(define %gzip-magic-bytes
|
|
|
|
|
;; Magic bytes of gzip file.
|
|
|
|
|
#vu8(#x1f #x8b))
|
|
|
|
|
|
2016-07-18 21:58:34 +00:00
|
|
|
|
;; Wait until the two servers are ready.
|
|
|
|
|
(wait-until-ready 6789)
|
2015-03-17 14:21:31 +00:00
|
|
|
|
|
2017-03-22 08:50:06 +00:00
|
|
|
|
;; Initialize the public/private key SRFI-39 parameters.
|
|
|
|
|
(%public-key (read-file-sexp %public-key-file))
|
|
|
|
|
(%private-key (read-file-sexp %private-key-file))
|
|
|
|
|
|
2016-01-21 22:45:52 +00:00
|
|
|
|
|
2015-03-17 14:21:31 +00:00
|
|
|
|
(test-begin "publish")
|
|
|
|
|
|
|
|
|
|
(test-equal "/nix-cache-info"
|
|
|
|
|
(format #f "StoreDir: ~a\nWantMassQuery: 0\nPriority: 100\n"
|
|
|
|
|
%store-directory)
|
|
|
|
|
(http-get-body (publish-uri "/nix-cache-info")))
|
|
|
|
|
|
|
|
|
|
(test-equal "/*.narinfo"
|
|
|
|
|
(let* ((info (query-path-info %store %item))
|
|
|
|
|
(unsigned-info
|
|
|
|
|
(format #f
|
|
|
|
|
"StorePath: ~a
|
|
|
|
|
URL: nar/~a
|
|
|
|
|
Compression: none
|
2019-05-30 16:36:37 +00:00
|
|
|
|
FileSize: ~a
|
2015-03-17 14:21:31 +00:00
|
|
|
|
NarHash: sha256:~a
|
|
|
|
|
NarSize: ~d
|
2019-05-30 16:36:37 +00:00
|
|
|
|
References: ~a~%"
|
2015-03-17 14:21:31 +00:00
|
|
|
|
%item
|
|
|
|
|
(basename %item)
|
2019-05-30 16:36:37 +00:00
|
|
|
|
(path-info-nar-size info)
|
2015-07-18 14:05:28 +00:00
|
|
|
|
(bytevector->nix-base32-string
|
2015-03-17 14:21:31 +00:00
|
|
|
|
(path-info-hash info))
|
|
|
|
|
(path-info-nar-size info)
|
2019-05-30 16:36:37 +00:00
|
|
|
|
(basename (first (path-info-references info)))))
|
2015-03-17 14:21:31 +00:00
|
|
|
|
(signature (base64-encode
|
|
|
|
|
(string->utf8
|
|
|
|
|
(canonical-sexp->string
|
2020-01-16 09:43:29 +00:00
|
|
|
|
(signed-string unsigned-info))))))
|
2015-03-17 14:21:31 +00:00
|
|
|
|
(format #f "~aSignature: 1;~a;~a~%"
|
|
|
|
|
unsigned-info (gethostname) signature))
|
|
|
|
|
(utf8->string
|
|
|
|
|
(http-get-body
|
|
|
|
|
(publish-uri
|
|
|
|
|
(string-append "/" (store-path-hash-part %item) ".narinfo")))))
|
|
|
|
|
|
2016-06-08 16:59:25 +00:00
|
|
|
|
(test-equal "/*.narinfo with properly encoded '+' sign"
|
|
|
|
|
;; See <http://bugs.gnu.org/21888>.
|
|
|
|
|
(let* ((item (add-text-to-store %store "fake-gtk+" "Congrats!"))
|
|
|
|
|
(info (query-path-info %store item))
|
|
|
|
|
(unsigned-info
|
|
|
|
|
(format #f
|
|
|
|
|
"StorePath: ~a
|
|
|
|
|
URL: nar/~a
|
|
|
|
|
Compression: none
|
2019-05-30 16:36:37 +00:00
|
|
|
|
FileSize: ~a
|
2016-06-08 16:59:25 +00:00
|
|
|
|
NarHash: sha256:~a
|
|
|
|
|
NarSize: ~d
|
2019-05-30 16:36:37 +00:00
|
|
|
|
References: ~%"
|
2016-06-08 16:59:25 +00:00
|
|
|
|
item
|
|
|
|
|
(uri-encode (basename item))
|
2019-05-30 16:36:37 +00:00
|
|
|
|
(path-info-nar-size info)
|
2016-06-08 16:59:25 +00:00
|
|
|
|
(bytevector->nix-base32-string
|
|
|
|
|
(path-info-hash info))
|
|
|
|
|
(path-info-nar-size info)))
|
|
|
|
|
(signature (base64-encode
|
|
|
|
|
(string->utf8
|
|
|
|
|
(canonical-sexp->string
|
2020-01-16 09:43:29 +00:00
|
|
|
|
(signed-string unsigned-info))))))
|
2016-06-08 16:59:25 +00:00
|
|
|
|
(format #f "~aSignature: 1;~a;~a~%"
|
|
|
|
|
unsigned-info (gethostname) signature))
|
|
|
|
|
|
|
|
|
|
(let ((item (add-text-to-store %store "fake-gtk+" "Congrats!")))
|
|
|
|
|
(utf8->string
|
|
|
|
|
(http-get-body
|
|
|
|
|
(publish-uri
|
|
|
|
|
(string-append "/" (store-path-hash-part item) ".narinfo"))))))
|
|
|
|
|
|
2015-03-17 14:21:31 +00:00
|
|
|
|
(test-equal "/nar/*"
|
|
|
|
|
"bar"
|
|
|
|
|
(call-with-temporary-output-file
|
|
|
|
|
(lambda (temp port)
|
|
|
|
|
(let ((nar (utf8->string
|
|
|
|
|
(http-get-body
|
|
|
|
|
(publish-uri
|
|
|
|
|
(string-append "/nar/" (basename %item)))))))
|
|
|
|
|
(call-with-input-string nar (cut restore-file <> temp)))
|
|
|
|
|
(call-with-input-file temp read-string))))
|
|
|
|
|
|
2016-07-18 21:58:34 +00:00
|
|
|
|
(test-equal "/nar/gzip/*"
|
|
|
|
|
"bar"
|
|
|
|
|
(call-with-temporary-output-file
|
|
|
|
|
(lambda (temp port)
|
|
|
|
|
(let ((nar (http-get-port
|
|
|
|
|
(publish-uri
|
|
|
|
|
(string-append "/nar/gzip/" (basename %item))))))
|
|
|
|
|
(call-with-gzip-input-port nar
|
|
|
|
|
(cut restore-file <> temp)))
|
|
|
|
|
(call-with-input-file temp read-string))))
|
|
|
|
|
|
2018-01-22 09:46:34 +00:00
|
|
|
|
(test-equal "/nar/gzip/* is really gzip"
|
|
|
|
|
%gzip-magic-bytes
|
|
|
|
|
;; Since 'gzdopen' (aka. 'call-with-gzip-input-port') transparently reads
|
|
|
|
|
;; uncompressed gzip, the test above doesn't check whether it's actually
|
|
|
|
|
;; gzip. This is what this test does. See <https://bugs.gnu.org/30184>.
|
|
|
|
|
(let ((nar (http-get-port
|
|
|
|
|
(publish-uri
|
|
|
|
|
(string-append "/nar/gzip/" (basename %item))))))
|
|
|
|
|
(get-bytevector-n nar (bytevector-length %gzip-magic-bytes))))
|
|
|
|
|
|
2019-05-24 06:26:38 +00:00
|
|
|
|
(test-equal "/nar/lzip/*"
|
|
|
|
|
"bar"
|
|
|
|
|
(call-with-temporary-output-file
|
|
|
|
|
(lambda (temp port)
|
|
|
|
|
(let ((nar (http-get-port
|
|
|
|
|
(publish-uri
|
|
|
|
|
(string-append "/nar/lzip/" (basename %item))))))
|
|
|
|
|
(call-with-lzip-input-port nar
|
|
|
|
|
(cut restore-file <> temp)))
|
|
|
|
|
(call-with-input-file temp read-string))))
|
|
|
|
|
|
2020-12-27 11:10:15 +00:00
|
|
|
|
(unless (zstd-supported?) (test-skip 1))
|
|
|
|
|
(test-equal "/nar/zstd/*"
|
|
|
|
|
"bar"
|
|
|
|
|
(call-with-temporary-output-file
|
|
|
|
|
(lambda (temp port)
|
|
|
|
|
(let ((nar (http-get-port
|
|
|
|
|
(publish-uri
|
|
|
|
|
(string-append "/nar/zstd/" (basename %item))))))
|
|
|
|
|
(call-with-zstd-input-port nar
|
|
|
|
|
(cut restore-file <> temp)))
|
|
|
|
|
(call-with-input-file temp read-string))))
|
|
|
|
|
|
2016-07-18 21:58:34 +00:00
|
|
|
|
(test-equal "/*.narinfo with compression"
|
|
|
|
|
`(("StorePath" . ,%item)
|
|
|
|
|
("URL" . ,(string-append "nar/gzip/" (basename %item)))
|
|
|
|
|
("Compression" . "gzip"))
|
2016-08-02 15:48:21 +00:00
|
|
|
|
(let ((thread (with-separate-output-ports
|
|
|
|
|
(call-with-new-thread
|
|
|
|
|
(lambda ()
|
|
|
|
|
(guix-publish "--port=6799" "-C5"))))))
|
2016-07-18 21:58:34 +00:00
|
|
|
|
(wait-until-ready 6799)
|
|
|
|
|
(let* ((url (string-append "http://localhost:6799/"
|
|
|
|
|
(store-path-hash-part %item) ".narinfo"))
|
|
|
|
|
(body (http-get-port url)))
|
|
|
|
|
(filter (lambda (item)
|
|
|
|
|
(match item
|
|
|
|
|
(("Compression" . _) #t)
|
|
|
|
|
(("StorePath" . _) #t)
|
|
|
|
|
(("URL" . _) #t)
|
|
|
|
|
(_ #f)))
|
|
|
|
|
(recutils->alist body)))))
|
|
|
|
|
|
2019-05-24 06:26:38 +00:00
|
|
|
|
(test-equal "/*.narinfo with lzip compression"
|
|
|
|
|
`(("StorePath" . ,%item)
|
|
|
|
|
("URL" . ,(string-append "nar/lzip/" (basename %item)))
|
|
|
|
|
("Compression" . "lzip"))
|
|
|
|
|
(let ((thread (with-separate-output-ports
|
|
|
|
|
(call-with-new-thread
|
|
|
|
|
(lambda ()
|
|
|
|
|
(guix-publish "--port=6790" "-Clzip"))))))
|
|
|
|
|
(wait-until-ready 6790)
|
|
|
|
|
(let* ((url (string-append "http://localhost:6790/"
|
|
|
|
|
(store-path-hash-part %item) ".narinfo"))
|
|
|
|
|
(body (http-get-port url)))
|
|
|
|
|
(filter (lambda (item)
|
|
|
|
|
(match item
|
|
|
|
|
(("Compression" . _) #t)
|
|
|
|
|
(("StorePath" . _) #t)
|
|
|
|
|
(("URL" . _) #t)
|
|
|
|
|
(_ #f)))
|
|
|
|
|
(recutils->alist body)))))
|
|
|
|
|
|
2016-08-01 15:42:09 +00:00
|
|
|
|
(test-equal "/*.narinfo for a compressed file"
|
|
|
|
|
'("none" "nar") ;compression-less nar
|
|
|
|
|
;; Assume 'guix publish -C' is already running on port 6799.
|
|
|
|
|
(let* ((item (add-text-to-store %store "fake.tar.gz"
|
|
|
|
|
"This is a fake compressed file."))
|
|
|
|
|
(url (string-append "http://localhost:6799/"
|
|
|
|
|
(store-path-hash-part item) ".narinfo"))
|
|
|
|
|
(body (http-get-port url))
|
|
|
|
|
(info (recutils->alist body)))
|
|
|
|
|
(list (assoc-ref info "Compression")
|
|
|
|
|
(dirname (assoc-ref info "URL")))))
|
|
|
|
|
|
2019-05-30 16:36:37 +00:00
|
|
|
|
(test-equal "/*.narinfo with lzip + gzip"
|
|
|
|
|
`((("StorePath" . ,%item)
|
|
|
|
|
("URL" . ,(string-append "nar/gzip/" (basename %item)))
|
|
|
|
|
("Compression" . "gzip")
|
|
|
|
|
("URL" . ,(string-append "nar/lzip/" (basename %item)))
|
|
|
|
|
("Compression" . "lzip"))
|
|
|
|
|
200
|
|
|
|
|
200)
|
|
|
|
|
(call-with-temporary-directory
|
|
|
|
|
(lambda (cache)
|
|
|
|
|
(let ((thread (with-separate-output-ports
|
|
|
|
|
(call-with-new-thread
|
|
|
|
|
(lambda ()
|
|
|
|
|
(guix-publish "--port=6793" "-Cgzip:2" "-Clzip:2"))))))
|
|
|
|
|
(wait-until-ready 6793)
|
|
|
|
|
(let* ((base "http://localhost:6793/")
|
|
|
|
|
(part (store-path-hash-part %item))
|
|
|
|
|
(url (string-append base part ".narinfo"))
|
|
|
|
|
(body (http-get-port url)))
|
|
|
|
|
(list (take (recutils->alist body) 5)
|
|
|
|
|
(response-code
|
|
|
|
|
(http-get (string-append base "nar/gzip/"
|
|
|
|
|
(basename %item))))
|
|
|
|
|
(response-code
|
|
|
|
|
(http-get (string-append base "nar/lzip/"
|
|
|
|
|
(basename %item))))))))))
|
|
|
|
|
|
2017-03-22 12:31:54 +00:00
|
|
|
|
(test-equal "custom nar path"
|
|
|
|
|
;; Serve nars at /foo/bar/chbouib instead of /nar.
|
|
|
|
|
(list `(("StorePath" . ,%item)
|
|
|
|
|
("URL" . ,(string-append "foo/bar/chbouib/" (basename %item)))
|
|
|
|
|
("Compression" . "none"))
|
|
|
|
|
200
|
|
|
|
|
404)
|
|
|
|
|
(let ((thread (with-separate-output-ports
|
|
|
|
|
(call-with-new-thread
|
|
|
|
|
(lambda ()
|
|
|
|
|
(guix-publish "--port=6798" "-C0"
|
|
|
|
|
"--nar-path=///foo/bar//chbouib/"))))))
|
|
|
|
|
(wait-until-ready 6798)
|
|
|
|
|
(let* ((base "http://localhost:6798/")
|
|
|
|
|
(part (store-path-hash-part %item))
|
|
|
|
|
(url (string-append base part ".narinfo"))
|
|
|
|
|
(nar-url (string-append base "foo/bar/chbouib/"
|
|
|
|
|
(basename %item)))
|
|
|
|
|
(body (http-get-port url)))
|
|
|
|
|
(list (filter (lambda (item)
|
|
|
|
|
(match item
|
|
|
|
|
(("Compression" . _) #t)
|
|
|
|
|
(("StorePath" . _) #t)
|
|
|
|
|
(("URL" . _) #t)
|
|
|
|
|
(_ #f)))
|
|
|
|
|
(recutils->alist body))
|
|
|
|
|
(response-code (http-get nar-url))
|
|
|
|
|
(response-code
|
|
|
|
|
(http-get (string-append base "nar/" (basename %item))))))))
|
|
|
|
|
|
2016-06-08 16:59:25 +00:00
|
|
|
|
(test-equal "/nar/ with properly encoded '+' sign"
|
|
|
|
|
"Congrats!"
|
|
|
|
|
(let ((item (add-text-to-store %store "fake-gtk+" "Congrats!")))
|
|
|
|
|
(call-with-temporary-output-file
|
|
|
|
|
(lambda (temp port)
|
|
|
|
|
(let ((nar (utf8->string
|
|
|
|
|
(http-get-body
|
|
|
|
|
(publish-uri
|
|
|
|
|
(string-append "/nar/" (uri-encode (basename item))))))))
|
|
|
|
|
(call-with-input-string nar (cut restore-file <> temp)))
|
|
|
|
|
(call-with-input-file temp read-string)))))
|
|
|
|
|
|
2016-02-25 10:48:17 +00:00
|
|
|
|
(test-equal "/nar/invalid"
|
|
|
|
|
404
|
|
|
|
|
(begin
|
|
|
|
|
(call-with-output-file (string-append (%store-prefix) "/invalid")
|
|
|
|
|
(lambda (port)
|
|
|
|
|
(display "This file is not a valid store item." port)))
|
|
|
|
|
(response-code (http-get (publish-uri (string-append "/nar/invalid"))))))
|
|
|
|
|
|
2016-07-20 14:54:31 +00:00
|
|
|
|
(test-equal "/file/NAME/sha256/HASH"
|
|
|
|
|
"Hello, Guix world!"
|
|
|
|
|
(let* ((data "Hello, Guix world!")
|
|
|
|
|
(hash (call-with-input-string data port-sha256))
|
|
|
|
|
(drv (run-with-store %store
|
|
|
|
|
(gexp->derivation "the-file.txt"
|
|
|
|
|
#~(call-with-output-file #$output
|
|
|
|
|
(lambda (port)
|
|
|
|
|
(display #$data port)))
|
|
|
|
|
#:hash-algo 'sha256
|
|
|
|
|
#:hash hash)))
|
|
|
|
|
(out (build-derivations %store (list drv))))
|
|
|
|
|
(utf8->string
|
|
|
|
|
(http-get-body
|
|
|
|
|
(publish-uri
|
|
|
|
|
(string-append "/file/the-file.txt/sha256/"
|
|
|
|
|
(bytevector->nix-base32-string hash)))))))
|
|
|
|
|
|
|
|
|
|
(test-equal "/file/NAME/sha256/INVALID-NIX-BASE32-STRING"
|
|
|
|
|
404
|
|
|
|
|
(let ((uri (publish-uri
|
|
|
|
|
"/file/the-file.txt/sha256/not-a-nix-base32-string")))
|
|
|
|
|
(response-code (http-get uri))))
|
|
|
|
|
|
|
|
|
|
(test-equal "/file/NAME/sha256/INVALID-HASH"
|
|
|
|
|
404
|
|
|
|
|
(let ((uri (publish-uri
|
|
|
|
|
(string-append "/file/the-file.txt/sha256/"
|
|
|
|
|
(bytevector->nix-base32-string
|
|
|
|
|
(call-with-input-string "" port-sha256))))))
|
|
|
|
|
(response-code (http-get uri))))
|
|
|
|
|
|
2017-04-17 21:13:40 +00:00
|
|
|
|
(test-equal "with cache"
|
|
|
|
|
(list #t
|
|
|
|
|
`(("StorePath" . ,%item)
|
|
|
|
|
("URL" . ,(string-append "nar/gzip/" (basename %item)))
|
|
|
|
|
("Compression" . "gzip"))
|
|
|
|
|
200 ;nar/gzip/…
|
|
|
|
|
#t ;Content-Length
|
2017-05-01 15:24:41 +00:00
|
|
|
|
#t ;FileSize
|
2017-10-05 20:15:19 +00:00
|
|
|
|
404) ;nar/…
|
2017-04-17 21:13:40 +00:00
|
|
|
|
(call-with-temporary-directory
|
|
|
|
|
(lambda (cache)
|
|
|
|
|
(let ((thread (with-separate-output-ports
|
|
|
|
|
(call-with-new-thread
|
|
|
|
|
(lambda ()
|
|
|
|
|
(guix-publish "--port=6797" "-C2"
|
2020-10-24 14:31:18 +00:00
|
|
|
|
(string-append "--cache=" cache)
|
|
|
|
|
"--cache-bypass-threshold=0"))))))
|
2017-04-17 21:13:40 +00:00
|
|
|
|
(wait-until-ready 6797)
|
|
|
|
|
(let* ((base "http://localhost:6797/")
|
|
|
|
|
(part (store-path-hash-part %item))
|
|
|
|
|
(url (string-append base part ".narinfo"))
|
2017-12-01 17:30:07 +00:00
|
|
|
|
(nar-url (string-append base "nar/gzip/" (basename %item)))
|
2017-04-17 21:13:40 +00:00
|
|
|
|
(cached (string-append cache "/gzip/" (basename %item)
|
|
|
|
|
".narinfo"))
|
|
|
|
|
(nar (string-append cache "/gzip/"
|
|
|
|
|
(basename %item) ".nar"))
|
|
|
|
|
(response (http-get url)))
|
|
|
|
|
(and (= 404 (response-code response))
|
2017-05-11 08:23:27 +00:00
|
|
|
|
|
|
|
|
|
;; We should get an explicitly short TTL for 404 in this case
|
|
|
|
|
;; because it's going to become 200 shortly.
|
|
|
|
|
(match (assq-ref (response-headers response) 'cache-control)
|
|
|
|
|
((('max-age . ttl))
|
|
|
|
|
(< ttl 3600)))
|
|
|
|
|
|
2017-04-17 21:13:40 +00:00
|
|
|
|
(wait-for-file cached)
|
2020-11-08 22:35:45 +00:00
|
|
|
|
|
|
|
|
|
;; Both the narinfo and nar should be world-readable.
|
2021-03-30 15:11:48 +00:00
|
|
|
|
(= #o444 (logand #o444 (stat:perms (lstat cached))))
|
|
|
|
|
(= #o444 (logand #o444 (stat:perms (lstat nar))))
|
2020-11-08 22:35:45 +00:00
|
|
|
|
|
2017-05-01 15:24:41 +00:00
|
|
|
|
(let* ((body (http-get-port url))
|
|
|
|
|
(compressed (http-get nar-url))
|
|
|
|
|
(uncompressed (http-get (string-append base "nar/"
|
|
|
|
|
(basename %item))))
|
|
|
|
|
(narinfo (recutils->alist body)))
|
2017-04-17 21:13:40 +00:00
|
|
|
|
(list (file-exists? nar)
|
|
|
|
|
(filter (lambda (item)
|
|
|
|
|
(match item
|
|
|
|
|
(("Compression" . _) #t)
|
|
|
|
|
(("StorePath" . _) #t)
|
|
|
|
|
(("URL" . _) #t)
|
|
|
|
|
(_ #f)))
|
2017-05-01 15:24:41 +00:00
|
|
|
|
narinfo)
|
2017-04-17 21:13:40 +00:00
|
|
|
|
(response-code compressed)
|
|
|
|
|
(= (response-content-length compressed)
|
|
|
|
|
(stat:size (stat nar)))
|
2017-05-01 15:24:41 +00:00
|
|
|
|
(= (string->number
|
|
|
|
|
(assoc-ref narinfo "FileSize"))
|
|
|
|
|
(stat:size (stat nar)))
|
2017-04-17 21:13:40 +00:00
|
|
|
|
(response-code uncompressed)))))))))
|
|
|
|
|
|
2019-05-30 16:36:37 +00:00
|
|
|
|
(test-equal "with cache, lzip + gzip"
|
|
|
|
|
'(200 200 404)
|
|
|
|
|
(call-with-temporary-directory
|
|
|
|
|
(lambda (cache)
|
|
|
|
|
(let ((thread (with-separate-output-ports
|
|
|
|
|
(call-with-new-thread
|
|
|
|
|
(lambda ()
|
|
|
|
|
(guix-publish "--port=6794" "-Cgzip:2" "-Clzip:2"
|
2020-10-24 14:31:18 +00:00
|
|
|
|
(string-append "--cache=" cache)
|
|
|
|
|
"--cache-bypass-threshold=0"))))))
|
2019-05-30 16:36:37 +00:00
|
|
|
|
(wait-until-ready 6794)
|
|
|
|
|
(let* ((base "http://localhost:6794/")
|
|
|
|
|
(part (store-path-hash-part %item))
|
|
|
|
|
(url (string-append base part ".narinfo"))
|
|
|
|
|
(nar-url (cute string-append "nar/" <> "/"
|
|
|
|
|
(basename %item)))
|
|
|
|
|
(cached (cute string-append cache "/" <> "/"
|
|
|
|
|
(basename %item) ".narinfo"))
|
|
|
|
|
(nar (cute string-append cache "/" <> "/"
|
|
|
|
|
(basename %item) ".nar"))
|
|
|
|
|
(response (http-get url)))
|
|
|
|
|
(wait-for-file (cached "gzip"))
|
|
|
|
|
(let* ((body (http-get-port url))
|
|
|
|
|
(narinfo (recutils->alist body))
|
|
|
|
|
(uncompressed (string-append base "nar/"
|
|
|
|
|
(basename %item))))
|
|
|
|
|
(and (file-exists? (nar "gzip"))
|
|
|
|
|
(file-exists? (nar "lzip"))
|
|
|
|
|
(equal? (take (pk 'narinfo/gzip+lzip narinfo) 7)
|
|
|
|
|
`(("StorePath" . ,%item)
|
|
|
|
|
("URL" . ,(nar-url "gzip"))
|
|
|
|
|
("Compression" . "gzip")
|
|
|
|
|
("FileSize" . ,(number->string
|
|
|
|
|
(stat:size (stat (nar "gzip")))))
|
|
|
|
|
("URL" . ,(nar-url "lzip"))
|
|
|
|
|
("Compression" . "lzip")
|
|
|
|
|
("FileSize" . ,(number->string
|
|
|
|
|
(stat:size (stat (nar "lzip")))))))
|
|
|
|
|
(list (response-code
|
|
|
|
|
(http-get (string-append base (nar-url "gzip"))))
|
|
|
|
|
(response-code
|
|
|
|
|
(http-get (string-append base (nar-url "lzip"))))
|
|
|
|
|
(response-code
|
|
|
|
|
(http-get uncompressed))))))))))
|
|
|
|
|
|
2017-05-18 19:19:49 +00:00
|
|
|
|
(let ((item (add-text-to-store %store "fake-compressed-thing.tar.gz"
|
|
|
|
|
(random-text))))
|
|
|
|
|
(test-equal "with cache, uncompressed"
|
2017-10-05 20:15:19 +00:00
|
|
|
|
(list #t
|
2018-12-17 22:01:51 +00:00
|
|
|
|
(* 42 3600) ;TTL on narinfo
|
2017-05-18 19:19:49 +00:00
|
|
|
|
`(("StorePath" . ,item)
|
|
|
|
|
("URL" . ,(string-append "nar/" (basename item)))
|
|
|
|
|
("Compression" . "none"))
|
|
|
|
|
200 ;nar/…
|
2018-12-17 22:01:51 +00:00
|
|
|
|
(* 42 3600) ;TTL on nar/…
|
2017-05-18 19:19:49 +00:00
|
|
|
|
(path-info-nar-size
|
|
|
|
|
(query-path-info %store item)) ;FileSize
|
|
|
|
|
404) ;nar/gzip/…
|
|
|
|
|
(call-with-temporary-directory
|
|
|
|
|
(lambda (cache)
|
|
|
|
|
(let ((thread (with-separate-output-ports
|
|
|
|
|
(call-with-new-thread
|
|
|
|
|
(lambda ()
|
2018-12-17 22:01:51 +00:00
|
|
|
|
(guix-publish "--port=6796" "-C2" "--ttl=42h"
|
2020-10-24 14:31:18 +00:00
|
|
|
|
(string-append "--cache=" cache)
|
|
|
|
|
"--cache-bypass-threshold=0"))))))
|
2017-05-18 19:19:49 +00:00
|
|
|
|
(wait-until-ready 6796)
|
|
|
|
|
(let* ((base "http://localhost:6796/")
|
|
|
|
|
(part (store-path-hash-part item))
|
|
|
|
|
(url (string-append base part ".narinfo"))
|
|
|
|
|
(cached (string-append cache "/none/"
|
|
|
|
|
(basename item) ".narinfo"))
|
|
|
|
|
(nar (string-append cache "/none/"
|
|
|
|
|
(basename item) ".nar"))
|
|
|
|
|
(response (http-get url)))
|
|
|
|
|
(and (= 404 (response-code response))
|
|
|
|
|
|
|
|
|
|
(wait-for-file cached)
|
2018-12-17 22:01:51 +00:00
|
|
|
|
(let* ((response (http-get url))
|
|
|
|
|
(body (http-get-port url))
|
2017-05-18 19:19:49 +00:00
|
|
|
|
(compressed (http-get (string-append base "nar/gzip/"
|
|
|
|
|
(basename item))))
|
|
|
|
|
(uncompressed (http-get (string-append base "nar/"
|
|
|
|
|
(basename item))))
|
|
|
|
|
(narinfo (recutils->alist body)))
|
|
|
|
|
(list (file-exists? nar)
|
2018-12-17 22:01:51 +00:00
|
|
|
|
(match (assq-ref (response-headers response)
|
|
|
|
|
'cache-control)
|
|
|
|
|
((('max-age . ttl)) ttl)
|
|
|
|
|
(_ #f))
|
|
|
|
|
|
2017-05-18 19:19:49 +00:00
|
|
|
|
(filter (lambda (item)
|
|
|
|
|
(match item
|
|
|
|
|
(("Compression" . _) #t)
|
|
|
|
|
(("StorePath" . _) #t)
|
|
|
|
|
(("URL" . _) #t)
|
|
|
|
|
(_ #f)))
|
|
|
|
|
narinfo)
|
|
|
|
|
(response-code uncompressed)
|
2018-12-17 22:01:51 +00:00
|
|
|
|
(match (assq-ref (response-headers uncompressed)
|
|
|
|
|
'cache-control)
|
|
|
|
|
((('max-age . ttl)) ttl)
|
|
|
|
|
(_ #f))
|
|
|
|
|
|
2017-05-18 19:19:49 +00:00
|
|
|
|
(string->number
|
|
|
|
|
(assoc-ref narinfo "FileSize"))
|
|
|
|
|
(response-code compressed))))))))))
|
|
|
|
|
|
2019-05-25 23:18:53 +00:00
|
|
|
|
(test-equal "with cache, vanishing item" ;<https://bugs.gnu.org/33897>
|
|
|
|
|
200
|
|
|
|
|
(call-with-temporary-directory
|
|
|
|
|
(lambda (cache)
|
|
|
|
|
(let ((thread (with-separate-output-ports
|
|
|
|
|
(call-with-new-thread
|
|
|
|
|
(lambda ()
|
|
|
|
|
(guix-publish "--port=6795"
|
|
|
|
|
(string-append "--cache=" cache)))))))
|
|
|
|
|
(wait-until-ready 6795)
|
|
|
|
|
|
|
|
|
|
;; Make sure that, even if ITEM disappears, we're still able to fetch
|
|
|
|
|
;; it.
|
|
|
|
|
(let* ((base "http://localhost:6795/")
|
|
|
|
|
(item (add-text-to-store %store "random" (random-text)))
|
|
|
|
|
(part (store-path-hash-part item))
|
|
|
|
|
(url (string-append base part ".narinfo"))
|
Use "guile-zlib" and "guile-lzlib" instead of (guix config).
* Makefile.am (MODULES): Remove guix/zlib.scm and guix/lzlib.scm,
(SCM_TESTS): remove tests/zlib.scm, tests/lzlib.scm.
* build-aux/build-self.scm (make-config.scm): Remove unused %libz variable.
* configure.ac: Remove LIBZ and LIBLZ variables and check instead for
Guile-zlib and Guile-lzlib.
* doc/guix.texi ("Requirements"): Remove zlib requirement and add Guile-zlib
and Guile-lzlib instead.
* gnu/packages/package-management.scm (guix)[native-inputs]: Add "guile-zlib"
and "guile-lzlib",
[inputs]: remove "zlib" and "lzlib",
[propagated-inputs]: ditto,
[arguments]: add "guile-zlib" and "guile-lzlib" to Guile load path.
* guix/config.scm.in (%libz, %liblz): Remove them.
* guix/lzlib.scm: Remove it.
* guix/man-db.scm: Use (zlib) instead of (guix zlib).
* guix/profiles.scm (manual-database): Do not stub (guix config) in imported
modules list, instead add "guile-zlib" to the extension list.
* guix/scripts/publish.scm: Use (zlib) instead of (guix zlib) and (lzlib)
instead of (guix lzlib),
(string->compression-type, effective-compression): do not check for zlib and
lzlib availability.
* guix/scripts/substitute.scm (%compression-methods): Do not check for lzlib
availability.
* guix/self.scm (specification->package): Add "guile-zlib" and "guile-lzlib"
and remove "zlib" and "lzlib",
(compiled-guix): remove "zlib" and "lzlib" arguments and add guile-zlib and
guile-lzlib to the dependencies, also do not pass "zlib" and "lzlib" to
"make-config.scm" procedure,
(make-config.scm): remove "zlib" and "lzlib" arguments as well as %libz and
%liblz variables.
* guix/utils.scm (lzip-port): Use (lzlib) instead of (guix lzlib) and do not
check for lzlib availability.
* guix/zlib.scm: Remove it.
* m4/guix.m4 (GUIX_LIBZ_LIBDIR, GUIX_LIBLZ_FILE_NAME): Remove them.
* tests/lzlib.scm: Use (zlib) instead of (guix zlib) and (lzlib)
instead of (guix lzlib), and do not check for zlib and lzlib availability.
* tests/publish.scm: Ditto.
* tests/substitute.scm: Do not check for lzlib availability.
* tests/utils.scm: Ditto.
* tests/zlib.scm: Remove it.
2020-07-27 14:36:39 +00:00
|
|
|
|
(cached (string-append cache "/gzip/"
|
2019-05-25 23:18:53 +00:00
|
|
|
|
(basename item)
|
|
|
|
|
".narinfo"))
|
|
|
|
|
(response (http-get url)))
|
2020-10-24 14:31:18 +00:00
|
|
|
|
(and (= 200 (response-code response)) ;we're below the threshold
|
2019-05-25 23:18:53 +00:00
|
|
|
|
(wait-for-file cached)
|
|
|
|
|
(begin
|
|
|
|
|
(delete-paths %store (list item))
|
|
|
|
|
(response-code (pk 'response (http-get url))))))))))
|
|
|
|
|
|
2020-10-24 14:31:18 +00:00
|
|
|
|
(test-equal "with cache, cache bypass"
|
|
|
|
|
200
|
|
|
|
|
(call-with-temporary-directory
|
|
|
|
|
(lambda (cache)
|
|
|
|
|
(let ((thread (with-separate-output-ports
|
|
|
|
|
(call-with-new-thread
|
|
|
|
|
(lambda ()
|
|
|
|
|
(guix-publish "--port=6788" "-C" "gzip"
|
|
|
|
|
(string-append "--cache=" cache)))))))
|
|
|
|
|
(wait-until-ready 6788)
|
|
|
|
|
|
|
|
|
|
(let* ((base "http://localhost:6788/")
|
|
|
|
|
(item (add-text-to-store %store "random" (random-text)))
|
|
|
|
|
(part (store-path-hash-part item))
|
|
|
|
|
(narinfo (string-append base part ".narinfo"))
|
|
|
|
|
(nar (string-append base "nar/gzip/" (basename item)))
|
|
|
|
|
(cached (string-append cache "/gzip/" (basename item)
|
|
|
|
|
".narinfo")))
|
|
|
|
|
;; We're below the default cache bypass threshold, so NAR and NARINFO
|
|
|
|
|
;; should immediately return 200. The NARINFO request should trigger
|
|
|
|
|
;; caching, and the next request to NAR should return 200 as well.
|
|
|
|
|
(and (let ((response (pk 'r1 (http-get nar))))
|
|
|
|
|
(and (= 200 (response-code response))
|
|
|
|
|
(not (response-content-length response)))) ;not known
|
|
|
|
|
(= 200 (response-code (http-get narinfo)))
|
|
|
|
|
(begin
|
|
|
|
|
(wait-for-file cached)
|
|
|
|
|
(let ((response (pk 'r2 (http-get nar))))
|
|
|
|
|
(and (> (response-content-length response)
|
|
|
|
|
(stat:size (stat item)))
|
|
|
|
|
(response-code response))))))))))
|
|
|
|
|
|
2020-11-04 14:57:00 +00:00
|
|
|
|
(test-equal "with cache, cache bypass, unmapped hash part"
|
|
|
|
|
200
|
|
|
|
|
|
|
|
|
|
;; This test reproduces the bug described in <https://bugs.gnu.org/44442>:
|
|
|
|
|
;; the daemon connection would be closed as a side effect of a nar request
|
|
|
|
|
;; for a non-existing file name.
|
|
|
|
|
(call-with-temporary-directory
|
|
|
|
|
(lambda (cache)
|
|
|
|
|
(let ((thread (with-separate-output-ports
|
|
|
|
|
(call-with-new-thread
|
|
|
|
|
(lambda ()
|
|
|
|
|
(guix-publish "--port=6787" "-C" "gzip"
|
|
|
|
|
(string-append "--cache=" cache)))))))
|
|
|
|
|
(wait-until-ready 6787)
|
|
|
|
|
|
|
|
|
|
(let* ((base "http://localhost:6787/")
|
|
|
|
|
(item (add-text-to-store %store "random" (random-text)))
|
|
|
|
|
(part (store-path-hash-part item))
|
|
|
|
|
(narinfo (string-append base part ".narinfo"))
|
|
|
|
|
(nar (string-append base "nar/gzip/" (basename item)))
|
|
|
|
|
(cached (string-append cache "/gzip/" (basename item)
|
|
|
|
|
".narinfo")))
|
|
|
|
|
;; The first response used to be 500 and to terminate the daemon
|
|
|
|
|
;; connection as a side effect.
|
|
|
|
|
(and (= (response-code
|
|
|
|
|
(http-get (string-append base "nar/gzip/"
|
|
|
|
|
(make-string 32 #\e)
|
|
|
|
|
"-does-not-exist")))
|
|
|
|
|
404)
|
|
|
|
|
(= 200 (response-code (http-get nar)))
|
|
|
|
|
(= 200 (response-code (http-get narinfo)))
|
|
|
|
|
(begin
|
|
|
|
|
(wait-for-file cached)
|
|
|
|
|
(response-code (http-get nar)))))))))
|
|
|
|
|
|
2018-01-04 23:19:35 +00:00
|
|
|
|
(test-equal "/log/NAME"
|
|
|
|
|
`(200 #t application/x-bzip2)
|
|
|
|
|
(let ((drv (run-with-store %store
|
|
|
|
|
(gexp->derivation "with-log"
|
|
|
|
|
#~(call-with-output-file #$output
|
|
|
|
|
(lambda (port)
|
|
|
|
|
(display "Hello, build log!"
|
|
|
|
|
(current-error-port))
|
2018-03-22 11:54:31 +00:00
|
|
|
|
(display #$(random-text) port)))))))
|
2018-01-04 23:19:35 +00:00
|
|
|
|
(build-derivations %store (list drv))
|
|
|
|
|
(let* ((response (http-get
|
|
|
|
|
(publish-uri (string-append "/log/"
|
|
|
|
|
(basename (derivation->output-path drv))))
|
|
|
|
|
#:decode-body? #f))
|
|
|
|
|
(base (basename (derivation-file-name drv)))
|
|
|
|
|
(log (string-append (dirname %state-directory)
|
|
|
|
|
"/log/guix/drvs/" (string-take base 2)
|
|
|
|
|
"/" (string-drop base 2) ".bz2")))
|
|
|
|
|
(list (response-code response)
|
|
|
|
|
(= (response-content-length response) (stat:size (stat log)))
|
|
|
|
|
(first (response-content-type response))))))
|
|
|
|
|
|
2021-05-11 13:01:00 +00:00
|
|
|
|
(test-equal "negative TTL"
|
|
|
|
|
`(404 42)
|
|
|
|
|
|
|
|
|
|
(call-with-temporary-directory
|
|
|
|
|
(lambda (cache)
|
|
|
|
|
(let ((thread (with-separate-output-ports
|
|
|
|
|
(call-with-new-thread
|
|
|
|
|
(lambda ()
|
|
|
|
|
(guix-publish "--port=6786" "-C0"
|
|
|
|
|
"--negative-ttl=42s"))))))
|
|
|
|
|
(wait-until-ready 6786)
|
|
|
|
|
|
|
|
|
|
(let* ((base "http://localhost:6786/")
|
|
|
|
|
(url (string-append base (make-string 32 #\z)
|
|
|
|
|
".narinfo"))
|
|
|
|
|
(response (http-get url)))
|
|
|
|
|
(list (response-code response)
|
|
|
|
|
(match (assq-ref (response-headers response) 'cache-control)
|
|
|
|
|
((('max-age . ttl)) ttl)
|
|
|
|
|
(_ #f))))))))
|
|
|
|
|
|
|
|
|
|
(test-equal "no negative TTL"
|
|
|
|
|
`(404 #f)
|
|
|
|
|
(let* ((uri (publish-uri
|
|
|
|
|
(string-append "/" (make-string 32 #\z)
|
|
|
|
|
".narinfo")))
|
|
|
|
|
(response (http-get uri)))
|
|
|
|
|
(list (response-code response)
|
|
|
|
|
(assq-ref (response-headers response) 'cache-control))))
|
|
|
|
|
|
2018-01-04 23:19:35 +00:00
|
|
|
|
(test-equal "/log/NAME not found"
|
|
|
|
|
404
|
|
|
|
|
(let ((uri (publish-uri "/log/does-not-exist")))
|
|
|
|
|
(response-code (http-get uri))))
|
|
|
|
|
|
2020-10-20 20:32:02 +00:00
|
|
|
|
(test-equal "/signing-key.pub"
|
|
|
|
|
200
|
|
|
|
|
(response-code (http-get (publish-uri "/signing-key.pub"))))
|
|
|
|
|
|
2018-03-22 11:51:23 +00:00
|
|
|
|
(test-equal "non-GET query"
|
|
|
|
|
'(200 404)
|
|
|
|
|
(let ((path (string-append "/" (store-path-hash-part %item)
|
|
|
|
|
".narinfo")))
|
|
|
|
|
(map response-code
|
|
|
|
|
(list (http-get (publish-uri path))
|
|
|
|
|
(http-post (publish-uri path))))))
|
|
|
|
|
|
2015-03-17 14:21:31 +00:00
|
|
|
|
(test-end "publish")
|