Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 8 additions & 24 deletions src/common/filesystembase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <QFile>
#include <QCoreApplication>

#include <filesystem>
#include <sys/stat.h>
#include <sys/types.h>

Expand Down Expand Up @@ -541,34 +540,19 @@ 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;
const auto deletedFileInfo = QFileInfo{fileName};
if (!deletedFileInfo.exists()) {
qCWarning(lcFileSystem()) << fileName << "has been already deleted";
}
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;
}

Expand Down
20 changes: 19 additions & 1 deletion src/libsync/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,25 @@ bool FileSystem::removeRecursively(const QString &path, const std::function<void
const auto parentPermissionsHandler = FileSystem::FilePermissionsRestore{parentFolderPath, FileSystem::FolderPermissions::ReadWrite};
FileSystem::setFolderPermissions(path, FileSystem::FolderPermissions::ReadWrite);
auto folderDeleteError = QString{};
allRemoved = FileSystem::remove(path, &folderDeleteError);

try {
if (!std::filesystem::remove(std::filesystem::path{fileInfo.filePath().toStdWString()})) {
qCWarning(lcFileSystem()) << "File is already deleted" << fileInfo.filePath();
}
}
catch (const std::filesystem::filesystem_error &e)
{
folderDeleteError = QString::fromLatin1(e.what());
qCWarning(lcFileSystem()) << e.what() << fileInfo.filePath();
allRemoved = false;
}
catch (...)
{
folderDeleteError = QObject::tr("Error deleting the file");
qCWarning(lcFileSystem()) << "Error deleting the file" << fileInfo.filePath();
allRemoved = false;
}

qCInfo(lcFileSystem()) << "delete" << path;
if (allRemoved) {
if (onDeleted)
Expand Down