diff options
author | colin <colin@cicadas.surf> | 2023-01-14 10:36:17 -0800 |
---|---|---|
committer | colin <colin@cicadas.surf> | 2023-01-14 10:36:17 -0800 |
commit | b8ac6f8f45bc274ab2a79247dbc976c015bcb667 (patch) | |
tree | 268024edc1960c9dde70303f21a09bf44b65170f | |
parent | db23eebb6f5a1fb40c7c7e6467a3c66b13e10e42 (diff) |
Refactor: superfluous with-open-file was masking a bug
The bug was the use of :if-exists :overwrite when it should have been
:if-exists :supersede.
Cleaned up zipped-playlist-url too.
-rw-r--r-- | package.lisp | 1 | ||||
-rw-r--r-- | zipper.lisp | 17 |
2 files changed, 12 insertions, 6 deletions
diff --git a/package.lisp b/package.lisp index ded3da3..c24492c 100644 --- a/package.lisp +++ b/package.lisp @@ -2,6 +2,7 @@ (defpackage #:vampire (:use #:cl #:clog) + (:local-nicknames (#:zippy #:org.shirakumo.zippy )) (:import-from #:bknr.datastore #:with-transaction #:store-object diff --git a/zipper.lisp b/zipper.lisp index 8ed37aa..91fafba 100644 --- a/zipper.lisp +++ b/zipper.lisp @@ -6,10 +6,12 @@ "Compresses playlist tracks into a zip archive." (unless (zipped-playlist-exists-p playlist) (let ((zip-file (zipped-playlist-path playlist))) + (ensure-directories-exist zip-file) (with-temp-dir (tmpdir) - (with-open-file (_foo zip-file :if-does-not-exist :create :direction :output :if-exists :overwrite) - (org.shirakumo.zippy:compress-zip - (copy-audio-files-for-download playlist tmpdir) zip-file :if-exists :overwrite)))))) + (copy-audio-files-for-download playlist tmpdir) + (zippy:compress-zip + tmpdir zip-file :if-exists :supersede))))) + (defun zip-track-filename (track pos) "Return a filename for a track. `NN-ARTIST-ALBUM-TITLE.CODEC'" @@ -22,16 +24,19 @@ (defun zipped-playlist-path (playlist) "Returns the zipped playlist path relative to the configured static directory." - (merge-pathnames (pathname-utils:to-relative (zipped-playlist-url playlist)) + (merge-pathnames (zipped-playlist-url playlist :absolute nil) (static-directory *config*))) -(defun zipped-playlist-url (playlist) +(defun zipped-playlist-url (playlist &key (absolute t)) "Returns the url where the playlist's zip file is expected to exist." - (merge-pathnames (zipped-playlist-filename playlist) "/media/bundled-playlists/")) + (format nil "~:[~;/~]media/bundled-playlists/~a" + absolute + (zipped-playlist-filename playlist))) (defun zipped-playlist-exists-p (playlist) (uiop:file-exists-p (zipped-playlist-path playlist))) + (defun copy-audio-files-for-download (playlist dir) "Copies all playlist tracks into a temporary directory and returns a list of the pathnames." (loop for track in (playlist-tracks playlist) |