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 <ljonas@riseup.net>
This commit is contained in:
togir 2023-02-24 12:04:11 +01:00 committed by GitHub
parent b0721edde5
commit a2aca7ddb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 6 deletions

View File

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