Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFile permission not reporting correctly

QFile permission not reporting correctly

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 6 Posters 3.5k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ocgltdO Offline
    ocgltdO Offline
    ocgltd
    wrote on last edited by ocgltd
    #1

    I have created file /tmp/abc for testing with QFile, and set file permissions to 000 from the command line. I noticed that I can correctly set permissions using QFile.setPermissions method (verified from command line).

    However, when I report the file permissions with the QFile.permissions method they report incorrectly. I'm running on Linux (FC34). If I step through the code below I can watch the permissions change (verified from shell "ls -la" command), yet my code always reports the same file permissions as shown below.

    Why are file permissions always reporting incorrectly?

    QFile myFile("/tmp/abc");
    QFileDevice::Permissions perm;
    qDebug() << "QFile permissions: " << myFile.permissions();
    if (myFile.setPermissions(perm))
        qDebug() << "QFile setPermissions successful";
    else
        qDebug() << "QFile setPermissions failed";
    qDebug() << "QFile permissions: " << myFile.permissions();
    perm.setFlag(QFileDevice::ExeOther);
    qDebug() << "perm is set to: " << perm;
    qDebug() << "QFile setPermissions attempted";
    if (myFile.setPermissions(perm))
        qDebug() << "QFile setPermissions successful";
    else
        qDebug() << "QFile setPermissions failed";
    qDebug() << "QFile permissions: " << myFile.permissions();
    

    and the output:

    QFile permissions:  QFlags(0x200|0x400|0x2000|0x4000)
    QFile setPermissions successful
    QFile permissions:  QFlags(0x200|0x400|0x2000|0x4000)
    perm is set to:  QFlags(0x1)
    QFile setPermissions successful
    QFile permissions:  QFlags(0x200|0x400|0x2000|0x4000)
    
    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #10

      Oh my, this should have been fixed, not closed :o

      (Z(:^

      1 Reply Last reply
      1
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #2

        Try an independent check (not through existing myFile object), like so:

        qDebug() << "QFile permissions: " << QFileInfo("/tmp/abc").permissions();
        

        (Z(:^

        ocgltdO 1 Reply Last reply
        3
        • sierdzioS sierdzio

          Try an independent check (not through existing myFile object), like so:

          qDebug() << "QFile permissions: " << QFileInfo("/tmp/abc").permissions();
          
          ocgltdO Offline
          ocgltdO Offline
          ocgltd
          wrote on last edited by
          #3

          @sierdzio They both report the exact same WRONG permissions. (Seems strange)

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Hi,

            I am wondering if there's not some cache that is used to store that information and your are accessing it again after the permission changed.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            ocgltdO 1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              I am wondering if there's not some cache that is used to store that information and your are accessing it again after the permission changed.

              ocgltdO Offline
              ocgltdO Offline
              ocgltd
              wrote on last edited by
              #5

              @SGaist I don't think so...simple SATA disk, no hardware cache inbetween. Software wise, just plain old linux...

              Or are you saying Qt might have a cache?

              JonBJ 1 Reply Last reply
              0
              • ocgltdO ocgltd

                @SGaist I don't think so...simple SATA disk, no hardware cache inbetween. Software wise, just plain old linux...

                Or are you saying Qt might have a cache?

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by JonB
                #6

                @ocgltd said in QFile permission not reporting correctly:

                Or are you saying Qt might have a cache?

                It might do, to speed repeated calls to the same file. The strange thing is it would not be surprising if you changing it externally via chmod did not make it update a cache it might have. But you would have thought that with myFile.setPermissions(perm) it would know to update any myFile.permissions() cached value correspondingly.

                ocgltdO 1 Reply Last reply
                0
                • JonBJ JonB

                  @ocgltd said in QFile permission not reporting correctly:

                  Or are you saying Qt might have a cache?

                  It might do, to speed repeated calls to the same file. The strange thing is it would not be surprising if you changing it externally via chmod did not make it update a cache it might have. But you would have thought that with myFile.setPermissions(perm) it would know to update any myFile.permissions() cached value correspondingly.

                  ocgltdO Offline
                  ocgltdO Offline
                  ocgltd
                  wrote on last edited by
                  #7

                  @JonB Yeah, if I changed via command line and Qt didn't see the change then I would suspect a cache. But if writing permissions from Qt I would expect it to update any Qt cache. I would have guess bug, but both QFile and QFileInfo suffering from the same bug makes me think I'm doing something wrong

                  JonBJ 1 Reply Last reply
                  0
                  • sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #8

                    Please report this on Qt bug tracker.

                    (Z(:^

                    1 Reply Last reply
                    0
                    • ocgltdO ocgltd

                      @JonB Yeah, if I changed via command line and Qt didn't see the change then I would suspect a cache. But if writing permissions from Qt I would expect it to update any Qt cache. I would have guess bug, but both QFile and QFileInfo suffering from the same bug makes me think I'm doing something wrong

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by JonB
                      #9

                      @ocgltd , @sierdzio
                      I checked this on my Ubuntu 20.04, Qt5.15, and it does indeed behave as you say. So then I looked and found bug QFile::permissions() returns old, cached value after call to QFile::setPermissions() on the same QFile object, Qt 4.6, Unresolved:

                      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.
                      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

                      This task is old and has been idle for a long time. It is therefore being closed on the assumption that it will not be addressed in the foreseeable future. If you really do care about this task, you may reopen it and vote for it.

                      It was created in 2010 and last updated in 2016. We agree it's a bit bad. You will have to use some alternative, e.g. maybe the static QFile permissions methods work, or the QFileInfo ones.

                      1 Reply Last reply
                      1
                      • sierdzioS Offline
                        sierdzioS Offline
                        sierdzio
                        Moderators
                        wrote on last edited by
                        #10

                        Oh my, this should have been fixed, not closed :o

                        (Z(:^

                        1 Reply Last reply
                        1
                        • Christian EhrlicherC Online
                          Christian EhrlicherC Online
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #11

                          Reopened: https://bugreports.qt.io/browse/QTBUG-7211

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          1 Reply Last reply
                          3
                          • sierdzioS Offline
                            sierdzioS Offline
                            sierdzio
                            Moderators
                            wrote on last edited by
                            #12

                            Thanks! Voted.

                            (Z(:^

                            1 Reply Last reply
                            0
                            • Christian EhrlicherC Online
                              Christian EhrlicherC Online
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #13

                              There is also already a patch for it... sometimes it's interesting to see how long bugs linger around and then a small change (here: chooinsg the correct maintainer) suddenly fixes it :)

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              1 Reply Last reply
                              1
                              • HoMaH Offline
                                HoMaH Offline
                                HoMa
                                wrote on last edited by
                                #14

                                I guess you can just use the static function!?

                                JonBJ 1 Reply Last reply
                                0
                                • HoMaH HoMa

                                  I guess you can just use the static function!?

                                  JonBJ Online
                                  JonBJ Online
                                  JonB
                                  wrote on last edited by JonB
                                  #15

                                  @HoMa
                                  I suggested earlier that the OP could try that, but there is no guarantee it will behave any differently. The cache may be by filepath, not by QFile/QFileInfo instance, we don't know.

                                  HoMaH 1 Reply Last reply
                                  0
                                  • JonBJ JonB

                                    @HoMa
                                    I suggested earlier that the OP could try that, but there is no guarantee it will behave any differently. The cache may be by filepath, not by QFile/QFileInfo instance, we don't know.

                                    HoMaH Offline
                                    HoMaH Offline
                                    HoMa
                                    wrote on last edited by
                                    #16

                                    @JonB Sorry - I missed that.

                                    JonBJ 1 Reply Last reply
                                    0
                                    • HoMaH HoMa

                                      @JonB Sorry - I missed that.

                                      JonBJ Online
                                      JonBJ Online
                                      JonB
                                      wrote on last edited by JonB
                                      #17

                                      @HoMa Not a problem :) I'm just saying it may or may not make any difference! But worth a try.

                                      ocgltdO 1 Reply Last reply
                                      0
                                      • JonBJ JonB

                                        @HoMa Not a problem :) I'm just saying it may or may not make any difference! But worth a try.

                                        ocgltdO Offline
                                        ocgltdO Offline
                                        ocgltd
                                        wrote on last edited by
                                        #18

                                        @JonB I'll use the workaround thanks. I couldn't imagine I found such a bug..so I assumed it must be my code.

                                        JonBJ 1 Reply Last reply
                                        0
                                        • ocgltdO ocgltd

                                          @JonB I'll use the workaround thanks. I couldn't imagine I found such a bug..so I assumed it must be my code.

                                          JonBJ Online
                                          JonBJ Online
                                          JonB
                                          wrote on last edited by
                                          #19

                                          @ocgltd said in QFile permission not reporting correctly:

                                          I couldn't imagine I found such a bug.

                                          You produced a simple example, minimal code, clear output to show bad behaviour. If everybody did similar that would be really great :)

                                          1 Reply Last reply
                                          1

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved