diff options
author | Martin Smith <msmith@trolltech.com> | 2010-03-11 08:14:39 (GMT) |
---|---|---|
committer | Martin Smith <msmith@trolltech.com> | 2010-03-11 08:14:39 (GMT) |
commit | b5d9d2eb1fbfbbf2732e90ef4d6a3e3ae5104c0c (patch) | |
tree | e224a95589b45d268c79ee55911f9eb85a9eb1b6 /src/corelib/io | |
parent | a21ac7e75730bb094b49e5b58698a2ceebe8d73e (diff) | |
parent | c75bd51df44359c386149c6962532344123b07d5 (diff) | |
download | Qt-b5d9d2eb1fbfbbf2732e90ef4d6a3e3ae5104c0c.zip Qt-b5d9d2eb1fbfbbf2732e90ef4d6a3e3ae5104c0c.tar.gz Qt-b5d9d2eb1fbfbbf2732e90ef4d6a3e3ae5104c0c.tar.bz2 |
Merge branch '4.7' of git@scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7
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_p.h | 4 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_unix.cpp | 71 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_win.cpp | 65 | ||||
-rw-r--r-- | src/corelib/io/qtextstream.cpp | 3 |
6 files changed, 87 insertions, 114 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_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..42ccc2d 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -737,6 +737,49 @@ static bool _q_isMacHidden(const QString &path) #endif /*! + \internal +*/ +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 */ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(FileFlags type) const @@ -755,32 +798,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..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) @@ -1480,25 +1480,35 @@ 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::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; + } + + // calculate user permissions + 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; @@ -1555,13 +1565,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"))) { diff --git a/src/corelib/io/qtextstream.cpp b/src/corelib/io/qtextstream.cpp index 9e79894..b1c403f 100644 --- a/src/corelib/io/qtextstream.cpp +++ b/src/corelib/io/qtextstream.cpp @@ -70,7 +70,7 @@ static const int QTEXTSTREAM_BUFFERSIZE = 16384; have reached the end of the data stream, with stdin. The reason for this is that as long as stdin doesn't give any input to the QTextStream, \c atEnd() will return true even if the stdin is open and waiting for more characters. - + Besides using QTextStream's constructors, you can also set the device or string QTextStream operates on by calling setDevice() or setString(). You can seek to a position by calling seek(), and @@ -1196,6 +1196,7 @@ bool QTextStream::seek(qint64 pos) resetCodecConverterStateHelper(&d->writeConverterState); delete d->readConverterSavedState; d->readConverterSavedState = 0; + d->writeConverterState.flags |= QTextCodec::IgnoreHeader; #endif return true; } |