Skip to content

Commit 2b33cdd

Browse files
authored
Merge pull request #8130 from nextcloud/backport/8127/stable-3.16
[stable-3.16] stop using QFile api to delete a single local file
2 parents 0c50e0f + 147a033 commit 2b33cdd

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

src/common/filesystembase.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <QFile>
2727
#include <QCoreApplication>
2828

29+
#include <filesystem>
2930
#include <sys/stat.h>
3031
#include <sys/types.h>
3132

@@ -588,13 +589,30 @@ bool FileSystem::remove(const QString &fileName, QString *errorString)
588589
// allow that.
589590
setFileReadOnly(fileName, false);
590591
#endif
591-
QFile f(fileName);
592-
if (!f.remove()) {
592+
593+
try {
594+
if (!std::filesystem::remove(std::filesystem::path{fileName.toUtf8().data()})) {
595+
if (errorString) {
596+
*errorString = QObject::tr("File is already deleted");
597+
}
598+
return false;
599+
}
600+
}
601+
catch (const std::filesystem::filesystem_error &e)
602+
{
593603
if (errorString) {
594-
*errorString = f.errorString();
604+
*errorString = QString::fromLatin1(e.what());
595605
}
596606
return false;
597607
}
608+
catch (...)
609+
{
610+
if (errorString) {
611+
*errorString = QObject::tr("Error deleting the file");
612+
}
613+
return false;
614+
}
615+
598616
return true;
599617
}
600618

0 commit comments

Comments
 (0)