[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
05/06: guix: build: Avoid using magic literals in the code for hash leng
From: |
guix-commits |
Subject: |
05/06: guix: build: Avoid using magic literals in the code for hash length. |
Date: |
Fri, 2 Sep 2022 11:57:59 -0400 (EDT) |
lilyp pushed a commit to branch core-updates
in repository guix.
commit e4adc665e1ce4fe5341eda12157460ac3bd87aec
Author: Attila Lendvai <attila@lendvai.name>
AuthorDate: Sun Oct 3 14:43:01 2021 +0200
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>
---
guix/build/graft.scm | 2 +-
guix/build/utils.scm | 11 +++++++++--
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/guix/build/graft.scm b/guix/build/graft.scm
index daac958d4f..281dbaba6f 100644
--- a/guix/build/graft.scm
+++ b/guix/build/graft.scm
@@ -44,7 +44,7 @@
;;;
;;; Code:
-(define-constant hash-length 32)
+(define-constant hash-length %store-hash-string-length)
(define nix-base32-char?
(cute char-set-contains?
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:
- branch core-updates updated (08380429b8 -> 42e3089752), guix-commits, 2022/09/02
- 05/06: guix: build: Avoid using magic literals in the code for hash length.,
guix-commits <=
- 04/06: guix: build: Promote local define-inline to a define-constant util., guix-commits, 2022/09/02
- 06/06: guix: build: Factor out default collision-resolver., guix-commits, 2022/09/02
- 01/06: gnu: gtk: Add missing input., guix-commits, 2022/09/02
- 02/06: gnu: gtksourceview: Update to 5.4.2., guix-commits, 2022/09/02
- 03/06: gnu: Make gtksourceview-5 the default gtksourceview., guix-commits, 2022/09/02