Standardize on unique_ptr to hold QAbstractFileEngine
This will make it possible to return it from functions in an owner, as exemplified in the QFileInfoPrivate ctor, unlike QScopedPointer, which lacks move special member functions. Change-Id: I179ffa4f656e1b83c23e0f67d1542834460ff382 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
80d7ba4c49
commit
186bdec01a
@ -153,7 +153,7 @@ QDirPrivate::QDirPrivate(const QDirPrivate ©)
|
|||||||
|
|
||||||
bool QDirPrivate::exists() const
|
bool QDirPrivate::exists() const
|
||||||
{
|
{
|
||||||
if (fileEngine.isNull()) {
|
if (!fileEngine) {
|
||||||
QFileSystemEngine::fillMetaData(dirEntry, metaData,
|
QFileSystemEngine::fillMetaData(dirEntry, metaData,
|
||||||
QFileSystemMetaData::ExistsAttribute | QFileSystemMetaData::DirectoryType); // always stat
|
QFileSystemMetaData::ExistsAttribute | QFileSystemMetaData::DirectoryType); // always stat
|
||||||
return metaData.exists() && metaData.isDirectory();
|
return metaData.exists() && metaData.isDirectory();
|
||||||
@ -226,7 +226,7 @@ inline void QDirPrivate::resolveAbsoluteEntry() const
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QString absoluteName;
|
QString absoluteName;
|
||||||
if (fileEngine.isNull()) {
|
if (!fileEngine) {
|
||||||
if (!dirEntry.isRelative() && dirEntry.isClean()) {
|
if (!dirEntry.isRelative() && dirEntry.isClean()) {
|
||||||
absoluteDirEntry = dirEntry;
|
absoluteDirEntry = dirEntry;
|
||||||
return;
|
return;
|
||||||
@ -693,7 +693,7 @@ QString QDir::absolutePath() const
|
|||||||
QString QDir::canonicalPath() const
|
QString QDir::canonicalPath() const
|
||||||
{
|
{
|
||||||
const QDirPrivate* d = d_ptr.constData();
|
const QDirPrivate* d = d_ptr.constData();
|
||||||
if (d->fileEngine.isNull()) {
|
if (!d->fileEngine) {
|
||||||
QFileSystemEntry answer = QFileSystemEngine::canonicalName(d->dirEntry, d->metaData);
|
QFileSystemEntry answer = QFileSystemEngine::canonicalName(d->dirEntry, d->metaData);
|
||||||
return answer.filePath();
|
return answer.filePath();
|
||||||
}
|
}
|
||||||
@ -1502,7 +1502,7 @@ bool QDir::mkdir(const QString &dirName) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString fn = filePath(dirName);
|
QString fn = filePath(dirName);
|
||||||
if (d->fileEngine.isNull())
|
if (!d->fileEngine)
|
||||||
return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), false);
|
return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), false);
|
||||||
return d->fileEngine->mkdir(fn, false);
|
return d->fileEngine->mkdir(fn, false);
|
||||||
}
|
}
|
||||||
@ -1526,7 +1526,7 @@ bool QDir::rmdir(const QString &dirName) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString fn = filePath(dirName);
|
QString fn = filePath(dirName);
|
||||||
if (d->fileEngine.isNull())
|
if (!d->fileEngine)
|
||||||
return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), false);
|
return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), false);
|
||||||
|
|
||||||
return d->fileEngine->rmdir(fn, false);
|
return d->fileEngine->rmdir(fn, false);
|
||||||
@ -1554,7 +1554,7 @@ bool QDir::mkpath(const QString &dirPath) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString fn = filePath(dirPath);
|
QString fn = filePath(dirPath);
|
||||||
if (d->fileEngine.isNull())
|
if (!d->fileEngine)
|
||||||
return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), true);
|
return QFileSystemEngine::createDirectory(QFileSystemEntry(fn), true);
|
||||||
return d->fileEngine->mkdir(fn, true);
|
return d->fileEngine->mkdir(fn, true);
|
||||||
}
|
}
|
||||||
@ -1580,7 +1580,7 @@ bool QDir::rmpath(const QString &dirPath) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString fn = filePath(dirPath);
|
QString fn = filePath(dirPath);
|
||||||
if (d->fileEngine.isNull())
|
if (!d->fileEngine)
|
||||||
return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), true);
|
return QFileSystemEngine::removeDirectory(QFileSystemEntry(fn), true);
|
||||||
return d->fileEngine->rmdir(fn, true);
|
return d->fileEngine->rmdir(fn, true);
|
||||||
}
|
}
|
||||||
@ -1653,7 +1653,7 @@ bool QDir::isReadable() const
|
|||||||
{
|
{
|
||||||
const QDirPrivate* d = d_ptr.constData();
|
const QDirPrivate* d = d_ptr.constData();
|
||||||
|
|
||||||
if (d->fileEngine.isNull()) {
|
if (!d->fileEngine) {
|
||||||
if (!d->metaData.hasFlags(QFileSystemMetaData::UserReadPermission))
|
if (!d->metaData.hasFlags(QFileSystemMetaData::UserReadPermission))
|
||||||
QFileSystemEngine::fillMetaData(d->dirEntry, d->metaData, QFileSystemMetaData::UserReadPermission);
|
QFileSystemEngine::fillMetaData(d->dirEntry, d->metaData, QFileSystemMetaData::UserReadPermission);
|
||||||
|
|
||||||
@ -1698,7 +1698,7 @@ bool QDir::exists() const
|
|||||||
*/
|
*/
|
||||||
bool QDir::isRoot() const
|
bool QDir::isRoot() const
|
||||||
{
|
{
|
||||||
if (d_ptr->fileEngine.isNull())
|
if (!d_ptr->fileEngine)
|
||||||
return d_ptr->dirEntry.isRoot();
|
return d_ptr->dirEntry.isRoot();
|
||||||
return d_ptr->fileEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::RootFlag;
|
return d_ptr->fileEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::RootFlag;
|
||||||
}
|
}
|
||||||
@ -1730,7 +1730,7 @@ bool QDir::isRoot() const
|
|||||||
*/
|
*/
|
||||||
bool QDir::isRelative() const
|
bool QDir::isRelative() const
|
||||||
{
|
{
|
||||||
if (d_ptr->fileEngine.isNull())
|
if (!d_ptr->fileEngine)
|
||||||
return d_ptr->dirEntry.isRelative();
|
return d_ptr->dirEntry.isRelative();
|
||||||
return d_ptr->fileEngine->isRelativePath();
|
return d_ptr->fileEngine->isRelativePath();
|
||||||
}
|
}
|
||||||
@ -1747,7 +1747,7 @@ bool QDir::makeAbsolute()
|
|||||||
{
|
{
|
||||||
const QDirPrivate *d = d_ptr.constData();
|
const QDirPrivate *d = d_ptr.constData();
|
||||||
QScopedPointer<QDirPrivate> dir;
|
QScopedPointer<QDirPrivate> dir;
|
||||||
if (!d->fileEngine.isNull()) {
|
if (!!d->fileEngine) {
|
||||||
QString absolutePath = d->fileEngine->fileName(QAbstractFileEngine::AbsoluteName);
|
QString absolutePath = d->fileEngine->fileName(QAbstractFileEngine::AbsoluteName);
|
||||||
if (QDir::isRelativePath(absolutePath))
|
if (QDir::isRelativePath(absolutePath))
|
||||||
return false;
|
return false;
|
||||||
@ -1780,8 +1780,8 @@ bool QDir::operator==(const QDir &dir) const
|
|||||||
if (d == other)
|
if (d == other)
|
||||||
return true;
|
return true;
|
||||||
Qt::CaseSensitivity sensitive;
|
Qt::CaseSensitivity sensitive;
|
||||||
if (d->fileEngine.isNull() || other->fileEngine.isNull()) {
|
if (!d->fileEngine || !other->fileEngine) {
|
||||||
if (d->fileEngine.data() != other->fileEngine.data()) // one is native, the other is a custom file-engine
|
if (d->fileEngine.get() != other->fileEngine.get()) // one is native, the other is a custom file-engine
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
sensitive = QFileSystemEngine::isCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive;
|
sensitive = QFileSystemEngine::isCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive;
|
||||||
|
@ -54,6 +54,8 @@
|
|||||||
#include "qfilesystementry_p.h"
|
#include "qfilesystementry_p.h"
|
||||||
#include "qfilesystemmetadata_p.h"
|
#include "qfilesystemmetadata_p.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class QDirPrivate : public QSharedData
|
class QDirPrivate : public QSharedData
|
||||||
@ -98,7 +100,7 @@ public:
|
|||||||
QDir::SortFlags sort;
|
QDir::SortFlags sort;
|
||||||
QDir::Filters filters;
|
QDir::Filters filters;
|
||||||
|
|
||||||
QScopedPointer<QAbstractFileEngine> fileEngine;
|
std::unique_ptr<QAbstractFileEngine> fileEngine;
|
||||||
|
|
||||||
QFileSystemEntry dirEntry;
|
QFileSystemEntry dirEntry;
|
||||||
mutable QFileSystemEntry absoluteDirEntry;
|
mutable QFileSystemEntry absoluteDirEntry;
|
||||||
|
@ -107,6 +107,8 @@
|
|||||||
#include <QtCore/private/qfilesystemengine_p.h>
|
#include <QtCore/private/qfilesystemengine_p.h>
|
||||||
#include <QtCore/private/qfileinfo_p.h>
|
#include <QtCore/private/qfileinfo_p.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
template <class Iterator>
|
template <class Iterator>
|
||||||
@ -132,7 +134,7 @@ public:
|
|||||||
void checkAndPushDirectory(const QFileInfo &);
|
void checkAndPushDirectory(const QFileInfo &);
|
||||||
bool matchesFilters(const QString &fileName, const QFileInfo &fi) const;
|
bool matchesFilters(const QString &fileName, const QFileInfo &fi) const;
|
||||||
|
|
||||||
QScopedPointer<QAbstractFileEngine> engine;
|
std::unique_ptr<QAbstractFileEngine> engine;
|
||||||
|
|
||||||
QFileSystemEntry dirEntry;
|
QFileSystemEntry dirEntry;
|
||||||
const QStringList nameFilters;
|
const QStringList nameFilters;
|
||||||
@ -435,7 +437,7 @@ bool QDirIteratorPrivate::matchesFilters(const QString &fileName, const QFileInf
|
|||||||
QDirIterator::QDirIterator(const QDir &dir, IteratorFlags flags)
|
QDirIterator::QDirIterator(const QDir &dir, IteratorFlags flags)
|
||||||
{
|
{
|
||||||
const QDirPrivate *other = dir.d_ptr.constData();
|
const QDirPrivate *other = dir.d_ptr.constData();
|
||||||
d.reset(new QDirIteratorPrivate(other->dirEntry, other->nameFilters, other->filters, flags, !other->fileEngine.isNull()));
|
d.reset(new QDirIteratorPrivate(other->dirEntry, other->nameFilters, other->filters, flags, bool(other->fileEngine)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -707,11 +707,11 @@ bool QFileInfo::exists(const QString &file)
|
|||||||
return false;
|
return false;
|
||||||
QFileSystemEntry entry(file);
|
QFileSystemEntry entry(file);
|
||||||
QFileSystemMetaData data;
|
QFileSystemMetaData data;
|
||||||
QAbstractFileEngine *engine =
|
std::unique_ptr<QAbstractFileEngine> engine
|
||||||
QFileSystemEngine::resolveEntryAndCreateLegacyEngine(entry, data);
|
{QFileSystemEngine::resolveEntryAndCreateLegacyEngine(entry, data)};
|
||||||
// Expensive fallback to non-QFileSystemEngine implementation
|
// Expensive fallback to non-QFileSystemEngine implementation
|
||||||
if (engine)
|
if (engine)
|
||||||
return QFileInfo(new QFileInfoPrivate(entry, data, engine)).exists();
|
return QFileInfo(new QFileInfoPrivate(entry, data, std::move(engine))).exists();
|
||||||
|
|
||||||
QFileSystemEngine::fillMetaData(entry, data, QFileSystemMetaData::ExistsAttribute);
|
QFileSystemEngine::fillMetaData(entry, data, QFileSystemMetaData::ExistsAttribute);
|
||||||
return data.exists();
|
return data.exists();
|
||||||
|
@ -61,6 +61,8 @@
|
|||||||
#include <QtCore/private/qfilesystementry_p.h>
|
#include <QtCore/private/qfilesystementry_p.h>
|
||||||
#include <QtCore/private/qfilesystemmetadata_p.h>
|
#include <QtCore/private/qfilesystemmetadata_p.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class QFileInfoPrivate : public QSharedData
|
class QFileInfoPrivate : public QSharedData
|
||||||
@ -126,10 +128,10 @@ public:
|
|||||||
metaData = QFileSystemMetaData();
|
metaData = QFileSystemMetaData();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QFileInfoPrivate(const QFileSystemEntry &file, const QFileSystemMetaData &data, QAbstractFileEngine *engine)
|
inline QFileInfoPrivate(const QFileSystemEntry &file, const QFileSystemMetaData &data, std::unique_ptr<QAbstractFileEngine> engine)
|
||||||
: fileEntry(file),
|
: fileEntry(file),
|
||||||
metaData(data),
|
metaData(data),
|
||||||
fileEngine(engine),
|
fileEngine{std::move(engine)},
|
||||||
cachedFlags(0),
|
cachedFlags(0),
|
||||||
#ifndef QT_NO_FSFILEENGINE
|
#ifndef QT_NO_FSFILEENGINE
|
||||||
isDefaultConstructed(false),
|
isDefaultConstructed(false),
|
||||||
@ -163,7 +165,7 @@ public:
|
|||||||
QFileSystemEntry fileEntry;
|
QFileSystemEntry fileEntry;
|
||||||
mutable QFileSystemMetaData metaData;
|
mutable QFileSystemMetaData metaData;
|
||||||
|
|
||||||
QScopedPointer<QAbstractFileEngine> const fileEngine;
|
std::unique_ptr<QAbstractFileEngine> const fileEngine;
|
||||||
|
|
||||||
mutable QString fileNames[QAbstractFileEngine::NFileNames];
|
mutable QString fileNames[QAbstractFileEngine::NFileNames];
|
||||||
mutable QString fileOwners[2]; // QAbstractFileEngine::FileOwner: OwnerUser and OwnerGroup
|
mutable QString fileOwners[2]; // QAbstractFileEngine::FileOwner: OwnerUser and OwnerGroup
|
||||||
|
Loading…
Reference in New Issue
Block a user