diff options
author | David Bremner <david@tethera.net> | 2022-05-05 08:29:20 -0300 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2022-05-05 12:26:10 -0700 |
commit | 54d75297ea8b190a3b91bd662deb61e670e9f9ef (patch) | |
tree | cb0027e12ac3f8de9319ed98c80ea2d721f1f1d7 /src/data/util.lisp | |
parent | dd44f19023f4cc9a70b431aff999c9a771b364b1 (diff) | |
download | consfigurator-54d75297ea8b190a3b91bd662deb61e670e9f9ef.tar.gz |
add package CONSFIGURATOR.DATA.UTIL
This package is intended to provide a home for utility functions used by
multiple data sources. Initially move a local function from
CONSFIGURATOR.DATA.FILES-TREE, and slightly generalize it to support an
extension or TYPE argument.
Note that the goal of LITERAL-DATA-PATHNAME is to map (IDEN1 IDEN2) to
existing paths in a user-maintained file hierarchy. This is quite different
from DATA-PATHNAME, which escapes various characters to map to a safe internal
filename, effectively flattening a directory hierarchy into a single level.
Signed-off-by: David Bremner <david@tethera.net>
Diffstat (limited to 'src/data/util.lisp')
-rw-r--r-- | src/data/util.lisp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/data/util.lisp b/src/data/util.lisp new file mode 100644 index 0000000..3fd8895 --- /dev/null +++ b/src/data/util.lisp @@ -0,0 +1,40 @@ +;;; Consfigurator -- Lisp declarative configuration management system + +;;; Copyright (C) 2022 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.util) +(named-readtables:in-readtable :consfigurator) + +(defun literal-data-pathname (base-path iden1 iden2 &key type) + "Generate a path from BASE-PATH, IDEN1 and IDEN2 by concatentation, +optionally adding extension TYPE. + +No escaping of special characters is done, but extra '/' characters between +pathname components are removed. + +The intended use case is to map IDEN1 and IDEN2 to files in a user-maintained +hierarchy under BASE-PATH. In particular IDEN2 and (if prefixed by '_') IDEN1 +may contain '/' characters to map into multiple levels of directory." + (let ((base-dir (uiop:parse-unix-namestring base-path :ensure-directory t))) + (unless (uiop:directory-pathname-p base-dir) + (simple-program-error "~A does not specify a directory" base-dir)) + (merge-pathnames + (uiop:relativize-pathname-directory + (uiop:parse-unix-namestring iden2 :type type)) + (merge-pathnames + (uiop:relativize-pathname-directory + (ensure-directory-pathname iden1)) + base-dir)))) |