unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: David Thompson <dthompson2@worcester.edu>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: guix-devel@gnu.org
Subject: Re: [PATCH 1/2] store: Add query-path-info operation.
Date: Fri, 27 Mar 2015 12:56:58 -0400	[thread overview]
Message-ID: <87zj6ygyzp.fsf@fsf.org> (raw)
In-Reply-To: <878ueuk7m8.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1012 bytes --]

Ludovic Courtès <ludo@gnu.org> writes:

> David Thompson <dthompson2@worcester.edu> skribis:
>
>> From e72bd43190bd561f7d96810a93f3b30f5f741343 Mon Sep 17 00:00:00 2001
>> From: David Thompson <dthompson2@worcester.edu>
>> Date: Tue, 17 Mar 2015 10:19:36 -0400
>> Subject: [PATCH 1/2] store: Add query-path-info operation.
>>
>> * guix/store.scm (<path-info>): New record type.
>>   (read-path-info): New procedure.
>>   (read-arg): Add 'path-info' syntax.
>>   (query-path-info): New variable.
>
> [...]
>
>> +  (reg-time path-info-reg-time)
>
> Please change the procedure name to ‘path-info-registration-time’.
>
>> +(define-operation (query-path-info (store-path path))
>> +  "Return the derivation store path for PATH."
>> +  path-info)
>
> Invalid docstring.
>
> Could you add a test in tests/store.scm?  It could add a file with
> ‘add-text-to-store’, with a non-empty reference list, and check its
> references and hash, for instance.

Done.

New patch below.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-store-Add-query-path-info-operation.patch --]
[-- Type: text/x-diff, Size: 3873 bytes --]

From d86678e29c951ae4983cea92074e8f04c3e49f50 Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Tue, 17 Mar 2015 10:19:36 -0400
Subject: [PATCH 1/2] store: Add query-path-info operation.

* guix/store.scm (<path-info>): New record type.
  (read-path-info): New procedure.
  (read-arg): Add 'path-info' syntax.
  (query-path-info): New variable.
* tests/store.scm ("query-path-info"): New test.
---
 guix/store.scm  | 34 +++++++++++++++++++++++++++++++++-
 tests/store.scm | 10 ++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/guix/store.scm b/guix/store.scm
index 3d6b069..10b9062 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -60,6 +60,7 @@
             valid-path?
             query-path-hash
             hash-part->path
+            query-path-info
             add-text-to-store
             add-to-store
             build-things
@@ -79,6 +80,13 @@
             substitutable-paths
             substitutable-path-info
 
+            path-info?
+            path-info-deriver
+            path-info-hash
+            path-info-references
+            path-info-registration-time
+            path-info-nar-size
+
             references
             requisites
             referrers
@@ -212,6 +220,24 @@
                 (cons (substitutable path deriver refs dl-size nar-size)
                       result))))))
 
+;; Information about a store path.
+(define-record-type <path-info>
+  (path-info deriver hash references registration-time nar-size)
+  path-info?
+  (deriver path-info-deriver)
+  (hash path-info-hash)
+  (references path-info-references)
+  (registration-time path-info-registration-time)
+  (nar-size path-info-nar-size))
+
+(define (read-path-info p)
+  (let ((deriver  (read-store-path p))
+        (hash     (base16-string->bytevector (read-string p)))
+        (refs     (read-store-path-list p))
+        (registration-time (read-int p))
+        (nar-size (read-long-long p)))
+    (path-info deriver hash refs registration-time nar-size)))
+
 (define-syntax write-arg
   (syntax-rules (integer boolean file string string-list string-pairs
                  store-path store-path-list base16)
@@ -236,7 +262,7 @@
 
 (define-syntax read-arg
   (syntax-rules (integer boolean string store-path store-path-list
-                 substitutable-path-list base16)
+                 substitutable-path-list path-info base16)
     ((_ integer p)
      (read-int p))
     ((_ boolean p)
@@ -249,6 +275,8 @@
      (read-store-path-list p))
     ((_ substitutable-path-list p)
      (read-substitutable-path-list p))
+    ((_ path-info p)
+     (read-path-info p))
     ((_ base16 p)
      (base16-string->bytevector (read-string p)))))
 
@@ -541,6 +569,10 @@ string).  Raise an error if no such path exists."
      ;; /HASH.narinfo.
      (query-path-from-hash-part server hash-part))))
 
+(define-operation (query-path-info (store-path path))
+  "Return the info (hash, references, etc.) for PATH."
+  path-info)
+
 (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.
diff --git a/tests/store.scm b/tests/store.scm
index f778c20..eeceed4 100644
--- a/tests/store.scm
+++ b/tests/store.scm
@@ -606,6 +606,16 @@
          (file (add %store "foo" "Lowered.")))
     (call-with-input-file file get-string-all)))
 
+(test-assert "query-path-info"
+  (let* ((ref (add-text-to-store %store "ref" "foo"))
+         (item (add-text-to-store %store "item" "bar" (list ref)))
+         (info (query-path-info %store item)))
+    (and (equal? (path-info-references info) (list ref))
+         (equal? (path-info-hash info)
+                 (sha256
+                  (string->utf8
+                   (call-with-output-string (cut write-file item <>))))))))
+
 (test-end "store")
 
 \f
-- 
2.1.4


[-- Attachment #3: Type: text/plain, Size: 136 bytes --]


-- 
David Thompson
Web Developer - Free Software Foundation - http://fsf.org
GPG Key: 0FF1D807
Support the FSF: https://fsf.org/donate

  reply	other threads:[~2015-03-27 16:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-17 14:57 [PATCH 0/2] Add 'guix publish' command David Thompson
2015-03-17 15:00 ` [PATCH 1/2] store: Add query-path-info operation David Thompson
2015-03-18  8:55   ` Ludovic Courtès
2015-03-27 16:56     ` David Thompson [this message]
2015-03-27 21:30       ` Ludovic Courtès
2015-03-17 15:01 ` [PATCH 2/2] scripts: Add 'publish' command David Thompson
2015-03-18 10:27   ` Ludovic Courtès
2015-03-27 16:58     ` David Thompson
2015-03-27 22:41       ` Ludovic Courtès
2015-03-29 17:02         ` Mark H Weaver
2015-03-29 17:29           ` David Thompson
2015-03-30 19:32             ` Ludovic Courtès
2015-04-04 18:30         ` David Thompson
2015-03-17 15:20 ` [PATCH 0/2] Add 'guix publish' command David Thompson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zj6ygyzp.fsf@fsf.org \
    --to=dthompson2@worcester.edu \
    --cc=guix-devel@gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).