From 0b539697833621e9c12cc014ee4347a6e06f8720 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 23 Oct 2022 21:17:14 +0100 Subject: [PATCH] add 'raw directory' functionality to storage package. This commit looks like it has more going on that is acutally does. The biggest mis-directed blobs are the docstring comments I added to get-files-in-directory and get-file-names. I just never got around to adding them until now. I remove the format call in make-raw-path because I forgot to do so in another commit. The code works with or without it which is why I missed it previously. I'm removing here to clean the code up and before I get distracted and forget. The actual code which this commit is mostly for are the get-raw-directories and get-directory-names. You shouldn't need to use these functions in the normal operations of the site. They are mostly intended to be used for dealing with the site's snapshots -- or any other directories outside of the /storage directory. The snapshot management section of the site is part of the 'danger zon' features -- hence the need to break-out of the usual '/storage directory' features. --- src/storage.lisp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) 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."