aboutsummaryrefslogtreecommitdiff
path: root/src/data
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2021-12-15 08:44:31 -0400
committerSean Whitton <spwhitton@spwhitton.name>2021-12-15 15:51:28 -0700
commit21cb78ab1a9c42f519e93ca8b441b058b50ae42d (patch)
tree942bd290bea53c87441d3cd4e1379a9ac0b58e6e /src/data
parenteda14d77dab39e05f69fef5fef2b5fb25482f215 (diff)
downloadconsfigurator-21cb78ab1a9c42f519e93ca8b441b058b50ae42d.tar.gz
add :FILES-TREE data source
This allows the user to conveniently maintain a set of files in their consfig tree (or elsewhere) for deployment as data. Signed-off-by: David Bremner <david@tethera.net>
Diffstat (limited to 'src/data')
-rw-r--r--src/data/files-tree.lisp57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/data/files-tree.lisp b/src/data/files-tree.lisp
new file mode 100644
index 0000000..26c41e3
--- /dev/null
+++ b/src/data/files-tree.lisp
@@ -0,0 +1,57 @@
+;;; Consfigurator -- Lisp declarative configuration management system
+
+;;; Copyright (C) 2021 David Bremner <david@tethera.net>
+
+;;; This file is free software; you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3, or (at your option)
+;;; any later version.
+
+;;; This file 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 General Public License for more details.
+
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+(in-package :consfigurator.data.files-tree)
+(named-readtables:in-readtable :consfigurator)
+
+(defmethod register-data-source ((type (eql :files-tree)) &key location)
+ "Provide the contents of a local directory on the machine running the root
+Lisp. Register this data source multiple times to provide multiple trees.
+LOCATION is either a designator for a pathname representing the root of the
+tree of files or a symbol which designates an ASDF package where the tree is
+contained in the subdirectory `data/'. IDEN1 specifies a subdirectory under
+LOCATION and IDEN2 a relative path within that subdirectory. For convenience
+IDEN1 and IDEN2 may be passed as absolute and will be converted to relative
+paths. The usual cases of IDEN1 as a hostname or a `_' prefixed identifier,
+and IDEN2 an an absolute or relative path are all supported."
+ (let ((base-path (if (symbolp location)
+ (asdf:system-relative-pathname location "data/")
+ (ensure-directory-pathname location))))
+ (unless (directory-exists-p base-path)
+ (missing-data-source
+ "~A does not exist, or is not a directory." base-path))
+ (labels ((%make-path (iden1 iden2)
+ (merge-pathnames
+ (uiop:relativize-pathname-directory
+ iden2)
+ (merge-pathnames
+ (uiop:relativize-pathname-directory
+ (ensure-directory-pathname iden1))
+ base-path)))
+ (check (iden1 iden2)
+ (let ((file-path (%make-path iden1 iden2)))
+ (and (file-exists-p file-path)
+ (file-write-date file-path))))
+ (extract (iden1 iden2)
+ (let ((file-path (%make-path iden1 iden2)))
+ (and (file-exists-p file-path)
+ (make-instance 'file-data
+ :file file-path
+ :iden1 iden1
+ :iden2 iden2
+ :version (file-write-date file-path))))))
+ (cons #'check #'extract))))