From 7cc6f198cf437ae60185b65bfa556341be8ec63f Mon Sep 17 00:00:00 2001 From: ailurux Date: Fri, 4 Oct 2024 14:41:05 +1000 Subject: Explicitly close the playlist files in the queue on storage unmount --- src/tangara/audio/playlist.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/tangara/audio/playlist.cpp') diff --git a/src/tangara/audio/playlist.cpp b/src/tangara/audio/playlist.cpp index db712252..f57f078d 100644 --- a/src/tangara/audio/playlist.cpp +++ b/src/tangara/audio/playlist.cpp @@ -33,6 +33,10 @@ Playlist::Playlist(const std::string& playlistFilepath) auto Playlist::open() -> bool { std::unique_lock lock(mutex_); + if (file_open_) { + return true; + } + FRESULT res = f_open(&file_, filepath_.c_str(), FA_READ | FA_WRITE | FA_OPEN_ALWAYS); if (res != FR_OK) { @@ -194,6 +198,14 @@ auto Playlist::deserialiseCache() -> bool { return true; } +auto Playlist::close() -> void { + if (file_open_) { + f_close(&file_); + file_open_ = false; + file_error_ = false; + } +} + auto Playlist::skipToLocked(size_t position) -> void { if (!file_open_ || file_error_) { return; @@ -306,6 +318,10 @@ MutablePlaylist::MutablePlaylist(const std::string& playlistFilepath) auto MutablePlaylist::open() -> bool { std::unique_lock lock(mutex_); + + if (file_open_) { + return true; + } FRESULT res = f_open(&file_, filepath_.c_str(), FA_READ | FA_WRITE | FA_OPEN_ALWAYS); -- cgit v1.2.3