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

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Fixed
    • Affects Version/s: 4.6.0, 5.15.5
    • Fix Version/s: 6.4, 6.5.0 Beta1
    • Component/s: Core: I/O
    • Labels:
      None
    • Commits:
      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

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            thiago Thiago Macieira
            Reporter:
            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