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 '';