let FileSystem::removeRecursively be able to delete read-only folders
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Mon, 2 Sep 2024 11:53:11 +0000 (13:53 +0200)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Thu, 12 Sep 2024 07:57:41 +0000 (09:57 +0200)
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/libsync/filesystem.cpp

index c05b29795401b0dbfb18fbbd92cc618b8f0a8507..7ff29ca4c1e855a64fb6ee1ee5830b997cf8f147 100644 (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)