From a2aca7ddb47651ce4ad123042525b8023c176f02 Mon Sep 17 00:00:00 2001 From: togir <39676950+togir2@users.noreply.github.com> Date: Fri, 24 Feb 2023 12:04:11 +0100 Subject: [PATCH] fix(legacy): do not delete audio file when removing artwork (#2395) * fix: do not delete audio file when removing artwork * replace glob with explicit filenames --------- Co-authored-by: jo --- legacy/application/common/FileDataHelper.php | 28 +++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/legacy/application/common/FileDataHelper.php b/legacy/application/common/FileDataHelper.php index d10c40204..ae745f0f8 100644 --- a/legacy/application/common/FileDataHelper.php +++ b/legacy/application/common/FileDataHelper.php @@ -305,15 +305,31 @@ class FileDataHelper $fp = Config::getStoragePath(); - $dbAudioPath = $md['MDATA_KEY_ARTWORK']; - $fullpath = $fp . $dbAudioPath; + $artworkBasePath = $fp . $md['MDATA_KEY_ARTWORK']; + $audioPath = $fp . $md['MDATA_KEY_FILEPATH']; - if (file_exists($fullpath)) { - foreach (glob("{$fullpath}*", GLOB_NOSORT) as $filename) { + $artworkPaths = [ + $artworkBasePath, + $artworkBasePath . '-32.jpg', + $artworkBasePath . '-64.jpg', + $artworkBasePath . '-128.jpg', + $artworkBasePath . '-256.jpg', + $artworkBasePath . '-512.jpg', + $artworkBasePath . '-32', + $artworkBasePath . '-64', + $artworkBasePath . '-128', + $artworkBasePath . '-256', + ]; + + foreach ($artworkPaths as $filename) { + // This should never happen. Make sure we don't delete the audio file. + if ($filename == $audioPath) { + continue; + } + + if (file_exists($filename)) { unlink($filename); } - } else { - throw new Exception('Could not locate file ' . $filepath); } return '';