[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet-scheme] 37/324: scripts: publish-store: publish individual files
From: |
gnunet |
Subject: |
[gnunet-scheme] 37/324: scripts: publish-store: publish individual files |
Date: |
Tue, 21 Sep 2021 13:21:17 +0200 |
This is an automated email from the git hooks/post-receive script.
maxime-devos pushed a commit to branch master
in repository gnunet-scheme.
commit 314b0962e97ed83b7f5887615920487cdc481e63
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Sat Jan 23 14:20:49 2021 +0100
scripts: publish-store: publish individual files
FIXME: respect anonymity, simulate, ...
* gnu/gnunet/scripts/publish-sore.scm
(sxml-data-files): new procedure, returning a list of file names.
(publish-object): new procedure, publishing an object via GNUnet.
(gnunet-publish): new procedure, calling the `gnunet-publish'
binary appropriately.
(extract-uri): new procedure, extracting the URI from `gnunet-publish'
output.
(gnunet-publish-uri-regexp): new variable
(publish-nar): call publish-object on each regular file
---
gnu/gnunet/scripts/publish-store.scm | 102 ++++++++++++++++++++++++++++++++---
1 file changed, 96 insertions(+), 6 deletions(-)
diff --git a/gnu/gnunet/scripts/publish-store.scm
b/gnu/gnunet/scripts/publish-store.scm
index a0aedd7..9059506 100644
--- a/gnu/gnunet/scripts/publish-store.scm
+++ b/gnu/gnunet/scripts/publish-store.scm
@@ -38,6 +38,13 @@
stat:type
stat:perms
stat:size)
+ (guile)
+ (rnrs bytevectors)
+ (ice-9 binary-ports)
+ (ice-9 textual-ports)
+ (ice-9 regex)
+ (ice-9 popen)
+ (ice-9 rdelim)
(sxml match)
(only (ice-9 optargs)
define*))
@@ -86,11 +93,85 @@ GNUnet options
#:config (option-ref options 'config #f)))
(else ???))))
- (define* (publish-nar #:key input simulate config)
- ;; FIXME use this
- (display (store-item->sxml input))
- (newline)
- ???)
+ (define* (publish-nar #:key input
+ #:allow-other-keys
+ #:rest r)
+ (let* ((sxml (store-item->sxml input))
+ (data-files (sxml-data-files sxml))
+ (publish-object
+ (lambda (object)
+ (apply publish-object object r))))
+ ;; Insert each regular file
+ (for-each (lambda (a)
+ (display (publish-object a))
+ (newline))
+ data-files)
+ ;; FIXME also write directories
+ '???
+ ))
+
+ (define gnunet-publish-uri-regexp
+ (make-regexp "\\b(gnunet://fs/chk/([A-Z0-9]+).([A-Z0-9]+).[0-9]+)\\b"))
+ (define (extract-uri output)
+ (match:substring (regexp-exec gnunet-publish-uri-regexp output) 1))
+
+ (define* (gnunet-publish file
+ #:key
+ ;; FIXME this shouldn't matter
+ input
+ (config (string-append
+ (getenv "HOME")
+ "/.config/gnunet.conf"))
+ (simulate #f)
+ (anonymity 1)
+ (priority 360)
+ (replication 0)
+ (noindex #f))
+ "Run the GNUnet publish binary, and return the computed hash
+as a string."
+ (setenv "LC_ALL" "C")
+ (let* ((*binary* "gnunet-publish")
+ (cmd `(,*binary*
+ "--disable-extractor"
+ "-a" ,(number->string anonymity)
+ "-p" ,(number->string priority)
+ "-r" ,(number->string replication)
+ ,@(if config
+ `("-c" ,config)
+ '())
+ ,@(if simulate
+ '("-s")
+ '("-s"))
+ ,@(if noindex
+ '("-n")
+ '())
+ "--"
+ ,file))
+ (pipe (apply open-pipe* OPEN_READ cmd))
+ (text-0 (read-line pipe))
+ (text-1 (read-line pipe))
+ (ret (close-pipe pipe)))
+ (unless (= ret 0)
+ ;; XXX
+ (throw 'gnunet-publish-eep 'gnunet-publish-???))
+ (extract-uri text-1)))
+
+ (define* (publish-object data
+ #:key
+ #:allow-other-keys
+ #:rest r)
+ "Publish DATA, a bytevector or filename, and return
+the resulting GNUnet FS URI. If SIMULATE is #t, do not
+actually publish the file, only compute its hash."
+ (cond ((bytevector? data)
+ (call-with-temporary-output-file
+ (lambda (name port)
+ (put-bytevector port data)
+ (close-port port)
+ (apply gnunet-publish name
+ #:no-index #t r))))
+ ((string? data)
+ (apply gnunet-publish data r))))
(define (store-item->sxml filename)
(let* ((name (basename filename))
@@ -122,4 +203,13 @@ GNUnet options
(map (lambda (name)
(let ((file (string-append filename "/" name)))
(store-item->sxml file)))
- names)))))
+ names)))
+
+ (define (sxml-data-files sxml)
+ (sxml-match sxml
+ ((regular (@ (data-from-file ,filename)))
+ (list filename))
+ ((symlink) '())
+ ((directory ,(entry) ...)
+ (append entry ...))))))
+
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet-scheme] 26/324: Port meta-data-serialize/uncached, (continued)
- [gnunet-scheme] 26/324: Port meta-data-serialize/uncached, gnunet, 2021/09/21
- [gnunet-scheme] 29/324: Define meta data structures systematically, gnunet, 2021/09/21
- [gnunet-scheme] 31/324: fix netstruct, and implement wrap-reader-setter, gnunet, 2021/09/21
- [gnunet-scheme] 28/324: Define library for structures, gnunet, 2021/09/21
- [gnunet-scheme] 34/324: scripts: add incomplete script for publishing a store item, gnunet, 2021/09/21
- [gnunet-scheme] 33/324: include some notes on reverse-engineering GNUdirs, gnunet, 2021/09/21
- [gnunet-scheme] 36/324: scripts: publish-store: eliminate add-name, gnunet, 2021/09/21
- [gnunet-scheme] 32/324: remove some uses of old accessors, gnunet, 2021/09/21
- [gnunet-scheme] 41/324: scripts: publish-store: fix predicate of --format option, gnunet, 2021/09/21
- [gnunet-scheme] 38/324: scripts: publish-store: publish whole trees, gnunet, 2021/09/21
- [gnunet-scheme] 37/324: scripts: publish-store: publish individual files,
gnunet <=
- [gnunet-scheme] 40/324: scripts: publish-store: allow setting all options, gnunet, 2021/09/21
- [gnunet-scheme] 39/324: guix: suggest a package definition, gnunet, 2021/09/21
- [gnunet-scheme] 35/324: scripts: publish-store: compute file tree, gnunet, 2021/09/21
- [gnunet-scheme] 43/324: scripts: publish-store: exit after main function, gnunet, 2021/09/21
- [gnunet-scheme] 48/324: scripts: download-store: download json container, gnunet, 2021/09/21
- [gnunet-scheme] 45/324: scripts: publish-store: fix '--config' option parsing, gnunet, 2021/09/21
- [gnunet-scheme] 46/324: scripts: download-store: parse input arguments, gnunet, 2021/09/21
- [gnunet-scheme] 42/324: scripts: publish-store: export some procedures, gnunet, 2021/09/21
- [gnunet-scheme] 44/324: doc: document publish-store.scm, gnunet, 2021/09/21
- [gnunet-scheme] 53/324: doc: add a section on Guix in the roadmap, gnunet, 2021/09/21