blob: 3fd88952f45e5f7c4cfeebf23e6858ce1926161f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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))))
|