Details
-
Bug
-
Resolution: Fixed
-
P3: Somewhat important
-
4.6.0, 5.15.5
-
None
-
864fbd65828e0e84e588c896d778ae523a30e97b (qt/qtbase/dev) 4b997d1851 (qt/tqtc-qtbase/dev) ea9e8cc7e0 (qt/qtbase/6.4) ea9e8cc7e0 (qt/tqtc-qtbase/6.4)
Description
Calling QFile::permissions() returns an out-of-date value after calling QFile::setPermissions() on the same object.
I can understand why QFile would not detect changes to the file's permissions outside of the QFile object, although if the permissions
change is done via QFile::setPermissions() then the object can clear its cached value automatically.
Test case:
#include <QtCore/QFile> #include <QtDebug> int main(int,char**) { // create a file QFile file("test-file"); file.open(QIODevice::WriteOnly); file.write(QByteArray("some data")); file.close(); if (file.setPermissions(file.permissions() | QFile::WriteOther)) { qDebug() << "new permissions (using old QFile object)" << (file.permissions() & QFile::WriteOther); qDebug() << "new permissions (using new QFile object)" << (QFile("test-file").permissions() & QFile::WriteOther); } file.remove(); return 0; }
Alternatively, the fact that permissions() returns a cached value should be documented.
A related issue is that there is no explicit refresh() method for QFile as there is for QFileInfo, although QFile::exists() does trigger a refresh when called.