aboutsummaryrefslogtreecommitdiff
path: root/guix/build/utils.scm
diff options
context:
space:
mode:
authorAttila Lendvai <attila@lendvai.name>2021-10-03 14:43:01 +0200
committerLiliana Marie Prikler <liliana.prikler@gmail.com>2022-09-02 17:04:46 +0200
commite4adc665e1ce4fe5341eda12157460ac3bd87aec (patch)
treed49a6d46ba0e957515bb25e4e83241d82dc1e228 /guix/build/utils.scm
parent54c365d6457fd19479f3cea797196240a73299bf (diff)
downloadguix-e4adc665e1ce4fe5341eda12157460ac3bd87aec.tar
guix-e4adc665e1ce4fe5341eda12157460ac3bd87aec.tar.gz
guix: build: Avoid using magic literals in the code for hash length.
* guix/build/utils.scm (%store-hash-string-length): New constant. (store-path-prefix-length): Factor out the calculation of the total store prefix length. * guix/build/graft.scm (hash-length): Use it. Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com>
Diffstat (limited to 'guix/build/utils.scm')
-rw-r--r--guix/build/utils.scm11
1 files changed, 9 insertions, 2 deletions
diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index 3570de81e9..2352a627e9 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -48,6 +48,7 @@
;; <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26805#16>.
delete)
#:export (%store-directory
+ %store-hash-string-length
store-file-name?
strip-store-file-name
package-name->name+version
@@ -198,15 +199,21 @@ compression."
(getenv "NIX_STORE") ;inside builder, set by the daemon
"/gnu/store"))
+(define-constant %store-hash-string-length 32)
+
(define (store-file-name? file)
"Return true if FILE is in the store."
(string-prefix? (%store-directory) file))
+(define (store-path-prefix-length)
+ (+ 2 ; the slash after %store-directory, and the dash after the hash
+ (string-length (%store-directory))
+ %store-hash-string-length))
+
(define (strip-store-file-name file)
"Strip the '/gnu/store' and hash from FILE, a store file name. The result
is typically a \"PACKAGE-VERSION\" string."
- (string-drop file
- (+ 34 (string-length (%store-directory)))))
+ (string-drop file (store-path-prefix-length)))
(define (package-name->name+version name)
"Given NAME, a package name like \"foo-0.9.1b\", return two values: