stop using QFile api to delete a single local file

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
This commit is contained in:
Matthieu Gallien 2025-04-07 15:37:41 +02:00 committed by backportbot[bot]
parent 0c50e0fafe
commit 147a033f88

View File

@ -26,6 +26,7 @@
#include <QFile>
#include <QCoreApplication>
#include <filesystem>
#include <sys/stat.h>
#include <sys/types.h>
@ -588,13 +589,30 @@ bool FileSystem::remove(const QString &fileName, QString *errorString)
// allow that.
setFileReadOnly(fileName, false);
#endif
QFile f(fileName);
if (!f.remove()) {
try {
if (!std::filesystem::remove(std::filesystem::path{fileName.toUtf8().data()})) {
if (errorString) {
*errorString = QObject::tr("File is already deleted");
}
return false;
}
}
catch (const std::filesystem::filesystem_error &e)
{
if (errorString) {
*errorString = f.errorString();
*errorString = QString::fromLatin1(e.what());
}
return false;
}
catch (...)
{
if (errorString) {
*errorString = QObject::tr("Error deleting the file");
}
return false;
}
return true;
}