Deprecate usage of qt_ntfs_permission_lookup

With the introduction of a new atomic variable the users should use the
class QNtfsPermissionCheckGuard or the helper functions
- qEnableNtfsPermissionChecks()
- qDisableNtfsPermissionChecks()
- qAreNtfsPermissionChecksEnabled()
to enable/disable permission checks instead of manually managing the
variable qt_ntfs_permission_lookup (which is a non-atomic variable and
as such prone to data races).

Also moved the variable qt_ntfs_permission_lookup to qfile.h to make it
clash with the user-side declarations the documentation suggested to
use (and it is probably also a better fit thematically anyway).

[ChangeLog][QtCore][Deprecation Notice] Deprecated the variable
qt_ntfs_permission_lookup to avoid race conditions while enabling or
disabling permission checks. It can be replaced by the RAII class
QNtfsPermissionCheckGuard or with the functions
qEnableNtfsPermissionChecks(), qDisableNtfsPermissionChecks() and
qAreNtfsPermissionChecksEnabled().

Fixes: QTBUG-105804
Change-Id: I93a563864ffb3f9945551c34004d8ca393603b25
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Mate Barany 2023-01-19 13:53:21 +01:00
parent 5999ff4fd6
commit fd70555b33
3 changed files with 24 additions and 5 deletions

View File

@ -27,6 +27,12 @@ namespace std {
QT_BEGIN_NAMESPACE
#ifdef Q_OS_WIN
#if QT_DEPRECATED_SINCE(6,6)
QT_DEPRECATED_VERSION_X_6_6("Use QNtfsPermissionCheckGuard RAII class instead.")
Q_CORE_EXPORT extern int qt_ntfs_permission_lookup; // defined in qfilesystemengine_win.cpp
#endif
Q_CORE_EXPORT bool qEnableNtfsPermissionChecks() noexcept;
Q_CORE_EXPORT bool qDisableNtfsPermissionChecks() noexcept;
Q_CORE_EXPORT bool qAreNtfsPermissionChecksEnabled() noexcept;

View File

@ -381,11 +381,15 @@ constexpr QFileDevice::Permissions toSpecificPermissions(PermissionTag tag,
} // anonymous namespace
#endif // QT_CONFIG(fslibs)
Q_CORE_EXPORT int qt_ntfs_permission_lookup = 0;
#if QT_DEPRECATED_SINCE(6,6)
int qt_ntfs_permission_lookup = 0;
#endif
static QBasicAtomicInt qt_ntfs_permission_lookup_v2 = Q_BASIC_ATOMIC_INITIALIZER(0);
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
/*!
\internal
@ -395,7 +399,7 @@ static QBasicAtomicInt qt_ntfs_permission_lookup_v2 = Q_BASIC_ATOMIC_INITIALIZER
bool qEnableNtfsPermissionChecks() noexcept
{
return qt_ntfs_permission_lookup_v2.fetchAndAddRelaxed(1)
+ qt_ntfs_permission_lookup
QT_IF_DEPRECATED_SINCE(6, 6, /*nothing*/, + qt_ntfs_permission_lookup)
!= 0;
}
@ -408,7 +412,7 @@ bool qEnableNtfsPermissionChecks() noexcept
bool qDisableNtfsPermissionChecks() noexcept
{
return qt_ntfs_permission_lookup_v2.fetchAndSubRelaxed(1)
+ qt_ntfs_permission_lookup
QT_IF_DEPRECATED_SINCE(6, 6, /*nothing*/, + qt_ntfs_permission_lookup)
== 1;
}
@ -421,8 +425,10 @@ bool qDisableNtfsPermissionChecks() noexcept
bool qAreNtfsPermissionChecksEnabled() noexcept
{
return qt_ntfs_permission_lookup_v2.loadRelaxed()
+ qt_ntfs_permission_lookup;
QT_IF_DEPRECATED_SINCE(6, 6, /*nothing*/, + qt_ntfs_permission_lookup)
;
}
QT_WARNING_POP
/*!
\class QNativeFilePermissions

View File

@ -171,7 +171,9 @@ private slots:
#ifdef Q_OS_WIN
void permissionsNtfs_data();
void permissionsNtfs();
#if QT_DEPRECATED_SINCE(6,6)
void deprecatedNtfsPermissionCheck();
#endif
#endif
void setPermissions_data();
void setPermissions();
@ -1418,6 +1420,9 @@ void tst_QFile::permissionsNtfs()
permissions();
}
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
#if QT_DEPRECATED_SINCE(6,6)
void tst_QFile::deprecatedNtfsPermissionCheck()
{
QScopedValueRollback<int> guard(qt_ntfs_permission_lookup);
@ -1428,6 +1433,8 @@ void tst_QFile::deprecatedNtfsPermissionCheck()
qt_ntfs_permission_lookup--;
QCOMPARE(qAreNtfsPermissionChecksEnabled(), false);
}
#endif
QT_WARNING_POP
#endif