ambrevar/storage: Return inspectable values in write-roots-index.

master
Pierre Neidhardt 2021-06-05 12:25:07 +02:00
parent 5af2036b5d
commit 4cbcf9eea2
1 changed files with 29 additions and 23 deletions

View File

@ -12,7 +12,7 @@
(trivial-package-local-nicknames:add-package-local-nickname :alex :alexandria) (trivial-package-local-nicknames:add-package-local-nickname :alex :alexandria)
(trivial-package-local-nicknames:add-package-local-nickname :sera :serapeum)) (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/")) (defun roots (&optional (prefix "/media/"))
(sera:filter (sera:op (str:starts-with? prefix _)) (sera:filter (sera:op (str:starts-with? prefix _))
@ -60,7 +60,8 @@ EncFS encrypted directories are skipped.
result)) result))
(defun write-index (directory destination) (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'. See `index'.
If DESTINATION ends with '.gpg', it gets GPG-encrypted." If DESTINATION ends with '.gpg', it gets GPG-encrypted."
(let* ((relative-index (mapcar (alex:rcurry #'fof:relative-path (fof:file directory)) (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) :if-exists :supersede)
(dolist (entry sorted-index) (dolist (entry sorted-index)
(format f "~a~&" entry)))) (format f "~a~&" entry))))
(values (list destination sorted-index)))
nil
sorted-index)))
(export-always 'write-roots-index) (export-always 'write-roots-index)
(defun write-roots-index (&optional (destination (personal "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")))))) (str:concat (fof:basename target) ".index"))))))
(index1 (root) (index1 (root)
(ambrevar/shell:make-directory destination) (ambrevar/shell:make-directory destination)
(dolist (entry (fof:list-directory root)) (alex:mappend
(str:string-case (fof:basename entry) (lambda (entry)
("public" (str:string-case (fof:basename entry)
(dolist (subentry (fof:list-directory entry)) ("public"
(match (fof:basename subentry) (alex:mappend
((or "gaming" "videos") (lambda (subentry)
(ambrevar/shell:make-directory (subpath destination (fof:basename subentry))) (match (fof:basename subentry)
(dolist (entry (fof:list-directory subentry)) ((or "gaming" "videos")
(write-simple-index entry (fof:basename subentry)))) (ambrevar/shell:make-directory (subpath destination (fof:basename subentry)))
(otherwise (mapcar (lambda (entry)
(write-simple-index subentry))))) (write-simple-index entry (fof:basename subentry)))
("private" (fof:list-directory subentry)))
(dolist (subentry (fof:list-directory entry)) (otherwise
(write-index subentry (subpath destination "private" (list (write-simple-index subentry)))))
(str:concat (fof:basename subentry) ".index.gpg"))))) (fof:list-directory entry)))
("big-games" ("private"
(write-simple-index entry)))))) (mapcar (lambda (subentry)
(mapc #'index1 (roots)))) (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) (export-always 'notmuch-tags)
(defun notmuch-tags () (defun notmuch-tags ()