[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet-scheme] 280/324: config/fs: Locate the user and system configura
From: |
gnunet |
Subject: |
[gnunet-scheme] 280/324: config/fs: Locate the user and system configuration. |
Date: |
Tue, 21 Sep 2021 13:25:20 +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 f11480492afc4b14554360f53f58cd89fcb1f50a
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Sun Sep 12 21:47:10 2021 +0200
config/fs: Locate the user and system configuration.
* Makefile.am (modules): Add new module.
(SCM_TESTS): Add new tests.
* doc/scheme-gnunet.tm (Locating configuration files): New section.
* gnu/gnunet/config/fs.scm: New module.
* tests/config-fs.scm: New test file.
---
Makefile.am | 2 ++
doc/scheme-gnunet.tm | 58 ++++++++++++++++++++++++++++++++++++++++++
gnu/gnunet/config/fs.scm | 64 +++++++++++++++++++++++++++++++++++++++++++++++
tests/config-fs.scm | 65 ++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 189 insertions(+)
diff --git a/Makefile.am b/Makefile.am
index 8ed4ab5..536c705 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -59,6 +59,7 @@ modules = \
gnu/gnunet/config/value-parser.scm \
gnu/gnunet/config/expand.scm \
gnu/gnunet/config/db.scm \
+ gnu/gnunet/config/fs.scm \
\
gnu/gnunet/util/cmsg.scm \
gnu/gnunet/util/time.scm \
@@ -161,6 +162,7 @@ SCM_TESTS = \
tests/config-value-parser.scm \
tests/config-expand.scm \
tests/config-db.scm \
+ tests/config-fs.scm \
tests/netstruct.scm \
tests/time.scm \
tests/tokeniser.scm
diff --git a/doc/scheme-gnunet.tm b/doc/scheme-gnunet.tm
index 01234b1..a6c2ad2 100644
--- a/doc/scheme-gnunet.tm
+++ b/doc/scheme-gnunet.tm
@@ -93,6 +93,64 @@
<section|Configuration>
+ <subsection|Locating configuration files>
+
+ There are two \U possibly non-existent \U configuration files: the
+ <with|font-shape|italic|user> configuration and the
+ <with|font-shape|italic|system> configuration.<space|1em>The
+ <with|font-shape|italic|system> configuration typically contains the paths
+ for services like NSE, CORE, <text-dots><space|1em>A user may choose not to
+ use the services by the system and instead use their own.<space|1em>To do
+ so, the user needs to override the paths in the
+ <with|font-shape|italic|user> configuration.<space|1em><todo|defaults?> The
+ module <scm|(gnu gnunet config fs)> is responsible for determining the
+ location of the configuration files to load and actually load configuration
+ files.<space|1em>For determining the location of the configuration files,
+ the procedures <scm|locate-user-configuration> and
+ <scm|locate-system-configuration> can be used.
+
+ <\warning>
+ The C implementation's mechanism for user-system separation seems to work
+ differently.
+ </warning>
+
+ <\explain>
+ <scm|(locate-user-configuration <scm|#:getenv=getenv>)>
+ <|explain>
+ This procedure determines the location of the user configuration file, as
+ a string, or <scm|#false> if it could not be determined.<space|1em>If the
+ location of the user configuration file is known, but the file does not
+ exist, it is returned anyway, as a string.
+
+ If the environment variable <shell|XDG_CONFIG_HOME> is set, the location
+ of the file <verbatim|gnunet.conf> in the directory
+ <shell|$XDG_CONFIG_HOME> is returned.<space|1em>If the environment
+ variable is not set, the location of the file at
+ <verbatim|.config/gnunet.conf> in the home directory specified by the
+ environment variable <verbatim|HOME> is returned, if that environment
+ variable exists.<space|1em>If both are unset, <scm|#false> is returned.
+
+ The values of environment variables is determined with the procedure
+ <scm|getenv>.
+ </explain>
+
+ <\explain>
+ <scm|(locate-system-configuration)>
+ <|explain>
+ This procedure determines the location of the system configuration file,
+ as a string.
+
+ Currently, this is always <verbatim|/etc/gnunet.conf>.
+ </explain>
+
+ <subsection|Loading configuration files>
+
+ TODO: loading configurations from the disk
+
+ <subsection|Value types>
+
+ TODO
+
<section|Manipulation of network structures>
<index|network structure><index|netstruct>The modules <scm|(gnu gnunet
diff --git a/gnu/gnunet/config/fs.scm b/gnu/gnunet/config/fs.scm
new file mode 100644
index 0000000..0a39679
--- /dev/null
+++ b/gnu/gnunet/config/fs.scm
@@ -0,0 +1,64 @@
+;; This file is part of scheme-GNUnet, a partial Scheme port of GNUnet.
+;; Copyright (C) 2021 Maxime Devos <maximedevos@telenet.be>
+;;
+;; scheme-GNUnet is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU Affero General Public License as published
+;; by the Free Software Foundation, either version 3 of the License,
+;; or (at your option) any later version.
+;;
+;; scheme-GNUnet is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; Affero General Public License for more details.
+;;
+;; You should have received a copy of the GNU Affero General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+;;
+;; SPDX-License-Identifier: AGPL-3.0-or-later
+
+(define-library (gnu gnunet config fs)
+ (export locate-system-configuration
+ locate-user-configuration)
+ (import (only (rnrs base)
+ begin define and not or)
+ (only (ice-9 optargs)
+ define*)
+ (only (guile)
+ getenv in-vicinity string-null?)
+ (only (gnu gnunet utils hat-let)
+ let^))
+ (begin
+ (define (locate-system-configuration)
+ "/etc/gnunet.conf")
+
+ (define* (locate-user-configuration #:key (getenv getenv))
+ "Determine the location of the user configuration file,
+as a string, or @code{#false} if it could not be determined.
+If the location of the user configuration file is known,
+but the file does not exist, it is returned anyway, as a string.
+
+If the environment variable @code{XDG_CONFIG_HOME} is set, the
+location of the file @code{gnunet.conf} in the directory
+@code{XDG_CONFIG_HOME} is returned. If the environment variable
+is not set, the location of the file at @code{.config/gnunet.conf}
+in the home directory specified by the environment variable
+@code{HOME} is returned, if that environment variable exist.
+If both are unset, @code{#false} is returned.
+
+The values of environment variables is determined with the procedure
+@var{getenv}."
+ (define (locate/HOME)
+ (define HOME (getenv "HOME"))
+ ;; It is possible, though inadvisable, for HOME
+ ;; to be unset.
+ (and HOME (not (string-null? HOME))
+ (in-vicinity HOME (in-vicinity ".config" "gnunet.conf"))))
+ (let^ ((! XDG_CONFIG_HOME (getenv "XDG_CONFIG_HOME"))
+ ;; If the environment variable is unset, fall-back to
+ ;; $HOME.
+ (? (or (not XDG_CONFIG_HOME)
+ (string-null? XDG_CONFIG_HOME))
+ (locate/HOME)))
+ (in-vicinity XDG_CONFIG_HOME "gnunet.conf")))
+ ;; TODO actually load the configuration, defaults, ...
+ ))
diff --git a/tests/config-fs.scm b/tests/config-fs.scm
new file mode 100644
index 0000000..f44770f
--- /dev/null
+++ b/tests/config-fs.scm
@@ -0,0 +1,65 @@
+;; This file is part of scheme-GNUnet.
+;; Copyright (C) 2021 Maxime Devos
+;;
+;; scheme-GNUnet is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU Affero General Public License as published
+;; by the Free Software Foundation, either version 3 of the License,
+;; or (at your option) any later version.
+;;
+;; scheme-GNUnet is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; Affero General Public License for more details.
+;;
+;; You should have received a copy of the GNU Affero General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+;;
+;; SPDX-License-Identifier: AGPL3.0-or-later
+
+(import (gnu gnunet config fs)
+ (srfi srfi-64))
+(test-begin "config-fs")
+
+(define (alist->getenv alist)
+ (lambda (x)
+ (assoc-ref alist x)))
+
+(test-equal "locate-user-configuraton, XDG_CONFIG_HOME + HOME"
+ "/somewhere/unusual/gnunet.conf"
+ (locate-user-configuration
+ #:getenv
+ (alist->getenv '(("HOME" . "/a/home")
+ ("XDG_CONFIG_HOME" . "/somewhere/unusual")))))
+
+(test-equal "locate-user-configuraton, XDG_CONFIG_HOME without HOME"
+ "/somewhere/unusual/gnunet.conf"
+ (locate-user-configuration
+ #:getenv
+ (alist->getenv '(("XDG_CONFIG_HOME" . "/somewhere/unusual")))))
+
+(test-equal "locate-user-configuration, no XDG_CONFIG_HOME"
+ "/a/home/.config/gnunet.conf"
+ (locate-user-configuration
+ #:getenv
+ (alist->getenv '(("HOME" . "/a/home")))))
+
+(test-equal "locate-user-configuration, empty XDG_CONFIG_HOME"
+ "/a/home/.config/gnunet.conf"
+ (locate-user-configuration
+ #:getenv
+ (alist->getenv '(("HOME" . "/a/home")
+ ("XDG_CONFIG_HOME" . "")))))
+
+(test-equal "locate-user-configuration, no XDG_CONFIG_HOME, no HOME"
+ #false
+ (locate-user-configuration
+ #:getenv
+ (alist->getenv '())))
+
+(test-equal "locate-user-configuration, no XDG_CONFIG_HOME, empty HOME"
+ #false
+ (locate-user-configuration
+ #:getenv
+ (alist->getenv '(("HOME" . "")))))
+
+(test-end "config-fs")
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet-scheme] 269/324: mq/error-reporting: Support error reporting., (continued)
- [gnunet-scheme] 269/324: mq/error-reporting: Support error reporting., gnunet, 2021/09/21
- [gnunet-scheme] 273/324: nse/client: Use 'spawn' instead of hardcoding 'spawn-fiber'., gnunet, 2021/09/21
- [gnunet-scheme] 275/324: nse/client: Remove default for 'spawn'., gnunet, 2021/09/21
- [gnunet-scheme] 277/324: tests/network-size: Make ‘reconnects’ test reproducible., gnunet, 2021/09/21
- [gnunet-scheme] 271/324: tests: Abstract setting of O_NONBLOCK., gnunet, 2021/09/21
- [gnunet-scheme] 272/324: tests/network-size: Abstract configuration creation., gnunet, 2021/09/21
- [gnunet-scheme] 274/324: nse/client: Remove rest arguments., gnunet, 2021/09/21
- [gnunet-scheme] 276/324: nse/client: Stop reconnecting when a disconnect is requested., gnunet, 2021/09/21
- [gnunet-scheme] 278/324: doc: Use MathML instead of PNG images., gnunet, 2021/09/21
- [gnunet-scheme] 279/324: build: Remove resolved TODO., gnunet, 2021/09/21
- [gnunet-scheme] 280/324: config/fs: Locate the user and system configuration.,
gnunet <=
- [gnunet-scheme] 283/324: config/fs: Mark TODO's as done., gnunet, 2021/09/21
- [gnunet-scheme] 286/324: build: Correct location of defaults file., gnunet, 2021/09/21
- [gnunet-scheme] 287/324: doc: Document how the read values from a configuration., gnunet, 2021/09/21
- [gnunet-scheme] 281/324: config: Implement loading a configuration file., gnunet, 2021/09/21
- [gnunet-scheme] 284/324: config: Automatically load defaults, system and user configuration., gnunet, 2021/09/21
- [gnunet-scheme] 282/324: config: Allow expanding loaded configurations., gnunet, 2021/09/21
- [gnunet-scheme] 285/324: examples: Distribute the example., gnunet, 2021/09/21
- [gnunet-scheme] 289/324: guix: Set up .guix-authorizations., gnunet, 2021/09/21
- [gnunet-scheme] 288/324: ROADMAP.org: Mark resolved TODO's as DONE., gnunet, 2021/09/21
- [gnunet-scheme] 295/324: tests/network-size: Remove resolved XXX., gnunet, 2021/09/21