mirror of
https://github.com/stumpwm/stumpwm.git
synced 2026-09-10 07:26:20 -04:00
Convert some pathname functions to use uiop
This commit is contained in:
parent
47afa9a6e5
commit
5edf4f46c8
|
|
@ -36,34 +36,16 @@
|
|||
(export '(list-directory
|
||||
pathname-as-directory))
|
||||
|
||||
(defun component-present-p (value)
|
||||
"Helper function for DIRECTORY-PATHNAME-P which checks whether VALUE
|
||||
is neither NIL nor the keyword :UNSPECIFIC."
|
||||
(and value (not (eql value :unspecific))))
|
||||
|
||||
(defun directory-pathname-p (pathspec)
|
||||
"Returns NIL if PATHSPEC \(a pathname designator) does not designate
|
||||
a directory, PATHSPEC otherwise. It is irrelevant whether file or
|
||||
directory designated by PATHSPEC does actually exist."
|
||||
(and
|
||||
(not (component-present-p (pathname-name pathspec)))
|
||||
(not (component-present-p (pathname-type pathspec)))
|
||||
pathspec))
|
||||
(uiop:directory-pathname-p pathspec))
|
||||
|
||||
(defun pathname-as-directory (pathspec)
|
||||
"Converts the non-wild pathname designator PATHSPEC to directory
|
||||
form."
|
||||
(let ((pathname (pathname pathspec)))
|
||||
(when (wild-pathname-p pathname)
|
||||
(error "Can't reliably convert wild pathnames."))
|
||||
(cond ((not (directory-pathname-p pathspec))
|
||||
(make-pathname :directory (append (or (pathname-directory pathname)
|
||||
(list :relative))
|
||||
(list (file-namestring pathname)))
|
||||
:name nil
|
||||
:type nil
|
||||
:defaults pathname))
|
||||
(t pathname))))
|
||||
(uiop:ensure-directory-pathname pathspec))
|
||||
|
||||
(defun directory-wildcard (dirname)
|
||||
"Returns a wild pathname designator that designates all files within
|
||||
|
|
@ -82,7 +64,8 @@ directory form - see PATHNAME-AS-DIRECTORY."
|
|||
(when (wild-pathname-p dirname)
|
||||
(error "Can only list concrete directory names."))
|
||||
(let ((wildcard (directory-wildcard dirname)))
|
||||
(directory wildcard)))
|
||||
(directory wildcard)))
|
||||
|
||||
(defun list-directory-recursive (dirname &optional flatten-p)
|
||||
"Returns a list of pathnames corresponding to the truenames all
|
||||
files within the directory and in any subdirectories. If
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
"fiasco")
|
||||
:pathname "tests/"
|
||||
:components ((:file "package")
|
||||
(:file "kmap"))
|
||||
(:file "kmap")
|
||||
(:file "pathnames"))
|
||||
:perform (test-op (o c)
|
||||
(uiop/package:symbol-call "FIASCO" "RUN-TESTS" 'stumpwm-tests)))
|
||||
|
|
|
|||
8
tests/pathnames.lisp
Normal file
8
tests/pathnames.lisp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(in-package #:stumpwm-tests)
|
||||
|
||||
(deftest test-directory-pathname-p ()
|
||||
(is (stumpwm::directory-pathname-p "/")))
|
||||
|
||||
(deftest test-ensure-directory-pathname ()
|
||||
(is (equal (pathname-as-directory "/") #P"/"))
|
||||
(is (equal (pathname-as-directory "/test.lisp") #P"/test.lisp/")))
|
||||
Loading…
Reference in a new issue