diff --git a/src/storage.lisp b/src/storage.lisp index 80ff1c9..4bb3c1a 100644 --- a/src/storage.lisp +++ b/src/storage.lisp @@ -27,7 +27,9 @@ #:ensure-raw-directory-exists #:remove-raw-directory #:copy-storage-directory - #:copy-raw-directory)) + #:copy-raw-directory + #:get-files-in-raw-directory + #:get-raw-subdirectories)) (in-package #:storage) (defun init-storage () @@ -96,13 +98,31 @@ If the file exists, the full (absolute) path is returned (equates to (cl:probe-file (make-path username subdirectory slug))) (defun get-files-in-directory (username directory) - "" + "Returns a list of paths for the files in `DIRECTORY' in the /storage directory. +`USERNAME' is the subdirectory in /storage. If you are not implementing or have +a need for creating sub-directories in /storage, pass in an empty string \"\" . +Full directory structure: /storage/`USERNAME'/`DIRECTORY' + +When empty string used for 'username': /storage/`DIRECTORY'" (uiop:directory-files (make-path username directory ""))) (defun get-file-names (filenames) - "" + "Returns a list of file names from a list of paths in `FILENAMES'. +Make sure you call `STORAGE:GET-FILES-IN-DIRECTORY' and pass as `FILENAMES' when +calling this function." (mapcar #'(lambda (x) (file-namestring x)) filenames)) +(defun get-raw-directories (directory-path) + "Returns a list of paths for the files in `DIRECTORY-PATH' outside /storage directory." + (cl-fad:list-directory (make-raw-path directory-path))) + +(defun get-directory-names (directory-names) + "Returns the final part of a directories absolute path in `DIRECTORY-NAMES'. +Make sure you use `GET-RAW-DIRECTORIES' to build the `DIRECTORY-NAMES' list." + (mapcar #'(lambda (x) (first (last (pathname-directory x)))) directory-names)) + +;; (first (last (pathname-directory (cl-fad:pathname-directory-pathname (first (cl-fad:list-directory (storage:make-raw-path "snapshots/"))))))) + (defun make-path (username subdirectory slug) "Forms the path used to save a file. Storage path: @@ -118,8 +138,7 @@ not (user-)`ID' is because I wanted to easily identify the directories in (defun make-raw-path (path) "Make a file/directory path outsite of the /storage directory." - (merge-pathnames (format nil "~a" path) - ritherdon-archive.config:*application-root*)) + (merge-pathnames path ritherdon-archive.config:*application-root*)) (defun open-binary-file (username subdirectory slug) "Reads the file stored in the /storage directory."