From 3a1e96fc9d5844583138d183e95e127a034daf56 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Tue, 9 Mar 2010 14:57:29 +0100 Subject: QFSFileEngine reduce number of system calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit for isolated calls to QFileInfo::isReadable, isExecutable and isWritable. Merge-request: 428 Reviewed-by: João Abecasis --- src/corelib/io/qfsfileengine_p.h | 2 +- src/corelib/io/qfsfileengine_unix.cpp | 22 ++++++++++++++-------- src/corelib/io/qfsfileengine_win.cpp | 30 ++++++++++++++++++------------ 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/corelib/io/qfsfileengine_p.h b/src/corelib/io/qfsfileengine_p.h index c540173..d07c3a0 100644 --- a/src/corelib/io/qfsfileengine_p.h +++ b/src/corelib/io/qfsfileengine_p.h @@ -156,7 +156,7 @@ protected: void init(); - QAbstractFileEngine::FileFlags getPermissions() const; + QAbstractFileEngine::FileFlags getPermissions(QAbstractFileEngine::FileFlags type) const; }; QT_END_NAMESPACE diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index d63a088..42ccc2d 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -739,7 +739,7 @@ static bool _q_isMacHidden(const QString &path) /*! \internal */ -QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const +QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions(QAbstractFileEngine::FileFlags type) const { QAbstractFileEngine::FileFlags ret = 0; @@ -763,12 +763,18 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const ret |= QAbstractFileEngine::ExeOtherPerm; // calculate user permissions - if (QT_ACCESS(nativeFilePath.constData(), R_OK) == 0) - ret |= QAbstractFileEngine::ReadUserPerm; - if (QT_ACCESS(nativeFilePath.constData(), W_OK) == 0) - ret |= QAbstractFileEngine::WriteUserPerm; - if (QT_ACCESS(nativeFilePath.constData(), X_OK) == 0) - ret |= QAbstractFileEngine::ExeUserPerm; + if (type & QAbstractFileEngine::ReadUserPerm) { + if (QT_ACCESS(nativeFilePath.constData(), R_OK) == 0) + ret |= QAbstractFileEngine::ReadUserPerm; + } + if (type & QAbstractFileEngine::WriteUserPerm) { + if (QT_ACCESS(nativeFilePath.constData(), W_OK) == 0) + ret |= QAbstractFileEngine::WriteUserPerm; + } + if (type & QAbstractFileEngine::ExeUserPerm) { + if (QT_ACCESS(nativeFilePath.constData(), X_OK) == 0) + ret |= QAbstractFileEngine::ExeUserPerm; + } return ret; } @@ -793,7 +799,7 @@ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(FileFlags type) const return ret; if (exists && (type & PermsMask)) - ret |= d->getPermissions(); + ret |= d->getPermissions(type); if (type & TypesMask) { #if !defined(QWS) && defined(Q_OS_MAC) bool foundAlias = false; diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index ecfb17a..761b847 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -1408,7 +1408,7 @@ bool QFSFileEngine::link(const QString &newName) /*! \internal */ -QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const +QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions(QAbstractFileEngine::FileFlags type) const { QAbstractFileEngine::FileFlags ret = 0; @@ -1429,7 +1429,7 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const if(res == ERROR_SUCCESS) { ACCESS_MASK access_mask; TRUSTEE_W trustee; - { //user + if (type & 0x0700) { // user if(ptrGetEffectiveRightsFromAclW(pDacl, ¤tUserTrusteeW, &access_mask) != ERROR_SUCCESS) access_mask = (ACCESS_MASK)-1; if(access_mask & ReadMask) @@ -1439,7 +1439,7 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const if(access_mask & ExecMask) ret |= QAbstractFileEngine::ExeUserPerm; } - { //owner + if (type & 0x7000) { // owner ptrBuildTrusteeWithSidW(&trustee, pOwner); if(ptrGetEffectiveRightsFromAclW(pDacl, &trustee, &access_mask) != ERROR_SUCCESS) access_mask = (ACCESS_MASK)-1; @@ -1450,7 +1450,7 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const if(access_mask & ExecMask) ret |= QAbstractFileEngine::ExeOwnerPerm; } - { //group + if (type & 0x0070) { // group ptrBuildTrusteeWithSidW(&trustee, pGroup); if(ptrGetEffectiveRightsFromAclW(pDacl, &trustee, &access_mask) != ERROR_SUCCESS) access_mask = (ACCESS_MASK)-1; @@ -1461,7 +1461,7 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const if(access_mask & ExecMask) ret |= QAbstractFileEngine::ExeGroupPerm; } - { //other (world) + if (type & 0x0007) { // other (world) if(ptrGetEffectiveRightsFromAclW(pDacl, &worldTrusteeW, &access_mask) != ERROR_SUCCESS) access_mask = (ACCESS_MASK)-1; // ### if(access_mask & ReadMask) @@ -1498,12 +1498,18 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const } // calculate user permissions - if (::_waccess((wchar_t*)longFileName(filePath).utf16(), R_OK) == 0) - ret |= QAbstractFileEngine::ReadUserPerm; - if (::_waccess((wchar_t*)longFileName(filePath).utf16(), W_OK) == 0) - ret |= QAbstractFileEngine::WriteUserPerm; - if (::_waccess((wchar_t*)longFileName(filePath).utf16(), X_OK) == 0) - ret |= QAbstractFileEngine::ExeUserPerm; + if (type & QAbstractFileEngine::ReadUserPerm) { + if (::_waccess((wchar_t*)longFileName(filePath).utf16(), R_OK) == 0) + ret |= QAbstractFileEngine::ReadUserPerm; + } + if (type & QAbstractFileEngine::WriteUserPerm) { + if (::_waccess((wchar_t*)longFileName(filePath).utf16(), W_OK) == 0) + ret |= QAbstractFileEngine::WriteUserPerm; + } + if (type & QAbstractFileEngine::ExeUserPerm) { + if (::_waccess((wchar_t*)longFileName(filePath).utf16(), X_OK) == 0) + ret |= QAbstractFileEngine::ExeUserPerm; + } } return ret; } @@ -1561,7 +1567,7 @@ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(QAbstractFileEngine::Fil if (type & PermsMask) { if (d->doStat()) { ret |= ExistsFlag; - ret |= d->getPermissions(); + ret |= d->getPermissions(type); } } if (type & TypesMask) { -- cgit v0.12