Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-7211

QFile::permissions() returns old, cached value after call to QFile::setPermissions() on the same QFile object

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3: Somewhat important
    • 6.4, 6.5.0 Beta1
    • 4.6.0, 5.15.5
    • Core: I/O
    • 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.

      Attachments

        For Gerrit Dashboard: QTBUG-7211
        # Subject Branch Project Status CR V

        Activity

          People

            thiago Thiago Macieira
            robertknight Robert Knight
            Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes