mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-11-07 07:26:13 -05:00
store: Add 'hash-part->path'.
* guix/store.scm (hash-part->path): New procedure. * tests/store.scm ("hash-part->path"): New test.
This commit is contained in:
parent
1a8ea0a188
commit
11e7a6cf46
2 changed files with 19 additions and 1 deletions
|
@ -57,6 +57,7 @@ (define-module (guix store)
|
|||
set-build-options
|
||||
valid-path?
|
||||
query-path-hash
|
||||
hash-part->path
|
||||
add-text-to-store
|
||||
add-to-store
|
||||
build-derivations
|
||||
|
@ -501,6 +502,18 @@ (define-operation (query-path-hash (store-path path))
|
|||
"Return the SHA256 hash of PATH as a bytevector."
|
||||
base16)
|
||||
|
||||
(define hash-part->path
|
||||
(let ((query-path-from-hash-part
|
||||
(operation (query-path-from-hash-part (string hash))
|
||||
#f
|
||||
store-path)))
|
||||
(lambda (server hash-part)
|
||||
"Return the store path whose hash part is HASH-PART (a nix-base32
|
||||
string). Raise an error if no such path exists."
|
||||
;; This RPC is primarily used by Hydra to reply to HTTP GETs of
|
||||
;; /HASH.narinfo.
|
||||
(query-path-from-hash-part server hash-part))))
|
||||
|
||||
(define add-text-to-store
|
||||
;; A memoizing version of `add-to-store', to avoid repeated RPCs with
|
||||
;; the very same arguments during a given session.
|
||||
|
|
|
@ -87,7 +87,12 @@ (define (random-text)
|
|||
(%store-prefix)
|
||||
"/283gqy39v3g9dxjy26rynl0zls82fmcg-guile-2.0.7/bin/guile")))))
|
||||
|
||||
(test-skip (if %store 0 10))
|
||||
(test-skip (if %store 0 11))
|
||||
|
||||
(test-assert "hash-part->path"
|
||||
(let ((p (add-text-to-store %store "hello" "hello, world")))
|
||||
(equal? (hash-part->path %store (store-path-hash-part p))
|
||||
p)))
|
||||
|
||||
(test-assert "dead-paths"
|
||||
(let ((p (add-text-to-store %store "random-text" (random-text))))
|
||||
|
|
Loading…
Reference in a new issue