Skip to content

Commit

Permalink
let FileSystem::removeRecursively be able to delete read-only folders
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien committed Sep 2, 2024
1 parent 56b609b commit d55760d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libsync/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ bool FileSystem::removeRecursively(const QString &path, const std::function<void
removeOk = removeRecursively(path + QLatin1Char('/') + di.fileName(), onDeleted, errors); // recursive
} else {
QString removeError;
const auto fileInfo = QFileInfo{di.filePath()};
const auto parentFolderPath = fileInfo.dir().absolutePath();
const auto parentPermissionsHandler = FileSystem::FilePermissionsRestore{parentFolderPath, FileSystem::FolderPermissions::ReadWrite};
removeOk = FileSystem::remove(di.filePath(), &removeError);
if (removeOk) {
if (onDeleted)
Expand All @@ -289,6 +292,10 @@ bool FileSystem::removeRecursively(const QString &path, const std::function<void
allRemoved = false;
}
if (allRemoved) {
const auto fileInfo = QFileInfo{path};
const auto parentFolderPath = fileInfo.dir().absolutePath();
const auto parentPermissionsHandler = FileSystem::FilePermissionsRestore{parentFolderPath, FileSystem::FolderPermissions::ReadWrite};
FileSystem::setFolderPermissions(path, FileSystem::FolderPermissions::ReadWrite);
allRemoved = QDir().rmdir(path);
if (allRemoved) {
if (onDeleted)
Expand Down

0 comments on commit d55760d

Please sign in to comment.