diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-03-15 21:59:03 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-03-15 21:59:03 (GMT) |
commit | 077513815c65e70d569b8656935ac7783bf4c974 (patch) | |
tree | 0f6d106e754004da1d94fa0627f09837171d5512 /src/corelib/io | |
parent | fdcb62d5d6a3e295273042555d2551eb491a5b2d (diff) | |
parent | 3813e236a8f48babaa850123e3a2a04e80713219 (diff) | |
download | Qt-077513815c65e70d569b8656935ac7783bf4c974.zip Qt-077513815c65e70d569b8656935ac7783bf4c974.tar.gz Qt-077513815c65e70d569b8656935ac7783bf4c974.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1: (72 commits)
different approach to fixing "the other" aliasing issue
fix aliasing issue in node_construct()
detach in fewer cases, remove redundant calculation
SSL: Fix memleak related to local certificate
Improve keyboard layout detection on X11
Compile on ARM with -Werror -Wold-style-cast
Use the vista-style native dialog for QFileDialog::getExistingDirectory
Apply the stdset attribute for resource properties
doc: Completed sentence about HideNameFilterDetails
Doc fix in QLocale
Doc for for QGestureRecognizer::create.
Fix broken setCollectionFile (creating multiple models instead reusing)
Enable the fast paths when converting to Rgb565
qdoc: ifdefed out all the debug code.
Add missing QtScript API shims
Further fix license whitespace.
Remove NetworkManager test-bed application.
Remove configure test for NetworkManager.
Fix QDir::entryList regression
Add DEFINES to mingw32/windres.exe command line.
...
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qfileinfo.cpp | 51 | ||||
-rw-r--r-- | src/corelib/io/qfileinfo_p.h | 7 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine.cpp | 4 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_p.h | 4 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_unix.cpp | 68 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_win.cpp | 66 |
6 files changed, 83 insertions, 117 deletions
diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index 625098e..37591c5 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -41,7 +41,6 @@ #include "qplatformdefs.h" #include "qfileinfo.h" -#include "qfsfileengine_p.h" #include "qglobal.h" #include "qdir.h" #include "qfileinfo_p.h" @@ -75,50 +74,6 @@ void QFileInfoPrivate::initFileEngine(const QString &file) data->fileName = file; } -bool QFileInfoPrivate::hasAccess(Access access) const -{ - if (!(getFileFlags(QAbstractFileEngine::PermsMask - | QAbstractFileEngine::LocalDiskFlag) & QAbstractFileEngine::LocalDiskFlag)) { - switch (access) { - case ReadAccess: - return getFileFlags(QAbstractFileEngine::ReadUserPerm); - case WriteAccess: - return getFileFlags(QAbstractFileEngine::WriteUserPerm); - case ExecuteAccess: - return getFileFlags(QAbstractFileEngine::ExeUserPerm); - default: - return false; - } - } - - int mode = 0; - switch (access) { - case ReadAccess: - mode = R_OK; - break; - case WriteAccess: - mode = W_OK; - break; - case ExecuteAccess: - mode = X_OK; - break; - }; -#ifdef Q_OS_UNIX - return QT_ACCESS(QFile::encodeName(data->fileName).data(), mode) == 0; -#endif -#ifdef Q_OS_WIN - if ((access == ReadAccess && !getFileFlags(QAbstractFileEngine::ReadUserPerm)) - || (access == WriteAccess && !getFileFlags(QAbstractFileEngine::WriteUserPerm))) { - return false; - } - if (access == ExecuteAccess) - return getFileFlags(QAbstractFileEngine::ExeUserPerm); - - return ::_waccess((wchar_t*)QFSFileEnginePrivate::longFileName(data->fileName).utf16(), mode) == 0; -#endif - return false; -} - void QFileInfoPrivate::detach() { qAtomicDetach(data); @@ -893,7 +848,7 @@ bool QFileInfo::isReadable() const Q_D(const QFileInfo); if (!d->data->fileEngine) return false; - return d->hasAccess(QFileInfoPrivate::ReadAccess); + return d->getFileFlags(QAbstractFileEngine::ReadUserPerm); } /*! @@ -906,7 +861,7 @@ bool QFileInfo::isWritable() const Q_D(const QFileInfo); if (!d->data->fileEngine) return false; - return d->hasAccess(QFileInfoPrivate::WriteAccess); + return d->getFileFlags(QAbstractFileEngine::WriteUserPerm); } /*! @@ -919,7 +874,7 @@ bool QFileInfo::isExecutable() const Q_D(const QFileInfo); if (!d->data->fileEngine) return false; - return d->hasAccess(QFileInfoPrivate::ExecuteAccess); + return d->getFileFlags(QAbstractFileEngine::ExeUserPerm); } /*! diff --git a/src/corelib/io/qfileinfo_p.h b/src/corelib/io/qfileinfo_p.h index d97a0cf..306ffe1 100644 --- a/src/corelib/io/qfileinfo_p.h +++ b/src/corelib/io/qfileinfo_p.h @@ -68,13 +68,6 @@ public: void initFileEngine(const QString &); - enum Access { - ReadAccess, - WriteAccess, - ExecuteAccess - }; - bool hasAccess(Access access) const; - uint getFileFlags(QAbstractFileEngine::FileFlags) const; QDateTime &getFileTime(QAbstractFileEngine::FileTime) const; QString getFileName(QAbstractFileEngine::FileName) const; diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp index 070edb4..5e14804 100644 --- a/src/corelib/io/qfsfileengine.cpp +++ b/src/corelib/io/qfsfileengine.cpp @@ -1033,6 +1033,10 @@ bool QFSFileEngine::supportsExtension(Extension extension) const to store temporary files). */ +/*! \fn QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions(QAbstractFileEngine::FileFlags type) const + \internal +*/ + QT_END_NAMESPACE #endif // QT_NO_FSFILEENGINE diff --git a/src/corelib/io/qfsfileengine_p.h b/src/corelib/io/qfsfileengine_p.h index 0f63eb8..d07c3a0 100644 --- a/src/corelib/io/qfsfileengine_p.h +++ b/src/corelib/io/qfsfileengine_p.h @@ -156,9 +156,7 @@ protected: void init(); -#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) - QAbstractFileEngine::FileFlags getPermissions() const; -#endif + 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 1331f54..6df00d6 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -736,6 +736,46 @@ static bool _q_isMacHidden(const QString &path) } #endif +QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions(QAbstractFileEngine::FileFlags type) const +{ + QAbstractFileEngine::FileFlags ret = 0; + + if (st.st_mode & S_IRUSR) + ret |= QAbstractFileEngine::ReadOwnerPerm; + if (st.st_mode & S_IWUSR) + ret |= QAbstractFileEngine::WriteOwnerPerm; + if (st.st_mode & S_IXUSR) + ret |= QAbstractFileEngine::ExeOwnerPerm; + if (st.st_mode & S_IRGRP) + ret |= QAbstractFileEngine::ReadGroupPerm; + if (st.st_mode & S_IWGRP) + ret |= QAbstractFileEngine::WriteGroupPerm; + if (st.st_mode & S_IXGRP) + ret |= QAbstractFileEngine::ExeGroupPerm; + if (st.st_mode & S_IROTH) + ret |= QAbstractFileEngine::ReadOtherPerm; + if (st.st_mode & S_IWOTH) + ret |= QAbstractFileEngine::WriteOtherPerm; + if (st.st_mode & S_IXOTH) + ret |= QAbstractFileEngine::ExeOtherPerm; + + // calculate user permissions + 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; +} + /*! \reimp */ @@ -755,32 +795,8 @@ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(FileFlags type) const if (!exists && !d->isSymlink()) return ret; - if (exists && (type & PermsMask)) { - if (d->st.st_mode & S_IRUSR) - ret |= ReadOwnerPerm; - if (d->st.st_mode & S_IWUSR) - ret |= WriteOwnerPerm; - if (d->st.st_mode & S_IXUSR) - ret |= ExeOwnerPerm; - if (d->st.st_mode & S_IRUSR) - ret |= ReadUserPerm; - if (d->st.st_mode & S_IWUSR) - ret |= WriteUserPerm; - if (d->st.st_mode & S_IXUSR) - ret |= ExeUserPerm; - if (d->st.st_mode & S_IRGRP) - ret |= ReadGroupPerm; - if (d->st.st_mode & S_IWGRP) - ret |= WriteGroupPerm; - if (d->st.st_mode & S_IXGRP) - ret |= ExeGroupPerm; - if (d->st.st_mode & S_IROTH) - ret |= ReadOtherPerm; - if (d->st.st_mode & S_IWOTH) - ret |= WriteOtherPerm; - if (d->st.st_mode & S_IXOTH) - ret |= ExeOtherPerm; - } + if (exists && (type & PermsMask)) + 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 d8b1c03..8d34486 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -1405,10 +1405,7 @@ bool QFSFileEngine::link(const QString &newName) #endif // Q_OS_WINCE } -/*! - \internal -*/ -QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const +QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions(QAbstractFileEngine::FileFlags type) const { QAbstractFileEngine::FileFlags ret = 0; @@ -1429,7 +1426,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 +1436,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 +1447,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 +1458,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) @@ -1476,29 +1473,35 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const } } else #endif - { + { //### 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::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::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; + } + + // calculate user permissions + if (type & QAbstractFileEngine::ReadUserPerm) { + if (::_waccess((wchar_t*)longFileName(fname).utf16(), R_OK) == 0) + ret |= QAbstractFileEngine::ReadUserPerm; + } + if (type & QAbstractFileEngine::WriteUserPerm) { + if (::_waccess((wchar_t*)longFileName(fname).utf16(), W_OK) == 0) + ret |= QAbstractFileEngine::WriteUserPerm; } } return ret; @@ -1555,13 +1558,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(type); + } } if (type & TypesMask) { if (d->filePath.endsWith(QLatin1String(".lnk"))) { |