From 1392bcbbe1445e4292ac72b3cd6d93819a701267 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sun, 28 Dec 2025 21:28:49 +0100 Subject: [PATCH] FilesystemMusicStorage: Fallback to delete if moving to trash fails Fixes #1679 --- src/core/filesystemmusicstorage.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/core/filesystemmusicstorage.cpp b/src/core/filesystemmusicstorage.cpp index 3df251015..b50d061f0 100644 --- a/src/core/filesystemmusicstorage.cpp +++ b/src/core/filesystemmusicstorage.cpp @@ -110,21 +110,32 @@ bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job, QString &error_te bool FilesystemMusicStorage::DeleteFromStorage(const DeleteJob &job) { - QString path = job.metadata_.url().toLocalFile(); - QFileInfo fileInfo(path); + const QString path = job.metadata_.url().toLocalFile(); + const QFileInfo fileInfo(path); #if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0) if (job.use_trash_ && QFile::supportsMoveToTrash()) { #else if (job.use_trash_) { #endif - return QFile::moveToTrash(path); + if (QFile::moveToTrash(path)) { + return true; + } + qLog(Warning) << "Moving file to trash failed for" << path << ", falling back to direct deletion"; } + bool success = false; if (fileInfo.isDir()) { - return Utilities::RemoveRecursive(path); + success = Utilities::RemoveRecursive(path); + } + else { + success = QFile::remove(path); } - return QFile::remove(path); + if (!success) { + qLog(Error) << "Failed to delete file" << path; + } + + return success; }