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 authored and backportbot[bot] committed Sep 12, 2024
1 parent bbb36e3 commit 73d41dd
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/libsync/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ bool FileSystem::removeRecursively(const QString &path, const std::function<void
removeOk = removeRecursively(path + QLatin1Char('/') + di.fileName(), onDeleted, errors); // recursive
} else {
QString removeError;

#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
const auto fileInfo = QFileInfo{di.filePath()};
const auto parentFolderPath = fileInfo.dir().absolutePath();
const auto parentPermissionsHandler = FileSystem::FilePermissionsRestore{parentFolderPath, FileSystem::FolderPermissions::ReadWrite};
#endif
removeOk = FileSystem::remove(di.filePath(), &removeError);
if (removeOk) {
if (onDeleted)
Expand All @@ -289,6 +295,12 @@ bool FileSystem::removeRecursively(const QString &path, const std::function<void
allRemoved = false;
}
if (allRemoved) {
#if !defined(Q_OS_MACOS) || __MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15
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);
#endif
allRemoved = QDir().rmdir(path);
if (allRemoved) {
if (onDeleted)
Expand Down

0 comments on commit 73d41dd

Please sign in to comment.