diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2010-08-31 07:56:27 (GMT) |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2010-09-07 12:17:10 (GMT) |
commit | b0de175aab06092932077eb1c5fb3f89691b6014 (patch) | |
tree | 234528d2f057de9e213d61f17a611836b952c366 /src/corelib/io | |
parent | 8e8743113f642e82bac6ecc055d2d3be8f53d7a6 (diff) | |
download | Qt-b0de175aab06092932077eb1c5fb3f89691b6014.zip Qt-b0de175aab06092932077eb1c5fb3f89691b6014.tar.gz Qt-b0de175aab06092932077eb1c5fb3f89691b6014.tar.bz2 |
QDir and QFileInfo shouldn't lose properties when detaching
For QFileInfo, the caching state was being lost on the different setFile
overloads. QDir::cd and ::makeAbsolute were losing filters and sorting
flags.
QDir issues were introduced with these patches:
"Simplify QDir::cd"
"QDir::makeAbsolute could self-destruct on failure"
Reviewed-by: Prasanth Ullattil
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qdir.cpp | 41 | ||||
-rw-r--r-- | src/corelib/io/qfileinfo.cpp | 8 |
2 files changed, 29 insertions, 20 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index b126c6d..6393509 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -136,6 +136,19 @@ public: delete fileEngine; } + bool exists() const + { + if (!fileEngine) + return false; + const QAbstractFileEngine::FileFlags info = + fileEngine->fileFlags(QAbstractFileEngine::DirectoryType + | QAbstractFileEngine::ExistsFlag + | QAbstractFileEngine::Refresh); + if (!(info & QAbstractFileEngine::DirectoryType)) + return false; + return info & QAbstractFileEngine::ExistsFlag; + } + void initFileEngine(); void initFileLists() const; @@ -891,11 +904,13 @@ bool QDir::cd(const QString &dirName) } } - QDir dir(newPath); - if (!dir.exists()) + QScopedPointer<QDirPrivate> dir(new QDirPrivate(*d_ptr.constData())); + dir->setPath(newPath); + + if (!dir->exists()) return false; - *this = dir; + d_ptr = dir.take(); return true; } @@ -1495,17 +1510,7 @@ bool QDir::isReadable() const */ bool QDir::exists() const { - const QDirPrivate* d = d_ptr.constData(); - - if (!d->fileEngine) - return false; - const QAbstractFileEngine::FileFlags info = - d->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType - | QAbstractFileEngine::ExistsFlag - | QAbstractFileEngine::Refresh); - if (!(info & QAbstractFileEngine::DirectoryType)) - return false; - return info & QAbstractFileEngine::ExistsFlag; + return d_ptr->exists(); } /*! @@ -1579,11 +1584,13 @@ bool QDir::makeAbsolute() // ### What do the return values signify? if (QDir::isRelativePath(absolutePath)) return false; - QDir dir(absolutePath); - if (!(dir.d_ptr.constData()->fileEngine->fileFlags(QAbstractFileEngine::TypesMask) & QAbstractFileEngine::DirectoryType)) + QScopedPointer<QDirPrivate> dir(new QDirPrivate(*d_ptr.constData())); + dir->setPath(absolutePath); + + if (!(dir->fileEngine->fileFlags(QAbstractFileEngine::TypesMask) & QAbstractFileEngine::DirectoryType)) return false; - *this = dir; + d_ptr = dir.take(); return true; } diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index 248b83d..7eca212 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -395,7 +395,9 @@ QFileInfo &QFileInfo::operator=(const QFileInfo &fileinfo) */ void QFileInfo::setFile(const QString &file) { + bool caching = d_ptr.constData()->cache_enabled; *this = QFileInfo(file); + d_ptr->cache_enabled = caching; } /*! @@ -411,7 +413,7 @@ void QFileInfo::setFile(const QString &file) */ void QFileInfo::setFile(const QFile &file) { - *this = QFileInfo(file.fileName()); + setFile(file.fileName()); } /*! @@ -427,7 +429,7 @@ void QFileInfo::setFile(const QFile &file) */ void QFileInfo::setFile(const QDir &dir, const QString &file) { - *this = QFileInfo(dir.filePath(file)); + setFile(dir.filePath(file)); } /*! @@ -579,7 +581,7 @@ bool QFileInfo::makeAbsolute() QString absFileName = d_ptr.constData()->getFileName(QAbstractFileEngine::AbsoluteName); // QSharedDataPointer::operator->() will detach. - *this = QFileInfo(absFileName); + setFile(absFileName); return true; } |