add missing exception handling
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 6 Sep 2024 14:02:38 +0000 (16:02 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Fri, 6 Sep 2024 14:05:04 +0000 (14:05 +0000)
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/libsync/filesystem.cpp

index baafe2225599511cd689e0c1d3f7362487803ad6..d249623373e4d8e069be6e32509e475cc2d1b1e0 100644 (file)
@@ -484,11 +484,15 @@ bool FileSystem::isFolderReadOnly(const std::filesystem::path &path) noexcept
 FileSystem::FilePermissionsRestore::FilePermissionsRestore(const QString &path, FolderPermissions temporaryPermissions)
     : _path(path)
 {
-    const auto stdStrPath = _path.toStdWString();
-    _initialPermissions = FileSystem::isFolderReadOnly(stdStrPath) ? OCC::FileSystem::FolderPermissions::ReadOnly : OCC::FileSystem::FolderPermissions::ReadWrite;
-    if (_initialPermissions != temporaryPermissions) {
-        _rollbackNeeded = true;
-        FileSystem::setFolderPermissions(_path, temporaryPermissions);
+    try {
+        const auto stdStrPath = _path.toStdWString();
+        _initialPermissions = FileSystem::isFolderReadOnly(stdStrPath) ? OCC::FileSystem::FolderPermissions::ReadOnly : OCC::FileSystem::FolderPermissions::ReadWrite;
+        if (_initialPermissions != temporaryPermissions) {
+            _rollbackNeeded = true;
+            FileSystem::setFolderPermissions(_path, temporaryPermissions);
+        }
+    } catch (const std::filesystem::filesystem_error &e) {
+        qCWarning(lcFileSystem()) << "exception when modifying folder permissions" << e.what() << e.path1().c_str() << e.path2().c_str();
     }
 }