From 4cbcf9eea21b8f4e6094f654379532cd300f9b86 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Sat, 5 Jun 2021 12:25:07 +0200 Subject: [PATCH] ambrevar/storage: Return inspectable values in write-roots-index. --- .../common-lisp/source/ambrevar/storage.lisp | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/.local/share/common-lisp/source/ambrevar/storage.lisp b/.local/share/common-lisp/source/ambrevar/storage.lisp index cc30d36e..d04fed08 100644 --- a/.local/share/common-lisp/source/ambrevar/storage.lisp +++ b/.local/share/common-lisp/source/ambrevar/storage.lisp @@ -12,7 +12,7 @@ (trivial-package-local-nicknames:add-package-local-nickname :alex :alexandria) (trivial-package-local-nicknames:add-package-local-nickname :sera :serapeum)) -;; TODO: Use ppath to simplify code? +;; TODO: Use pathname-utils to simplify code. (defun roots (&optional (prefix "/media/")) (sera:filter (sera:op (str:starts-with? prefix _)) @@ -60,7 +60,8 @@ EncFS encrypted directories are skipped. result)) (defun write-index (directory destination) - "Write index of DIRECTORY to DESTINATION. + "Write sorted index of DIRECTORY to DESTINATION. +Return a pair of (DESTINATION index). See `index'. If DESTINATION ends with '.gpg', it gets GPG-encrypted." (let* ((relative-index (mapcar (alex:rcurry #'fof:relative-path (fof:file directory)) @@ -74,9 +75,7 @@ If DESTINATION ends with '.gpg', it gets GPG-encrypted." :if-exists :supersede) (dolist (entry sorted-index) (format f "~a~&" entry)))) - (values - nil - sorted-index))) + (list destination sorted-index))) (export-always 'write-roots-index) (defun write-roots-index (&optional (destination (personal "index"))) @@ -89,24 +88,31 @@ If DESTINATION ends with '.gpg', it gets GPG-encrypted." (str:concat (fof:basename target) ".index")))))) (index1 (root) (ambrevar/shell:make-directory destination) - (dolist (entry (fof:list-directory root)) - (str:string-case (fof:basename entry) - ("public" - (dolist (subentry (fof:list-directory entry)) - (match (fof:basename subentry) - ((or "gaming" "videos") - (ambrevar/shell:make-directory (subpath destination (fof:basename subentry))) - (dolist (entry (fof:list-directory subentry)) - (write-simple-index entry (fof:basename subentry)))) - (otherwise - (write-simple-index subentry))))) - ("private" - (dolist (subentry (fof:list-directory entry)) - (write-index subentry (subpath destination "private" - (str:concat (fof:basename subentry) ".index.gpg"))))) - ("big-games" - (write-simple-index entry)))))) - (mapc #'index1 (roots)))) + (alex:mappend + (lambda (entry) + (str:string-case (fof:basename entry) + ("public" + (alex:mappend + (lambda (subentry) + (match (fof:basename subentry) + ((or "gaming" "videos") + (ambrevar/shell:make-directory (subpath destination (fof:basename subentry))) + (mapcar (lambda (entry) + (write-simple-index entry (fof:basename subentry))) + (fof:list-directory subentry))) + (otherwise + (list (write-simple-index subentry))))) + (fof:list-directory entry))) + ("private" + (mapcar (lambda (subentry) + (write-index subentry + (subpath destination "private" + (str:concat (fof:basename subentry) ".index.gpg")))) + (fof:list-directory entry))) + ("big-games" + (list (write-simple-index entry))))) + (fof:list-directory root)))) + (delete-if-not #'second (alex:mappend #'index1 (roots))))) (export-always 'notmuch-tags) (defun notmuch-tags ()