ambrevar/storage: Replace own `parent' with pathname-utils:parent.

master
Pierre Neidhardt 2021-06-05 13:22:10 +02:00
parent 9ded15843d
commit 3549a9461e
1 changed files with 5 additions and 12 deletions

View File

@ -10,9 +10,8 @@
(in-package ambrevar/storage)
(eval-when (:compile-toplevel :load-toplevel :execute)
(trivial-package-local-nicknames:add-package-local-nickname :alex :alexandria)
(trivial-package-local-nicknames:add-package-local-nickname :sera :serapeum))
;; TODO: Use pathname-utils to simplify code.
(trivial-package-local-nicknames:add-package-local-nickname :sera :serapeum)
(trivial-package-local-nicknames:add-package-local-nickname :path :pathname-utils))
(defun roots (&optional (prefix "/media/"))
(sera:filter (sera:op (str:starts-with? prefix _))
@ -144,19 +143,13 @@ If DESTINATION ends with '.gpg', it gets GPG-encrypted."
:test #'string=
:key #'basename))
(defun parent (path)
"Return the parent directory of PATH."
(if (uiop:directory-pathname-p path)
(uiop:pathname-parent-directory-pathname path)
(uiop:pathname-directory-pathname path)))
(defun depth (file parent)
(if (uiop:pathname-equal file parent)
0
(unless (uiop:pathname-equal (parent file) file)
(or (when (uiop:pathname-equal (parent file) parent)
(unless (uiop:pathname-equal (path:parent file) file)
(or (when (uiop:pathname-equal (path:parent file) parent)
1)
(alex:when-let ((level (depth (parent file) parent)))
(alex:when-let ((level (depth (path:parent file) parent)))
(1+ level))))))
(export-always 'list-projects)