From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id mGmzDlLgJGYpUwAAe85BDQ:P1 (envelope-from ) for ; Sun, 21 Apr 2024 11:45:54 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id mGmzDlLgJGYpUwAAe85BDQ (envelope-from ) for ; Sun, 21 Apr 2024 11:45:54 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1713692754; 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; bh=XlPdyBJGQ+U/Qhx64M/SbRAPpDx9aHSvnL0G249ECSo=; b=YSaRBwqRV6ctptxWO1lIgPBK9u228DdddmCAm16uuCM1hgrpD0MFOY5qyRRUGuo24JgmKF xm6eHwRSVzd+9bXhlsRr0bm+2qhztXVD0BceUpIU4UfxUkWsohBEtIKqlN5Bb6vYpFI0+a LuYOb7K22O8hC6lUtdopGSHCFFxQ4fCiRaN3Ip1PWhqihpt61IuT2nThZURhAsRHgq+J8n JuWf7C0Y2phyXliGd5y+DENHbS03BIQY/u/b6nGvbygNX/W/Mrwt8vGFNeVUMYLg49IYQt rupZUoStCvtk4mfWQUjITUHYJQr5a+P27m20DJYbHPWzRColM5zrJMqX3ha/oA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1713692754; a=rsa-sha256; cv=none; b=TcNLp/vhj6web6XmhiHodn3ab/X6U0djrM5uSFNwdkaTP9mnUpKRCOH+QV+vqdpdRR8gm1 CU7XZ4GBoitJXZpqwj3HrrqfhgOia9EB1glSM31bWNIsK163l33Z+tTiuaNa500xFCkBGB aYrNy+BaF77/W4w5dPPMV5o5/w0axiPp9dFbzzTKWiOpyCu3uhVtjxjLjeXAiYW7qnvccM WPdvQ3txga8wV9Kqn86b88xu5juj8j3/r7tmYh8SPpIcIiJki6vXJ+clJTQ3scQ9YkbKTM uY+ZROb3JsJCu7U1KkElffSP9WECtTikf7mo/nSCwMvQ/AigKLddJ+S0jD/3DA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none 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 1B96E1F909 for ; Sun, 21 Apr 2024 11:45:54 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ryTk0-0005eB-TO; Sun, 21 Apr 2024 05:44:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ryTjm-0005Rz-MS for guix-patches@gnu.org; Sun, 21 Apr 2024 05:43:55 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ryTjm-0002pL-DD; Sun, 21 Apr 2024 05:43:54 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ryTk0-0006VM-1B; Sun, 21 Apr 2024 05:44:08 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70494] [PATCH 10/23] store: database: Add procedures for querying valid paths. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Sun, 21 Apr 2024 09:44:07 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70494 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 70494@debbugs.gnu.org Cc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 70494-submit@debbugs.gnu.org id=B70494.171369262624672 (code B ref 70494); Sun, 21 Apr 2024 09:44:07 +0000 Received: (at 70494) by debbugs.gnu.org; 21 Apr 2024 09:43:46 +0000 Received: from localhost ([127.0.0.1]:41780 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ryTjb-0006Pa-T4 for submit@debbugs.gnu.org; Sun, 21 Apr 2024 05:43:45 -0400 Received: from mira.cbaines.net ([2a01:7e00:e000:2f8:fd4d:b5c7:13fb:3d27]:45147) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ryTiy-0006I6-EY for 70494@debbugs.gnu.org; Sun, 21 Apr 2024 05:43:06 -0400 Received: from localhost (unknown [212.132.255.10]) by mira.cbaines.net (Postfix) with ESMTPSA id 7CFE327BBF2 for <70494@debbugs.gnu.org>; Sun, 21 Apr 2024 10:42:47 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 5123b2fe for <70494@debbugs.gnu.org>; Sun, 21 Apr 2024 09:42:47 +0000 (UTC) From: Christopher Baines Date: Sun, 21 Apr 2024 10:42:28 +0100 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: <87bk632h36.fsf@cbaines.net> References: <87bk632h36.fsf@cbaines.net> 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -3.38 X-Spam-Score: -3.38 X-Migadu-Queue-Id: 1B96E1F909 X-Migadu-Scanner: mx12.migadu.com X-TUID: 6J4UbFU6K1yc * guix/store/database.scm (valid-path, all-valid-paths, valid-path-from-hash-part, valid-path-references): New procedures. Change-Id: Ib08837ee20f5a5a24a8089e611b5d67b003b62cc --- guix/store/database.scm | 88 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/guix/store/database.scm b/guix/store/database.scm index 07bd501644..8a3436368e 100644 --- a/guix/store/database.scm +++ b/guix/store/database.scm @@ -55,9 +55,13 @@ (define-module (guix store database) %epoch reset-timestamps vacuum-database + valid-path + all-valid-paths + valid-path-from-hash-part outputs-exist? file-closure - all-transitive-inputs)) + all-transitive-inputs + valid-path-references)) ;;; Code for working with the store database directly. @@ -447,6 +451,63 @@ (define (vacuum-database) (sqlite-exec db "VACUUM;") (sqlite-close db))) +(define (valid-path db store-filename) + (let ((statement + (sqlite-prepare + db + " +SELECT id, hash, registrationTime, deriver, narSize +FROM ValidPaths +WHERE path = :path" + #:cache? #t))) + + (sqlite-bind-arguments + statement + #:path store-filename) + + (let ((result (sqlite-step statement))) + (sqlite-reset statement) + + result))) + +(define (all-valid-paths db) + (let ((statement + (sqlite-prepare + db + " +SELECT path FROM ValidPaths" + #:cache? #t))) + + (let ((result + (sqlite-map + (match-lambda + (#(path) path)) + statement))) + (sqlite-reset statement) + + result))) + +(define (valid-path-from-hash-part db hash) + (let ((statement + (sqlite-prepare + db + " +SELECT path FROM ValidPaths WHERE path >= :path LIMIT 1" + #:cache? #t)) + (path-prefix + (string-append (%store-prefix) "/" hash))) + + (sqlite-bind-arguments + statement + #:path path-prefix) + + (let ((result + (sqlite-step statement))) + + (if (and result (string-prefix? path-prefix result)) + result + #f)))) + (define (outputs-exist? db drv-path outputs) "Determine whether all output labels in OUTPUTS exist as built outputs of DRV-PATH." @@ -527,3 +588,28 @@ (define (all-transitive-inputs db drv) vlist-null `(,@(derivation-sources drv) ,@input-paths))))) + +(define (valid-path-references db valid-path-id) + (let ((statement + (sqlite-prepare + db + " +SELECT ValidPaths.path +FROM Refs +INNER JOIN ValidPaths ON Refs.reference = ValidPaths.id +WHERE referrer = :id" + #:cache? #t))) + + (sqlite-bind-arguments + statement + #:id valid-path-id) + + (let ((result (sqlite-fold + (lambda (row result) + (cons (vector-ref row 0) + result)) + '() + statement))) + (sqlite-reset statement) + + result))) -- 2.41.0