From b8ac6f8f45bc274ab2a79247dbc976c015bcb667 Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 14 Jan 2023 10:36:17 -0800 Subject: 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. --- package.lisp | 1 + 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) -- cgit v1.2.3