Fix folder permission check on NTFS
authorHannah von Reth <hannah.vonreth@owncloud.com>
Thu, 22 Oct 2020 15:12:00 +0000 (17:12 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:26 +0000 (10:59 +0100)
Fixes: #8187
src/common/utility.h
src/common/utility_win.cpp
src/gui/folderman.cpp

index ad18c9f1cf27bded597ce5ebd2aaa0af45f89e20..3dc2586b498e3c0eb296e28ec10f42b93b2f1a43 100644 (file)
@@ -254,6 +254,21 @@ namespace Utility {
         return formatWinError(GetLastError());
     };
 
+    class OCSYNC_EXPORT NtfsPermissionLookupRAII
+    {
+    public:
+        /**
+         * NTFS permissions lookup is diabled by default for performance reasons
+         * Enable it and disable it again once we leave the scope
+         * https://doc.qt.io/Qt-5/qfileinfo.html#ntfs-permissions
+         */
+        NtfsPermissionLookupRAII();
+        ~NtfsPermissionLookupRAII();
+
+    private:
+        Q_DISABLE_COPY(NtfsPermissionLookupRAII);
+    };
+
 #endif
 }
 /** @} */ // \addtogroup
index 5aec8db5182df577d274e024455a3787d757361d..8a56bcd4198d7563352cb9bdbb5410ed94794c55 100644 (file)
@@ -29,6 +29,8 @@
 
 #include <QLibrary>
 
+extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
+
 static const char systemRunPathC[] = R"(HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run)";
 static const char runPathC[] = R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run)";
 
@@ -344,4 +346,15 @@ QString Utility::formatWinError(long errorCode)
     return QStringLiteral("WindowsError: %1: %2").arg(QString::number(errorCode, 16), QString::fromWCharArray(_com_error(errorCode).ErrorMessage()));
 }
 
+
+Utility::NtfsPermissionLookupRAII::NtfsPermissionLookupRAII()
+{
+    qt_ntfs_permission_lookup++;
+}
+
+Utility::NtfsPermissionLookupRAII::~NtfsPermissionLookupRAII()
+{
+    qt_ntfs_permission_lookup--;
+}
+
 } // namespace OCC
index b04ffa22791ccaffbd96e023c9a4c7b4df36a5b9..d7876d4d138c2fb8ace115cc9faad728615addab 100644 (file)
@@ -1458,7 +1458,10 @@ static QString checkPathValidityRecursive(const QString &path)
         return FolderMan::tr("No valid folder selected!");
     }
 
-    QFileInfo selFile(path);
+#ifdef Q_OS_WIN
+    Utility::NtfsPermissionLookupRAII ntfs_perm;
+#endif
+    const QFileInfo selFile(path);
 
     if (!selFile.exists()) {
         QString parentPath = selFile.dir().path();