From a490c50cf25b44f654ae215ac8191950eb726fd7 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Tue, 25 Oct 2022 04:35:39 +0100 Subject: [PATCH] implement store-snapshot in snapshot package. This feature provides the ability to unzip a .zip file (the expected file format users must upload Snapshots with) and store the contents of the .zip file in the /snapshots directory. --- src/snapshot.lisp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/snapshot.lisp b/src/snapshot.lisp index 75b11ac..ea5e769 100644 --- a/src/snapshot.lisp +++ b/src/snapshot.lisp @@ -7,7 +7,8 @@ (:export #:take-snapshot #:restore-from-snapshot - #:delete-snapshot)) + #:delete-snapshot + #:store-snapshot)) (in-package #:snapshot) (defun take-snapshot () @@ -37,3 +38,25 @@ user can repopulate that database after they have restored this website. The (defun delete-snapshot (snapshot-name) "Deletes the snapshot in the /snapshots directory with `SNAPSHOT-NAME'." (storage:remove-raw-directory (format nil "snapshots/~a/" snapshot-name))) + +(defun store-snapshot (filename data) + "Unzips `SNAPSHOT-FILE' and stores it in /snapshots directory. + +The .zip file is deleted after it has been un-zipped. I did think about moving +the zipped version of the file into the /storage/media directory but there is +too much second guessing going on. I found I was uploading .zip files from the +/storage/media directory and I don't know if users will be uploading .zip files +they had just downloaded from /storage/media. If that is the case, then there +is: + +a.) No need to move it to /storage/madia; +b.) Extra work regarding checks for duplicate entries; and, +c.) I don't know if that is too much 'magic' for users and cause confusion. + +If the user is in a paniced state -- trying to restore their website, confusion +is the thing I want to keep to a minimum for them." + (storage:store-with-raw-path (format nil "snapshots/~a" filename) data) + (zip:unzip (storage:make-raw-path (format nil"snapshots/~a" filename)) + (storage:make-raw-path (format nil "snapshots/~a/" + (pathname-name filename)))) + (storage:remove-file-with-raw-path (format nil "snapshots/~a" filename)))