From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 2B0IKp2lWWEHiAAAgWs5BA (envelope-from ) for ; Sun, 03 Oct 2021 14:44:13 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id qMGJJZ2lWWFTRQAAbx9fmQ (envelope-from ) for ; Sun, 03 Oct 2021 12:44:13 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1FA8814E0D for ; Sun, 3 Oct 2021 14:44:13 +0200 (CEST) Received: from localhost ([::1]:36666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mX0qi-0006ig-5A for larch@yhetil.org; Sun, 03 Oct 2021 08:44:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mX0qY-0006iE-Kp for guix-patches@gnu.org; Sun, 03 Oct 2021 08:44:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:49790) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mX0qY-0000v3-DV for guix-patches@gnu.org; Sun, 03 Oct 2021 08:44:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mX0qY-0006Iz-Ba for guix-patches@gnu.org; Sun, 03 Oct 2021 08:44:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50878] [PATCH 2/4] guix: build: Avoid using magic literals in the code for hash length. Resent-From: Attila Lendvai Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 03 Oct 2021 12:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50878 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 50878@debbugs.gnu.org Cc: Attila Lendvai Received: via spool by 50878-submit@debbugs.gnu.org id=B50878.163326502124180 (code B ref 50878); Sun, 03 Oct 2021 12:44:02 +0000 Received: (at 50878) by debbugs.gnu.org; 3 Oct 2021 12:43:41 +0000 Received: from localhost ([127.0.0.1]:33099 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mX0qD-0006Hw-Jp for submit@debbugs.gnu.org; Sun, 03 Oct 2021 08:43:41 -0400 Received: from mail-wr1-f49.google.com ([209.85.221.49]:42705) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mX0qB-0006HX-P2 for 50878@debbugs.gnu.org; Sun, 03 Oct 2021 08:43:40 -0400 Received: by mail-wr1-f49.google.com with SMTP id v17so24963354wrv.9 for <50878@debbugs.gnu.org>; Sun, 03 Oct 2021 05:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uqZpcjgK26RLLT/WLa+olTb/Q4pV96js45ePYWQnTfI=; b=bg+EurDb+8CLS73wQ4Fk1O94z2VCyl03Nhwc1wXSK+gNRIXo2jJy2FUZxxrI1AqTJm kT2KgHV8GRSNcH0q6PMKAyKrpP62b7ZL4EZFgk90m9ccVC5RAoK9syne9RRyhYlz0B3l AGtkAqsvW6cLLjdwhqOgqqrlDusWMiHCTv+X0/JRGJm5orlJUSCwhJZgFLRNtx0VCZPx cVxFWCWFc0O/1qhV4K98w1la/N2L1jn1cHdAPqEWQD0iC2TPUCq9Cldb9duGZypeP5Jj nDicRe5ZCWmCrksrwjaDkz8FHVT9EVRO+57xj+gN44hmI1yPPG0uKVnPdaqdNq2MV11b Go0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=uqZpcjgK26RLLT/WLa+olTb/Q4pV96js45ePYWQnTfI=; b=0wIU1o+20TekbNVaH37vqCkVAHawY290lugRgImd/gtJfzQ8CIRjNMLSdYnpM3+y4T bRoCjrRR1Dt4mB9+5AVXVc0kAbXzQD3zL4o+7jNRgJ4sPOQj95F1YsdLkqIZW6T2vjy6 e2G6+BS6Mxueold3MXS3hYvxo1ACy6mXlG0dhmNgD4xO2Cmkdp/IMcnsutiL+d6CP5mC fzgZZ6WWxdzmxRlC3oO3PnGJYacl0gYd1H5aqZElacUITii6vsruZSINS8jagrKYvUDt 42QjA7TNl+BHK7Nu+fbRpMVal8baCG9bNwDl4AxgUJq51D4cr+2s6X6Rrd/z92t1/FAX 8Mnw== X-Gm-Message-State: AOAM531pgBVCrjJKfVrOZYavgQius/bIzJ1Jxs5f5HRW7aVph5E957AU zU0carup4d/dBcQ268sCS+blehtEhCk= X-Google-Smtp-Source: ABdhPJwyD56BtOvKHklNLHykixhFxgNsdsIgCPWYcqy0aLJ3NAP7jv0OPYXkBgRHmBSszPOV5mnElw== X-Received: by 2002:a5d:49c5:: with SMTP id t5mr8561843wrs.295.1633265014109; Sun, 03 Oct 2021 05:43:34 -0700 (PDT) Received: from lelap.lan (catv-213-222-131-28.catv.broadband.hu. [213.222.131.28]) by smtp.gmail.com with ESMTPSA id v10sm11800474wri.29.2021.10.03.05.43.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 05:43:33 -0700 (PDT) From: Attila Lendvai Date: Sun, 3 Oct 2021 14:43:01 +0200 Message-Id: <20211003124303.8277-2-attila@lendvai.name> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211003124303.8277-1-attila@lendvai.name> References: <20211003124303.8277-1-attila@lendvai.name> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1633265053; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=uqZpcjgK26RLLT/WLa+olTb/Q4pV96js45ePYWQnTfI=; b=CUesTHMSfaXjFI95v5kB9eMXqgY4uOxM/ZHDqYSg6qANP9CGNsXxiAFw8woh6OTlXIwAiA 3cgkoeV5kXjkQ243l0X+8SSfT4i9heFkICurBxge+IhSsih9yYeS5Mn2Ljh9ABpvEjRFkD wwJeC/m/WG0n0+Dc62Qhg3MMNk+HtGZeqxsMIV+2UW8R5Ce3nAtHYR6t7HJZ71VPqRpFOC IM9Hbg78guPOvk0djaPG8V6qxY9/DHIw+F261X+kGQ7k+aHR2sNgSjciUYYE3QqSO2GXBx SduBw3YPHEDK/dAZuTdTcOtGpXcednlFRljMuInvOr06Fmncg46Xu3ZJOTbKCw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1633265053; a=rsa-sha256; cv=none; b=eB0DpadIbU3jsLgFIwNMvNjXUqPxY2ch8PAGQmRhb2i5t45LoCTb3waARs5U99JMgt8cEi q7lKe4AbOLZGksjHZj895hGdTtEtdnR/i0RKAapC3iZLgtpU5zmY8TQGU/2fcrBlv1FfNv lnJFlN8Q6JF542ywqv6Z373EQeucgJQmVSEiQMgL+K2TPs7jJw/LmqYotXLdYYcFQYrBD1 Z00vNjL/ULt7QQx/tVwSTpFzUWhM7/uFqpuE3N5i4Ec6P5ucKQZd9bnICXrT33Z/S/07CB qFUteFOkqXb+ZbGxyjNxHB+y9HsI14OjvCu/teRiqCZUdDi9BYwmqwoke1nF8w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=bg+EurDb; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 3.59 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=bg+EurDb; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 1FA8814E0D X-Spam-Score: 3.59 X-Migadu-Scanner: scn0.migadu.com X-TUID: ndPe8WNGnrpe * 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. --- 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 f3d913aa70..4009c137b8 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -44,6 +44,7 @@ ;; . delete) #:export (%store-directory + %store-hash-string-length store-file-name? strip-store-file-name package-name->name+version @@ -154,15 +155,21 @@ (or (getenv "NIX_STORE") "/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: -- 2.33.0