From b2934a68bc7debb1d83229eacae0f48eb95241bf Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Thu, 22 Oct 2020 17:12:00 +0200 Subject: [PATCH] Fix folder permission check on NTFS Fixes: #8187 --- src/common/utility.h | 15 +++++++++++++++ src/common/utility_win.cpp | 13 +++++++++++++ src/gui/folderman.cpp | 5 ++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/common/utility.h b/src/common/utility.h index ad18c9f1c..3dc2586b4 100644 --- a/src/common/utility.h +++ b/src/common/utility.h @@ -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 diff --git a/src/common/utility_win.cpp b/src/common/utility_win.cpp index 5aec8db51..8a56bcd41 100644 --- a/src/common/utility_win.cpp +++ b/src/common/utility_win.cpp @@ -29,6 +29,8 @@ #include +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 diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index b04ffa227..d7876d4d1 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -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(); -- 2.30.2