Description
The example program included inline demonstrates a problem I see with the implementations of the isReadable() methods on Linux. Assume a directory and a file with permissions 070, 060 resp. For both I am not the owner, but since I am a member of the same group "develop"
as the owner, I am allowed to read the file and list the directory and
change into the directory (which can be tested by using "cat" on the file and "ls" and "cd" on the directory).
bernd@corot:~/incoming> ls -ld file dir
d--rwx-- 2 andre develop 4096 2008-09-15 13:31 dir
---rw--- 1 andre develop 5 2008-09-15 13:29 file
The output of the program is:
fi1.isReadable 1
fi2.isReadable 1
dir.isReadable 0
That means, QFileInfo correctly recognizes that I have read permissions on the file and the directory. From the implementation it becomes clear that this is due to Qt's usage of the POSIX access() function in QFileInfoPrivate::hasAccess().
However, QDir works differently: it only evaluates the ReadUserPerm flag
from the method QAbstractFileEngine::fileFlags() and doesn't take the group permissions into consideration.
This difference is not evident from the documentation of the two methods. I would expect either that the implementation is changed accordingly or that the difference is explained more clearly.
This all applies to both Qt 4.3.2, Qt 4.4.0 and Qt 4.4.1 on Linux.
program code:
#include <QtCore/QFileInfo> #include <QtCore/QDir> int main (int /*argc*/, char ** /*argv*/) { QFileInfo fi1 ("file"); QFileInfo fi2 ("dir"); QDir dir ("dir"); qDebug ("fi1.isReadable %d", fi1.isReadable ()); qDebug ("fi2.isReadable %d", fi2.isReadable ()); qDebug ("dir.isReadable %d", dir.isReadable ()); return 0; }