let FileSystem::removeRecursively be able to delete read-only folders

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
This commit is contained in:
Matthieu Gallien 2024-09-02 13:53:11 +02:00
parent 5b8144f806
commit 27189bf4b1
No known key found for this signature in database
GPG key ID: 7D0F74F05C22F553

View file

@ -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)
@ -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)