diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2010-08-31 11:17:15 (GMT) |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2010-09-07 12:17:11 (GMT) |
commit | 3505c6cdcdfac5a6d0f4b94dbdbcc8ad72f8048a (patch) | |
tree | c2c93f0df90882122f7fde5ac07683f7f7a8b4f0 | |
parent | b0de175aab06092932077eb1c5fb3f89691b6014 (diff) | |
download | Qt-3505c6cdcdfac5a6d0f4b94dbdbcc8ad72f8048a.zip Qt-3505c6cdcdfac5a6d0f4b94dbdbcc8ad72f8048a.tar.gz Qt-3505c6cdcdfac5a6d0f4b94dbdbcc8ad72f8048a.tar.bz2 |
QDir: Removed checks for existance of fileEngine
Directly or indirectly, all instances of QDir call QDirPrivate::setPath,
which allocates a file engine and dereferences it. Any failures there
should already lead to a crash or a bad_alloc exception being thrown in
case of failure.
Given that, QDir may be (and was) broken when compiling Qt with
QT_NO_FSFILEENGINE, if no custom file engine and handler are provided.
This being the case, it's pointless to check fileEngine for null all
over the place. This simplifies the code and should allow for easier
transition to file-engine-less implementation.
Reviewed-by: Thomas Zander
-rw-r--r-- | src/corelib/io/qdir.cpp | 57 |
1 files changed, 8 insertions, 49 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 6393509..fcd17f7 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -97,7 +97,6 @@ public: , filterSepChar(0) , matchAllDirs(false) #endif - , fileEngine(0) , fileListsInitialized(false) { setPath(path.isEmpty() ? QString::fromLatin1(".") : path); @@ -126,20 +125,12 @@ public: , filterSepChar(copy.filterSepChar) , matchAllDirs(copy.matchAllDirs) #endif - , fileEngine(0) , fileListsInitialized(false) { } - ~QDirPrivate() - { - delete fileEngine; - } - bool exists() const { - if (!fileEngine) - return false; const QAbstractFileEngine::FileFlags info = fileEngine->fileFlags(QAbstractFileEngine::DirectoryType | QAbstractFileEngine::ExistsFlag @@ -183,8 +174,8 @@ public: p.truncate(p.length() - 1); } - delete fileEngine; - fileEngine = QAbstractFileEngine::create(p); + path = p; + initFileEngine(); // set the path to be the qt friendly version so then we can operate on it using just / path = fileEngine->fileName(QAbstractFileEngine::DefaultName); @@ -207,7 +198,7 @@ public: bool matchAllDirs; #endif - QAbstractFileEngine *fileEngine; + QScopedPointer<QAbstractFileEngine> fileEngine; mutable bool fileListsInitialized; mutable QStringList files; @@ -339,11 +330,9 @@ inline void QDirPrivate::initFileLists() const } } -void QDirPrivate::initFileEngine() +inline void QDirPrivate::initFileEngine() { - QAbstractFileEngine *newFileEngine = QAbstractFileEngine::create(path); - delete fileEngine; - fileEngine = newFileEngine; + fileEngine.reset(QAbstractFileEngine::create(path)); } /*! @@ -646,11 +635,7 @@ QString QDir::absolutePath() const */ QString QDir::canonicalPath() const { - const QDirPrivate* d = d_ptr.constData(); - - if (!d->fileEngine) - return QLatin1String(""); - return cleanPath(d->fileEngine->fileName(QAbstractFileEngine::CanonicalName)); + return cleanPath(d_ptr->fileEngine->fileName(QAbstractFileEngine::CanonicalName)); } /*! @@ -710,8 +695,6 @@ QString QDir::absoluteFilePath(const QString &fileName) const const QDirPrivate* d = d_ptr.constData(); if (isAbsolutePath(fileName)) return fileName; - if (!d->fileEngine) - return fileName; QString ret; #ifndef QT_NO_FSFILEENGINE @@ -1392,8 +1375,6 @@ bool QDir::mkdir(const QString &dirName) const qWarning("QDir::mkdir: Empty or null file name(s)"); return false; } - if (!d->fileEngine) - return false; QString fn = filePath(dirName); return d->fileEngine->mkdir(fn, false); @@ -1416,8 +1397,6 @@ bool QDir::rmdir(const QString &dirName) const qWarning("QDir::rmdir: Empty or null file name(s)"); return false; } - if (!d->fileEngine) - return false; QString fn = filePath(dirName); return d->fileEngine->rmdir(fn, false); @@ -1441,8 +1420,6 @@ bool QDir::mkpath(const QString &dirPath) const qWarning("QDir::mkpath: Empty or null file name(s)"); return false; } - if (!d->fileEngine) - return false; QString fn = filePath(dirPath); return d->fileEngine->mkdir(fn, true); @@ -1467,8 +1444,6 @@ bool QDir::rmpath(const QString &dirPath) const qWarning("QDir::rmpath: Empty or null file name(s)"); return false; } - if (!d->fileEngine) - return false; QString fn = filePath(dirPath); return d->fileEngine->rmdir(fn, true); @@ -1487,8 +1462,6 @@ bool QDir::isReadable() const { const QDirPrivate* d = d_ptr.constData(); - if (!d->fileEngine) - return false; const QAbstractFileEngine::FileFlags info = d->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType | QAbstractFileEngine::PermsMask); @@ -1527,11 +1500,7 @@ bool QDir::exists() const */ bool QDir::isRoot() const { - const QDirPrivate* d = d_ptr.constData(); - - if (!d->fileEngine) - return true; - return d->fileEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::RootFlag; + return d_ptr->fileEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::RootFlag; } /*! @@ -1561,11 +1530,7 @@ bool QDir::isRoot() const */ bool QDir::isRelative() const { - const QDirPrivate* d = d_ptr.constData(); - - if (!d->fileEngine) - return false; - return d->fileEngine->isRelativePath(); + return d_ptr->fileEngine->isRelativePath(); } @@ -1578,8 +1543,6 @@ bool QDir::isRelative() const */ bool QDir::makeAbsolute() // ### What do the return values signify? { - if (!d_ptr.constData()->fileEngine) - return false; QString absolutePath = d_ptr.constData()->fileEngine->fileName(QAbstractFileEngine::AbsoluteName); if (QDir::isRelativePath(absolutePath)) return false; @@ -1610,7 +1573,6 @@ bool QDir::operator==(const QDir &dir) const if (d == other) return true; - Q_ASSERT(d->fileEngine && other->fileEngine); if (d->fileEngine->caseSensitive() != other->fileEngine->caseSensitive()) return false; if (d->filters == other->filters @@ -1695,9 +1657,6 @@ bool QDir::rename(const QString &oldName, const QString &newName) return false; } - if (!d_ptr.constData()->fileEngine) - return false; - QFile file(filePath(oldName)); if (!file.exists()) return false; |