QFileDevice: clear cached permissions on setPermission()
In theory, if we succeed, the permissions should be what we set, but let's not make that assumption. And if we failed, it might be because the file disappeared or something else, so re-stat()ing the file is a good idea. Fixes: QTBUG-7211 Change-Id: If5d5ef6220874ae8858efffd171255506b7bbee0 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 4b997d1851bc62b9a1eb761f08d3b22c85bb0b51) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
f2c00dd038
commit
ea9e8cc7e0
@ -489,6 +489,10 @@ bool QFSFileEngine::setPermissions(uint perms)
|
||||
Q_D(QFSFileEngine);
|
||||
QSystemError error;
|
||||
bool ok;
|
||||
|
||||
// clear cached state (if any)
|
||||
d->metaData.clearFlags(QFileSystemMetaData::Permissions);
|
||||
|
||||
if (d->fd != -1)
|
||||
ok = QFileSystemEngine::setPermissions(d->fd, QFile::Permissions(perms), error);
|
||||
else
|
||||
|
@ -655,6 +655,10 @@ bool QFSFileEngine::setPermissions(uint perms)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
QSystemError error;
|
||||
|
||||
// clear cached state (if any)
|
||||
d->metaData.clearFlags(QFileSystemMetaData::Permissions);
|
||||
|
||||
bool ret = QFileSystemEngine::setPermissions(d->fileEntry, QFile::Permissions(perms), error);
|
||||
if (!ret)
|
||||
setError(QFile::PermissionsError, error.toString());
|
||||
|
@ -1419,6 +1419,9 @@ void tst_QFile::permissionsNtfs()
|
||||
|
||||
void tst_QFile::setPermissions()
|
||||
{
|
||||
#ifdef Q_OS_QNX
|
||||
QSKIP("This test doesn't pass on QNX and no one has cared to investigate.");
|
||||
#endif
|
||||
if ( QFile::exists( "createme.txt" ) )
|
||||
QFile::remove( "createme.txt" );
|
||||
QVERIFY( !QFile::exists( "createme.txt" ) );
|
||||
@ -1429,9 +1432,12 @@ void tst_QFile::setPermissions()
|
||||
f.close();
|
||||
|
||||
QFile::Permissions perms(QFile::WriteUser | QFile::ReadUser);
|
||||
QVERIFY(f.setPermissions(QFile::ReadUser));
|
||||
QVERIFY((f.permissions() & perms) == QFile::ReadUser);
|
||||
QVERIFY(f.setPermissions(perms));
|
||||
QVERIFY((f.permissions() & perms) == perms);
|
||||
|
||||
// we should end the test with the file in writeable state
|
||||
}
|
||||
|
||||
void tst_QFile::copy()
|
||||
|
Loading…
x
Reference in New Issue
Block a user