#include "qplatformdefs.h"
#include "qdir.h"
#include "qdir_p.h"
-#include "qabstractfileengine.h"
#ifndef QT_NO_DEBUG_STREAM
#include "qdebug.h"
#endif
, nameFilters(nameFilters_)
, sort(sort_)
, filters(filters_)
- , fileEngine(nullptr)
, fileListsInitialized(false)
{
setPath(path.isEmpty() ? QString::fromLatin1(".") : path);
, nameFilters(copy.nameFilters)
, sort(copy.sort)
, filters(copy.filters)
- , fileEngine(nullptr)
, fileListsInitialized(false)
, dirEntry(copy.dirEntry)
, metaData(copy.metaData)
QDirPrivate::~QDirPrivate()
{
- delete fileEngine;
}
bool QDirPrivate::exists() const
{
- if (!fileEngine) {
- QFileSystemEngine::fillMetaData(dirEntry, metaData,
- QFileSystemMetaData::ExistsAttribute | QFileSystemMetaData::DirectoryType); // always stat
- return metaData.exists() && metaData.isDirectory();
- }
- const QAbstractFileEngine::FileFlags info =
- fileEngine->fileFlags(QAbstractFileEngine::DirectoryType
- | QAbstractFileEngine::ExistsFlag
- | QAbstractFileEngine::Refresh);
- if (!(info & QAbstractFileEngine::DirectoryType))
- return false;
- return info & QAbstractFileEngine::ExistsFlag;
+ QFileSystemEngine::fillMetaData(dirEntry, metaData,
+ QFileSystemMetaData::ExistsAttribute | QFileSystemMetaData::DirectoryType); // always stat
+ return metaData.exists() && metaData.isDirectory();
}
inline void QDirPrivate::setPath(const QString &path)
dirEntry = QFileSystemEntry(QDir::fromNativeSeparators(path));
metaData.clear();
- initFileEngine();
clearFileLists();
absoluteDirEntry = QFileSystemEntry();
}
if (!absoluteDirEntry.isEmpty() || dirEntry.isEmpty())
return;
- QString absoluteName;
- if (!fileEngine) {
- if (!dirEntry.isRelative() && dirEntry.isClean()) {
- absoluteDirEntry = dirEntry;
- return;
- }
-
- absoluteName = QFileSystemEngine::absoluteName(dirEntry).filePath();
- } else {
- absoluteName = fileEngine->fileName(QAbstractFileEngine::AbsoluteName);
+ if (!dirEntry.isRelative() && dirEntry.isClean()) {
+ absoluteDirEntry = dirEntry;
+ return;
}
+ QString absoluteName = QFileSystemEngine::absoluteName(dirEntry).filePath();
absoluteDirEntry = QFileSystemEntry(QDir::cleanPath(absoluteName));
}
}
}
-inline void QDirPrivate::initFileEngine()
-{
- delete fileEngine;
- fileEngine = QAbstractFileEngine::create(dirEntry.filePath());
-}
-
/*!
\class QDir
\brief The QDir class provides access to directory structures and their contents.
QString QDir::canonicalPath() const
{
const QDirPrivate* d = d_ptr.constData();
- if (!d->fileEngine) {
- QFileSystemEntry answer = QFileSystemEngine::canonicalName(d->dirEntry, d->metaData);
- return answer.filePath();
- }
- return d->fileEngine->fileName(QAbstractFileEngine::CanonicalName);
+ QFileSystemEntry answer = QFileSystemEngine::canonicalName(d->dirEntry, d->metaData);
+ return answer.filePath();
}
/*!
void QDir::setNameFilters(const QStringList &nameFilters)
{
QDirPrivate* d = d_ptr.data();
- d->initFileEngine();
d->clearFileLists();
d->nameFilters = nameFilters;
void QDir::setFilter(Filters filters)
{
QDirPrivate* d = d_ptr.data();
- d->initFileEngine();
d->clearFileLists();
d->filters = filters;
void QDir::setSorting(SortFlags sort)
{
QDirPrivate* d = d_ptr.data();
- d->initFileEngine();
d->clearFileLists();
d->sort = sort;
const QDirPrivate* d = d_ptr.constData();
QString fn = filePath(dirName);
- if (!d->fileEngine)
- return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), false);
- return d->fileEngine->mkdir(fn, false);
+ return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), false);
}
/*!
const QDirPrivate* d = d_ptr.constData();
QString fn = filePath(dirName);
- if (!d->fileEngine)
- return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), false);
-
- return d->fileEngine->rmdir(fn, false);
+ return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), false);
}
/*!
const QDirPrivate* d = d_ptr.constData();
QString fn = filePath(dirPath);
- if (!d->fileEngine)
- return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), true);
- return d->fileEngine->mkdir(fn, true);
+ return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), true);
}
/*!
const QDirPrivate* d = d_ptr.constData();
QString fn = filePath(dirPath);
- if (!d->fileEngine)
- return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), true);
- return d->fileEngine->rmdir(fn, true);
+ return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), true);
}
/*!
{
const QDirPrivate* d = d_ptr.constData();
- if (!d->fileEngine) {
- if (!d->metaData.hasFlags(QFileSystemMetaData::UserReadPermission))
- QFileSystemEngine::fillMetaData(d->dirEntry, d->metaData, QFileSystemMetaData::UserReadPermission);
+ if (!d->metaData.hasFlags(QFileSystemMetaData::UserReadPermission))
+ QFileSystemEngine::fillMetaData(d->dirEntry, d->metaData, QFileSystemMetaData::UserReadPermission);
- return (d->metaData.permissions() & QFile::ReadUser) != 0;
- }
-
- const QAbstractFileEngine::FileFlags info =
- d->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType
- | QAbstractFileEngine::PermsMask);
- if (!(info & QAbstractFileEngine::DirectoryType))
- return false;
- return info & QAbstractFileEngine::ReadUserPerm;
+ return (d->metaData.permissions() & QFile::ReadUser) != 0;
}
/*!
*/
bool QDir::isRoot() const
{
- if (!d_ptr->fileEngine)
- return d_ptr->dirEntry.isRoot();
- return d_ptr->fileEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::RootFlag;
+ return d_ptr->dirEntry.isRoot();
}
/*!
*/
bool QDir::isRelative() const
{
- if (!d_ptr->fileEngine)
- return d_ptr->dirEntry.isRelative();
- return d_ptr->fileEngine->isRelativePath();
+ return d_ptr->dirEntry.isRelative();
}
-
/*!
Converts the directory path to an absolute path. If it is already
absolute nothing happens. Returns true if the conversion
{
const QDirPrivate *d = d_ptr.constData();
QScopedPointer<QDirPrivate> dir;
- if (d->fileEngine) {
- QString absolutePath = d->fileEngine->fileName(QAbstractFileEngine::AbsoluteName);
- if (QDir::isRelativePath(absolutePath))
- return false;
-
- dir.reset(new QDirPrivate(*d_ptr.constData()));
- dir->setPath(absolutePath);
- } else { // native FS
- d->resolveAbsoluteEntry();
- dir.reset(new QDirPrivate(*d_ptr.constData()));
- dir->setPath(d->absoluteDirEntry.filePath());
- }
+ d->resolveAbsoluteEntry();
+ dir.reset(new QDirPrivate(*d_ptr.constData()));
+ dir->setPath(d->absoluteDirEntry.filePath());
d_ptr = dir.take(); // actually detach
return true;
}
if (d == other)
return true;
- if (!d->fileEngine || !other->fileEngine) {
- if (d->fileEngine != other->fileEngine) // one is native, the other is a custom file-engine
- return false;
- }
if (d->filters == other->filters
&& d->sort == other->sort
{
QDirPrivate *d = d_ptr.data();
d->metaData.clear();
- d->initFileEngine();
d->clearFileLists();
}