From 2b8f129680b2a9557f7c90229dc4fcfa72d94162 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Thu, 24 Apr 2025 09:30:58 +0200 Subject: [PATCH 1/3] fix: Revert "stop using QFile api to delete a single local file" This reverts commit 58d28ab3306a5cd36d990678416375386d9a0db9. Signed-off-by: Matthieu Gallien --- src/common/filesystembase.cpp | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/src/common/filesystembase.cpp b/src/common/filesystembase.cpp index c6dcb49d1c9d0..441746aae0e59 100644 --- a/src/common/filesystembase.cpp +++ b/src/common/filesystembase.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include @@ -541,34 +540,14 @@ bool FileSystem::remove(const QString &fileName, QString *errorString) // allow that. setFileReadOnly(fileName, false); #endif - - try { - if (!std::filesystem::remove(std::filesystem::path{fileName.toStdWString()})) { - if (errorString) { - *errorString = QObject::tr("File is already deleted"); - } - qCWarning(lcFileSystem()) << "File is already deleted" << fileName; - return false; - } - qCInfo(lcFileSystem()) << "delete" << fileName; - } - catch (const std::filesystem::filesystem_error &e) - { - if (errorString) { - *errorString = QString::fromLatin1(e.what()); - } - qCWarning(lcFileSystem()) << e.what() << fileName; - return false; - } - catch (...) - { + QFile f(fileName); + if (!f.remove()) { if (errorString) { - *errorString = QObject::tr("Error deleting the file"); + *errorString = f.errorString(); } - qCWarning(lcFileSystem()) << "Error deleting the file" << fileName; + qCWarning(lcFileSystem()) << f.errorString() << fileName; return false; } - return true; } From 2bcf7ce54e0c98b08e3a6dc5b0f95f8553d6313b Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Thu, 24 Apr 2025 10:07:47 +0200 Subject: [PATCH 2/3] fix(filesystem): still use std::filesystem::remove for folders this API has a way to provide an error when failing to delete a folder we may want to know why teh folderf ailed to be deleted QDir::rmdir does not provide any error when failing to delete a folder Signed-off-by: Matthieu Gallien --- src/libsync/filesystem.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/libsync/filesystem.cpp b/src/libsync/filesystem.cpp index 55d4c3c8b6b8c..3150819a33a3e 100644 --- a/src/libsync/filesystem.cpp +++ b/src/libsync/filesystem.cpp @@ -305,7 +305,25 @@ bool FileSystem::removeRecursively(const QString &path, const std::function Date: Thu, 24 Apr 2025 10:27:41 +0200 Subject: [PATCH 3/3] fix(filesystem): warn when trying to delete an already deleted file Signed-off-by: Matthieu Gallien --- src/common/filesystembase.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/common/filesystembase.cpp b/src/common/filesystembase.cpp index 441746aae0e59..fafd0eeba61be 100644 --- a/src/common/filesystembase.cpp +++ b/src/common/filesystembase.cpp @@ -540,6 +540,11 @@ bool FileSystem::remove(const QString &fileName, QString *errorString) // allow that. setFileReadOnly(fileName, false); #endif + const auto deletedFileInfo = QFileInfo{fileName}; + if (!deletedFileInfo.exists()) { + qCWarning(lcFileSystem()) << fileName << "has been already deleted"; + } + QFile f(fileName); if (!f.remove()) { if (errorString) {