diff options
author | Ritt Konstantin <ritt.ks@gmail.com> | 2010-03-09 13:57:23 (GMT) |
---|---|---|
committer | João Abecasis <joao@trolltech.com> | 2010-03-09 15:46:30 (GMT) |
commit | 6fb8d8af7cc9d3f7e90c0534aa2ec90dd7289176 (patch) | |
tree | 7c6c6d05b704709920272a14ec22782657af3fdd | |
parent | 9b6c5a82b3693068e2db321c30be8c2e5f43b680 (diff) | |
download | Qt-6fb8d8af7cc9d3f7e90c0534aa2ec90dd7289176.zip Qt-6fb8d8af7cc9d3f7e90c0534aa2ec90dd7289176.tar.gz Qt-6fb8d8af7cc9d3f7e90c0534aa2ec90dd7289176.tar.bz2 |
In QFSFileEngine::fileFlags call getPermissions() only if entry exists
By calling doStat earlier and avoiding calling getPermissions if stat
fails, we can assume doStat has been called inside getPermissions. We
can also avoid the workaround for having all permissions set by default.
Moved the check for FILE_ATTRIBUTE_DIRECTORY earlier in if condition,
which should be cheaper.
Merge-request: 428
Reviewed-by: João Abecasis <joao@trolltech.com>
-rw-r--r-- | src/corelib/io/qfsfileengine_win.cpp | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index d8b1c03..72eb081 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -1480,25 +1480,21 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const //### what to do with permissions if we don't use NTFS // for now just add all permissions and what about exe missions ?? // also qt_ntfs_permission_lookup is now not set by default ... should it ? - ret |= QAbstractFileEngine::ReadOtherPerm | QAbstractFileEngine::ReadGroupPerm - | QAbstractFileEngine::ReadOwnerPerm | QAbstractFileEngine::ReadUserPerm - | QAbstractFileEngine::WriteUserPerm | QAbstractFileEngine::WriteOwnerPerm - | QAbstractFileEngine::WriteGroupPerm | QAbstractFileEngine::WriteOtherPerm; - - if (doStat()) { - if (ret & (QAbstractFileEngine::WriteOwnerPerm | QAbstractFileEngine::WriteUserPerm | - QAbstractFileEngine::WriteGroupPerm | QAbstractFileEngine::WriteOtherPerm)) { - if (fileAttrib & FILE_ATTRIBUTE_READONLY) - ret &= ~(QAbstractFileEngine::WriteOwnerPerm | QAbstractFileEngine::WriteUserPerm | - QAbstractFileEngine::WriteGroupPerm | QAbstractFileEngine::WriteOtherPerm); - } + ret |= QAbstractFileEngine::ReadOwnerPerm | QAbstractFileEngine::ReadUserPerm + | QAbstractFileEngine::ReadGroupPerm | QAbstractFileEngine::ReadOtherPerm; - QString fname = filePath.endsWith(QLatin1String(".lnk")) ? readLink(filePath) : filePath; - QString ext = fname.right(4).toLower(); - if (ext == QLatin1String(".exe") || ext == QLatin1String(".com") || ext == QLatin1String(".bat") || - ext == QLatin1String(".pif") || ext == QLatin1String(".cmd") || (fileAttrib & FILE_ATTRIBUTE_DIRECTORY)) - ret |= QAbstractFileEngine::ExeOwnerPerm | QAbstractFileEngine::ExeGroupPerm | - QAbstractFileEngine::ExeOtherPerm | QAbstractFileEngine::ExeUserPerm; + if (!(fileAttrib & FILE_ATTRIBUTE_READONLY)) { + ret |= QAbstractFileEngine::WriteOwnerPerm | QAbstractFileEngine::WriteUserPerm + | QAbstractFileEngine::WriteGroupPerm | QAbstractFileEngine::WriteOtherPerm; + } + + QString fname = filePath.endsWith(QLatin1String(".lnk")) ? readLink(filePath) : filePath; + QString ext = fname.right(4).toLower(); + if ((fileAttrib & FILE_ATTRIBUTE_DIRECTORY) || + ext == QLatin1String(".exe") || ext == QLatin1String(".com") || ext == QLatin1String(".bat") || + ext == QLatin1String(".pif") || ext == QLatin1String(".cmd")) { + ret |= QAbstractFileEngine::ExeOwnerPerm | QAbstractFileEngine::ExeGroupPerm | + QAbstractFileEngine::ExeOtherPerm | QAbstractFileEngine::ExeUserPerm; } } return ret; @@ -1555,13 +1551,10 @@ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(QAbstractFileEngine::Fil } if (type & PermsMask) { - ret |= d->getPermissions(); - // ### Workaround pascals ### above. Since we always set all properties to true - // we need to disable read and exec access if the file does not exists - if (d->doStat()) + if (d->doStat()) { ret |= ExistsFlag; - else - ret &= 0x2222; + ret |= d->getPermissions(); + } } if (type & TypesMask) { if (d->filePath.endsWith(QLatin1String(".lnk"))) { |