Drop file-engine abstraction from public API

This abstraction imposed serious performance penalties and is being
dropped from the public API.

In particular, by allowing file names to be arbitrarily hijacked by
different file engines, and requiring engines to be instantiated in
order to decide, it imposed unnecessary overhead on all file operations.

Another flaw in the design with direct impact on performance is how
engines have no way to provide (or retain) additional information
obtained when querying the filesystem. In many places this has meant
repeated operations on the file system, where useful information is
immediately discarded to be queried again subsequently.

For Qt 4.8 a major refactoring of the code base took place to allow
bypassing the file-engine abstraction in select places, with
considerable performance gains observed. In Qt 5 it is expected we'll be
able to take this further, reaping even more benefits, but the
abstraction has to go.

[Dropping this now does not preclude that virtual file systems make an
appearance in Qt at a later point in Qt 5's lifecycle. Hopefully with a
new and improved abstraction.]

Forward declarations for QFileExtension(Result) were dropped, as the
classes were never used or defined.

Tests using "internalized" classes will only fully run on developer
builds. QFSFileEngine was removed altogether from exception safety test,
as it isn't its intent to test internal API.

Change-Id: Ie910e6c2628be202ea9e05366b091d6d529b246b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
João Abecasis 2012-02-17 20:09:17 +01:00 committed by Qt by Nokia
parent 9beeb3030b
commit 7bbe79fe5f
37 changed files with 357 additions and 419 deletions

5
dist/changes-5.0.0 vendored
View File

@ -207,6 +207,11 @@ information about a particular change.
- QDir::NoDotAndDotDot is QDir::NoDot|QDir::NoDotDot therefore there is no need
to use or check both.
- QFSFileEngine, QAbstractFileEngine, QAbstractFileEngineIterator and
QAbstractFileEngineHandler were removed from public API and are no longer
exported. They may temporarily live as private implementation details, but
they may be altogether dropped or otherwise changed at will in the future.
- QLocale
* toShort(), toUShort(), toInt(), toUInt(), toLongLong() and toULongLong() no
longer take a parameter for base, they will only perform localised base 10

View File

@ -92,7 +92,7 @@ bootstrap { #Qt code
qdir_p.h \
qdiriterator.h \
qfile.h \
qabstractfileengine.h \
qabstractfileengine_p.h \
qfileinfo.h \
qglobal.h \
qnumeric.h \

View File

@ -1,7 +1,6 @@
# Qt core io module
HEADERS += \
io/qabstractfileengine.h \
io/qabstractfileengine_p.h \
io/qbuffer.h \
io/qdatastream.h \
@ -30,7 +29,6 @@ HEADERS += \
io/qtldurl_p.h \
io/qsettings.h \
io/qsettings_p.h \
io/qfsfileengine.h \
io/qfsfileengine_p.h \
io/qfsfileengine_iterator_p.h \
io/qfilesystemwatcher.h \

View File

@ -39,8 +39,8 @@
**
****************************************************************************/
#include "qabstractfileengine.h"
#include "private/qabstractfileengine_p.h"
#include "private/qfsfileengine_p.h"
#ifdef QT_BUILD_CORE_LIB
#include "private/qresource_p.h"
#endif
@ -48,7 +48,6 @@
#include "qreadwritelock.h"
#include "qvariant.h"
// built-in handlers
#include "qfsfileengine.h"
#include "qdiriterator.h"
#include "qstringbuilder.h"
@ -61,6 +60,7 @@ QT_BEGIN_NAMESPACE
/*!
\class QAbstractFileEngineHandler
\reentrant
\internal
\brief The QAbstractFileEngineHandler class provides a way to register
custom file engines with your application.
@ -220,6 +220,7 @@ QAbstractFileEngine *QAbstractFileEngine::create(const QString &fileName)
/*!
\class QAbstractFileEngine
\reentrant
\internal
\brief The QAbstractFileEngine class provides an abstraction for accessing
the filesystem.
@ -804,6 +805,7 @@ bool QAbstractFileEngine::unmap(uchar *address)
\class QAbstractFileEngineIterator
\brief The QAbstractFileEngineIterator class provides an iterator
interface for custom file engines.
\internal
If all you want is to iterate over entries in a directory, see
QDirIterator instead. This class is only for custom file engine authors.

View File

@ -1,247 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QABSTRACTFILEENGINE_H
#define QABSTRACTFILEENGINE_H
#include <QtCore/qdir.h>
#ifdef open
#error qabstractfileengine.h must be included before any header file that defines open
#endif
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
class QFileExtension;
class QFileExtensionResult;
class QVariant;
class QAbstractFileEngineIterator;
class QAbstractFileEnginePrivate;
class Q_CORE_EXPORT QAbstractFileEngine
{
public:
enum FileFlag {
//perms (overlaps the QFile::Permission)
ReadOwnerPerm = 0x4000, WriteOwnerPerm = 0x2000, ExeOwnerPerm = 0x1000,
ReadUserPerm = 0x0400, WriteUserPerm = 0x0200, ExeUserPerm = 0x0100,
ReadGroupPerm = 0x0040, WriteGroupPerm = 0x0020, ExeGroupPerm = 0x0010,
ReadOtherPerm = 0x0004, WriteOtherPerm = 0x0002, ExeOtherPerm = 0x0001,
//types
LinkType = 0x10000,
FileType = 0x20000,
DirectoryType = 0x40000,
BundleType = 0x80000,
//flags
HiddenFlag = 0x0100000,
LocalDiskFlag = 0x0200000,
ExistsFlag = 0x0400000,
RootFlag = 0x0800000,
Refresh = 0x1000000,
//masks
PermsMask = 0x0000FFFF,
TypesMask = 0x000F0000,
FlagsMask = 0x0FF00000,
FileInfoAll = FlagsMask | PermsMask | TypesMask
};
Q_DECLARE_FLAGS(FileFlags, FileFlag)
enum FileName {
DefaultName,
BaseName,
PathName,
AbsoluteName,
AbsolutePathName,
LinkName,
CanonicalName,
CanonicalPathName,
BundleName,
NFileNames = 9
};
enum FileOwner {
OwnerUser,
OwnerGroup
};
enum FileTime {
CreationTime,
ModificationTime,
AccessTime
};
virtual ~QAbstractFileEngine();
virtual bool open(QIODevice::OpenMode openMode);
virtual bool close();
virtual bool flush();
virtual qint64 size() const;
virtual qint64 pos() const;
virtual bool seek(qint64 pos);
virtual bool isSequential() const;
virtual bool remove();
virtual bool copy(const QString &newName);
virtual bool rename(const QString &newName);
virtual bool link(const QString &newName);
virtual bool mkdir(const QString &dirName, bool createParentDirectories) const;
virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
virtual bool setSize(qint64 size);
virtual bool caseSensitive() const;
virtual bool isRelativePath() const;
virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const;
virtual bool setPermissions(uint perms);
virtual QString fileName(FileName file=DefaultName) const;
virtual uint ownerId(FileOwner) const;
virtual QString owner(FileOwner) const;
virtual QDateTime fileTime(FileTime time) const;
virtual void setFileName(const QString &file);
virtual int handle() const;
bool atEnd() const;
uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags);
bool unmap(uchar *ptr);
typedef QAbstractFileEngineIterator Iterator;
virtual Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames);
virtual Iterator *endEntryList();
virtual qint64 read(char *data, qint64 maxlen);
virtual qint64 readLine(char *data, qint64 maxlen);
virtual qint64 write(const char *data, qint64 len);
QFile::FileError error() const;
QString errorString() const;
enum Extension {
AtEndExtension,
FastReadLineExtension,
MapExtension,
UnMapExtension
};
class ExtensionOption
{};
class ExtensionReturn
{};
class MapExtensionOption : public ExtensionOption {
public:
qint64 offset;
qint64 size;
QFile::MemoryMapFlags flags;
};
class MapExtensionReturn : public ExtensionReturn {
public:
uchar *address;
};
class UnMapExtensionOption : public ExtensionOption {
public:
uchar *address;
};
virtual bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
virtual bool supportsExtension(Extension extension) const;
// Factory
static QAbstractFileEngine *create(const QString &fileName);
protected:
void setError(QFile::FileError error, const QString &str);
QAbstractFileEngine();
QAbstractFileEngine(QAbstractFileEnginePrivate &);
QScopedPointer<QAbstractFileEnginePrivate> d_ptr;
private:
Q_DECLARE_PRIVATE(QAbstractFileEngine)
Q_DISABLE_COPY(QAbstractFileEngine)
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractFileEngine::FileFlags)
class Q_CORE_EXPORT QAbstractFileEngineHandler
{
public:
QAbstractFileEngineHandler();
virtual ~QAbstractFileEngineHandler();
virtual QAbstractFileEngine *create(const QString &fileName) const = 0;
};
class QAbstractFileEngineIteratorPrivate;
class Q_CORE_EXPORT QAbstractFileEngineIterator
{
public:
QAbstractFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters);
virtual ~QAbstractFileEngineIterator();
virtual QString next() = 0;
virtual bool hasNext() const = 0;
QString path() const;
QStringList nameFilters() const;
QDir::Filters filters() const;
virtual QString currentFileName() const = 0;
virtual QFileInfo currentFileInfo() const;
QString currentFilePath() const;
protected:
enum EntryInfoType {
};
virtual QVariant entryInfo(EntryInfoType type) const;
private:
Q_DISABLE_COPY(QAbstractFileEngineIterator)
friend class QDirIterator;
friend class QDirIteratorPrivate;
void setPath(const QString &path);
QScopedPointer<QAbstractFileEngineIteratorPrivate> d;
};
QT_END_NAMESPACE
QT_END_HEADER
#endif // QABSTRACTFILEENGINE_H

View File

@ -53,11 +53,200 @@
// We mean it.
//
#include "QtCore/qabstractfileengine.h"
#include "QtCore/qfile.h"
#include "QtCore/qdir.h"
#ifdef open
#error qabstractfileengine_p.h must be included before any header file that defines open
#endif
QT_BEGIN_NAMESPACE
class QVariant;
class QAbstractFileEngineIterator;
class QAbstractFileEnginePrivate;
class Q_AUTOTEST_EXPORT QAbstractFileEngine
{
public:
enum FileFlag {
//perms (overlaps the QFile::Permission)
ReadOwnerPerm = 0x4000, WriteOwnerPerm = 0x2000, ExeOwnerPerm = 0x1000,
ReadUserPerm = 0x0400, WriteUserPerm = 0x0200, ExeUserPerm = 0x0100,
ReadGroupPerm = 0x0040, WriteGroupPerm = 0x0020, ExeGroupPerm = 0x0010,
ReadOtherPerm = 0x0004, WriteOtherPerm = 0x0002, ExeOtherPerm = 0x0001,
//types
LinkType = 0x10000,
FileType = 0x20000,
DirectoryType = 0x40000,
BundleType = 0x80000,
//flags
HiddenFlag = 0x0100000,
LocalDiskFlag = 0x0200000,
ExistsFlag = 0x0400000,
RootFlag = 0x0800000,
Refresh = 0x1000000,
//masks
PermsMask = 0x0000FFFF,
TypesMask = 0x000F0000,
FlagsMask = 0x0FF00000,
FileInfoAll = FlagsMask | PermsMask | TypesMask
};
Q_DECLARE_FLAGS(FileFlags, FileFlag)
enum FileName {
DefaultName,
BaseName,
PathName,
AbsoluteName,
AbsolutePathName,
LinkName,
CanonicalName,
CanonicalPathName,
BundleName,
NFileNames = 9
};
enum FileOwner {
OwnerUser,
OwnerGroup
};
enum FileTime {
CreationTime,
ModificationTime,
AccessTime
};
virtual ~QAbstractFileEngine();
virtual bool open(QIODevice::OpenMode openMode);
virtual bool close();
virtual bool flush();
virtual qint64 size() const;
virtual qint64 pos() const;
virtual bool seek(qint64 pos);
virtual bool isSequential() const;
virtual bool remove();
virtual bool copy(const QString &newName);
virtual bool rename(const QString &newName);
virtual bool link(const QString &newName);
virtual bool mkdir(const QString &dirName, bool createParentDirectories) const;
virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
virtual bool setSize(qint64 size);
virtual bool caseSensitive() const;
virtual bool isRelativePath() const;
virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const;
virtual bool setPermissions(uint perms);
virtual QString fileName(FileName file=DefaultName) const;
virtual uint ownerId(FileOwner) const;
virtual QString owner(FileOwner) const;
virtual QDateTime fileTime(FileTime time) const;
virtual void setFileName(const QString &file);
virtual int handle() const;
bool atEnd() const;
uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags);
bool unmap(uchar *ptr);
typedef QAbstractFileEngineIterator Iterator;
virtual Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames);
virtual Iterator *endEntryList();
virtual qint64 read(char *data, qint64 maxlen);
virtual qint64 readLine(char *data, qint64 maxlen);
virtual qint64 write(const char *data, qint64 len);
QFile::FileError error() const;
QString errorString() const;
enum Extension {
AtEndExtension,
FastReadLineExtension,
MapExtension,
UnMapExtension
};
class ExtensionOption
{};
class ExtensionReturn
{};
class MapExtensionOption : public ExtensionOption {
public:
qint64 offset;
qint64 size;
QFile::MemoryMapFlags flags;
};
class MapExtensionReturn : public ExtensionReturn {
public:
uchar *address;
};
class UnMapExtensionOption : public ExtensionOption {
public:
uchar *address;
};
virtual bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
virtual bool supportsExtension(Extension extension) const;
// Factory
static QAbstractFileEngine *create(const QString &fileName);
protected:
void setError(QFile::FileError error, const QString &str);
QAbstractFileEngine();
QAbstractFileEngine(QAbstractFileEnginePrivate &);
QScopedPointer<QAbstractFileEnginePrivate> d_ptr;
private:
Q_DECLARE_PRIVATE(QAbstractFileEngine)
Q_DISABLE_COPY(QAbstractFileEngine)
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractFileEngine::FileFlags)
class Q_AUTOTEST_EXPORT QAbstractFileEngineHandler
{
public:
QAbstractFileEngineHandler();
virtual ~QAbstractFileEngineHandler();
virtual QAbstractFileEngine *create(const QString &fileName) const = 0;
};
class QAbstractFileEngineIteratorPrivate;
class Q_AUTOTEST_EXPORT QAbstractFileEngineIterator
{
public:
QAbstractFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters);
virtual ~QAbstractFileEngineIterator();
virtual QString next() = 0;
virtual bool hasNext() const = 0;
QString path() const;
QStringList nameFilters() const;
QDir::Filters filters() const;
virtual QString currentFileName() const = 0;
virtual QFileInfo currentFileInfo() const;
QString currentFilePath() const;
protected:
enum EntryInfoType {
};
virtual QVariant entryInfo(EntryInfoType type) const;
private:
Q_DISABLE_COPY(QAbstractFileEngineIterator)
friend class QDirIterator;
friend class QDirIteratorPrivate;
void setPath(const QString &path);
QScopedPointer<QAbstractFileEngineIteratorPrivate> d;
};
class QAbstractFileEnginePrivate
{
public:

View File

@ -42,12 +42,12 @@
#include "qplatformdefs.h"
#include "qdir.h"
#include "qdir_p.h"
#include "qabstractfileengine.h"
#include "qabstractfileengine_p.h"
#include "qfsfileengine_p.h"
#ifndef QT_NO_DEBUG_STREAM
#include "qdebug.h"
#endif
#include "qdiriterator.h"
#include "qfsfileengine.h"
#include "qdatetime.h"
#include "qstring.h"
#include "qregexp.h"

View File

@ -91,8 +91,7 @@
#include "qdiriterator.h"
#include "qdir_p.h"
#include "qabstractfileengine.h"
#include "qabstractfileengine_p.h"
#include <QtCore/qset.h>
#include <QtCore/qstack.h>
@ -102,7 +101,6 @@
#include <QtCore/private/qfilesystementry_p.h>
#include <QtCore/private/qfilesystemmetadata_p.h>
#include <QtCore/private/qfilesystemengine_p.h>
#include <QtCore/qfsfileengine.h>
#include <QtCore/private/qfileinfo_p.h>
QT_BEGIN_NAMESPACE

View File

@ -42,7 +42,7 @@
#include "qplatformdefs.h"
#include "qdebug.h"
#include "qfile.h"
#include "qfsfileengine.h"
#include "qfsfileengine_p.h"
#include "qtemporaryfile.h"
#include "qlist.h"
#include "qfileinfo.h"
@ -1197,7 +1197,7 @@ QFile::handle() const
\note On Windows CE 5.0 the file will be closed before mapping occurs.
\sa unmap(), QAbstractFileEngine::supportsExtension()
\sa unmap()
*/
uchar *QFile::map(qint64 offset, qint64 size, MemoryMapFlags flags)
{
@ -1219,7 +1219,7 @@ uchar *QFile::map(qint64 offset, qint64 size, MemoryMapFlags flags)
Returns true if the unmap succeeds; false otherwise.
\sa map(), QAbstractFileEngine::supportsExtension()
\sa map()
*/
bool QFile::unmap(uchar *address)
{

View File

@ -53,7 +53,7 @@
// We mean it.
//
#include "QtCore/qabstractfileengine.h"
#include "private/qabstractfileengine_p.h"
#include "private/qiodevice_p.h"
#include "private/qringbuffer_p.h"

View File

@ -54,12 +54,12 @@
//
#include "qfileinfo.h"
#include "qabstractfileengine.h"
#include "qdatetime.h"
#include "qatomic.h"
#include "qshareddata.h"
#include "qfilesystemengine_p.h"
#include <QtCore/private/qabstractfileengine_p.h>
#include <QtCore/private/qfilesystementry_p.h>
#include <QtCore/private/qfilesystemmetadata_p.h>

View File

@ -42,7 +42,6 @@
#include "qplatformdefs.h"
#include "qfilesystemengine_p.h"
#include "qplatformdefs.h"
#include "qfsfileengine.h"
#include "qfile.h"
#include <QtCore/qvarlengtharray.h>
@ -645,12 +644,12 @@ QFileSystemEntry QFileSystemEngine::currentPath()
result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath());
# if defined(QT_DEBUG)
if (result.isEmpty())
qWarning("QFSFileEngine::currentPath: getcwd() failed");
qWarning("QFileSystemEngine::currentPath: getcwd() failed");
# endif
#endif
} else {
# if defined(QT_DEBUG)
qWarning("QFSFileEngine::currentPath: stat(\".\") failed");
qWarning("QFileSystemEngine::currentPath: stat(\".\") failed");
# endif
}
return result;

View File

@ -43,7 +43,7 @@
#define _POSIX_
#include "qplatformdefs.h"
#include "qabstractfileengine.h"
#include "private/qabstractfileengine_p.h"
#include "private/qfsfileengine_p.h"
#include <private/qsystemlibrary_p.h>
#include <qdebug.h>

View File

@ -56,7 +56,7 @@
#include "qplatformdefs.h"
#include <QtCore/qglobal.h>
#include <QtCore/qdatetime.h>
#include <QtCore/qabstractfileengine.h>
#include <QtCore/private/qabstractfileengine_p.h>
// Platform-specific includes
#ifdef Q_OS_WIN

View File

@ -84,6 +84,7 @@ QT_BEGIN_NAMESPACE
/*! \class QFSFileEngine
\brief The QFSFileEngine class implements Qt's default file engine.
\since 4.1
\internal
This class is part of the file engine framework in Qt. If you only want to
access files or directories, use QFile, QFileInfo or QDir instead.

View File

@ -1,122 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QFSFILEENGINE_H
#define QFSFILEENGINE_H
#include <QtCore/qabstractfileengine.h>
#ifndef QT_NO_FSFILEENGINE
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
class QFSFileEnginePrivate;
class Q_CORE_EXPORT QFSFileEngine : public QAbstractFileEngine
{
Q_DECLARE_PRIVATE(QFSFileEngine)
public:
QFSFileEngine();
explicit QFSFileEngine(const QString &file);
~QFSFileEngine();
bool open(QIODevice::OpenMode openMode);
bool open(QIODevice::OpenMode flags, FILE *fh);
bool close();
bool flush();
qint64 size() const;
qint64 pos() const;
bool seek(qint64);
bool isSequential() const;
bool remove();
bool copy(const QString &newName);
bool rename(const QString &newName);
bool link(const QString &newName);
bool mkdir(const QString &dirName, bool createParentDirectories) const;
bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
bool setSize(qint64 size);
bool caseSensitive() const;
bool isRelativePath() const;
QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
FileFlags fileFlags(FileFlags type) const;
bool setPermissions(uint perms);
QString fileName(FileName file) const;
uint ownerId(FileOwner) const;
QString owner(FileOwner) const;
QDateTime fileTime(FileTime time) const;
void setFileName(const QString &file);
int handle() const;
Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames);
Iterator *endEntryList();
qint64 read(char *data, qint64 maxlen);
qint64 readLine(char *data, qint64 maxlen);
qint64 write(const char *data, qint64 len);
bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
bool supportsExtension(Extension extension) const;
//FS only!!
bool open(QIODevice::OpenMode flags, int fd);
bool open(QIODevice::OpenMode flags, int fd, QFile::FileHandleFlags handleFlags);
bool open(QIODevice::OpenMode flags, FILE *fh, QFile::FileHandleFlags handleFlags);
static bool setCurrentPath(const QString &path);
static QString currentPath(const QString &path = QString());
static QString homePath();
static QString rootPath();
static QString tempPath();
static QFileInfoList drives();
protected:
QFSFileEngine(QFSFileEnginePrivate &dd);
};
QT_END_NAMESPACE
QT_END_HEADER
#endif // QT_NO_FSFILEENGINE
#endif // QFSFILEENGINE_H

View File

@ -53,7 +53,7 @@
// We mean it.
//
#include "qabstractfileengine.h"
#include "private/qabstractfileengine_p.h"
#include "qfilesystemiterator_p.h"
#include "qdir.h"

View File

@ -54,8 +54,7 @@
//
#include "qplatformdefs.h"
#include "QtCore/qfsfileengine.h"
#include "private/qabstractfileengine_p.h"
#include "QtCore/private/qabstractfileengine_p.h"
#include <QtCore/private/qfilesystementry_p.h>
#include <QtCore/private/qfilesystemmetadata_p.h>
#include <qhash.h>
@ -68,6 +67,68 @@ QT_BEGIN_NAMESPACE
#define Q_USE_DEPRECATED_MAP_API 1
#endif
class QFSFileEnginePrivate;
class Q_AUTOTEST_EXPORT QFSFileEngine : public QAbstractFileEngine
{
Q_DECLARE_PRIVATE(QFSFileEngine)
public:
QFSFileEngine();
explicit QFSFileEngine(const QString &file);
~QFSFileEngine();
bool open(QIODevice::OpenMode openMode);
bool open(QIODevice::OpenMode flags, FILE *fh);
bool close();
bool flush();
qint64 size() const;
qint64 pos() const;
bool seek(qint64);
bool isSequential() const;
bool remove();
bool copy(const QString &newName);
bool rename(const QString &newName);
bool link(const QString &newName);
bool mkdir(const QString &dirName, bool createParentDirectories) const;
bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
bool setSize(qint64 size);
bool caseSensitive() const;
bool isRelativePath() const;
QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
FileFlags fileFlags(FileFlags type) const;
bool setPermissions(uint perms);
QString fileName(FileName file) const;
uint ownerId(FileOwner) const;
QString owner(FileOwner) const;
QDateTime fileTime(FileTime time) const;
void setFileName(const QString &file);
int handle() const;
Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames);
Iterator *endEntryList();
qint64 read(char *data, qint64 maxlen);
qint64 readLine(char *data, qint64 maxlen);
qint64 write(const char *data, qint64 len);
bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
bool supportsExtension(Extension extension) const;
//FS only!!
bool open(QIODevice::OpenMode flags, int fd);
bool open(QIODevice::OpenMode flags, int fd, QFile::FileHandleFlags handleFlags);
bool open(QIODevice::OpenMode flags, FILE *fh, QFile::FileHandleFlags handleFlags);
static bool setCurrentPath(const QString &path);
static QString currentPath(const QString &path = QString());
static QString homePath();
static QString rootPath();
static QString tempPath();
static QFileInfoList drives();
protected:
QFSFileEngine(QFSFileEnginePrivate &dd);
};
class Q_AUTOTEST_EXPORT QFSFileEnginePrivate : public QAbstractFileEnginePrivate
{
Q_DECLARE_PUBLIC(QFSFileEngine)

View File

@ -40,7 +40,7 @@
****************************************************************************/
#include "qplatformdefs.h"
#include "qabstractfileengine.h"
#include "private/qabstractfileengine_p.h"
#include "private/qfsfileengine_p.h"
#include "private/qcore_unix_p.h"
#include "qfilesystementry_p.h"

View File

@ -41,7 +41,7 @@
#define _POSIX_
#include "qplatformdefs.h"
#include "qabstractfileengine.h"
#include "private/qabstractfileengine_p.h"
#include "private/qfsfileengine_p.h"
#include "qfilesystemengine_p.h"
#include <qdebug.h>

View File

@ -53,7 +53,7 @@
// We mean it.
//
#include "qabstractfileengine.h"
#include "qabstractfileengine_p.h"
#include "qdir.h"
QT_BEGIN_NAMESPACE

View File

@ -53,7 +53,7 @@
// We mean it.
//
#include "QtCore/qabstractfileengine.h"
#include "qabstractfileengine_p.h"
QT_BEGIN_NAMESPACE

View File

@ -57,7 +57,7 @@
#include "qnetworkreply_p.h"
#include "qnetworkaccessmanager.h"
#include <QFile>
#include <QAbstractFileEngine>
#include <private/qabstractfileengine_p.h>
QT_BEGIN_NAMESPACE

View File

@ -53,9 +53,6 @@ QT_CLASS_LIB(Qt, QtCore, qnamespace.h)
QT_CLASS_LIB(QInternal, QtCore, qnamespace.h)
QT_CLASS_LIB(QCOORD, QtCore, qnamespace.h)
QT_CLASS_LIB(QtConfig, QtCore, qconfig.h)
QT_CLASS_LIB(QAbstractFileEngine, QtCore, qabstractfileengine.h)
QT_CLASS_LIB(QAbstractFileEngineHandler, QtCore, qabstractfileengine.h)
QT_CLASS_LIB(QAbstractFileEngineIterator, QtCore, qabstractfileengine.h)
QT_CLASS_LIB(QBuffer, QtCore, qbuffer.h)
QT_CLASS_LIB(QDataStream, QtCore, qdatastream.h)
QT_CLASS_LIB(QtDebug, QtCore, qdebug.h)
@ -68,7 +65,6 @@ QT_CLASS_LIB(QFileInfo, QtCore, qfileinfo.h)
QT_CLASS_LIB(QFileInfoList, QtCore, qfileinfo.h)
QT_CLASS_LIB(QFileInfoListIterator, QtCore, qfileinfo.h)
QT_CLASS_LIB(QFileSystemWatcher, QtCore, qfilesystemwatcher.h)
QT_CLASS_LIB(QFSFileEngine, QtCore, qfsfileengine.h)
QT_CLASS_LIB(QIODevice, QtCore, qiodevice.h)
QT_CLASS_LIB(Q_PID, QtCore, qprocess.h)
QT_CLASS_LIB(QProcessEnvironment, QtCore, qprocess.h)

View File

@ -41,7 +41,6 @@
#include "qfileinfogatherer_p.h"
#include <qdebug.h>
#include <qfsfileengine.h>
#include <qdiriterator.h>
#ifndef Q_OS_WIN
# include <unistd.h>

View File

@ -30,6 +30,7 @@ SUBDIRS=\
}
!contains(QT_CONFIG, private_tests): SUBDIRS -= \
qabstractfileengine \
qfileinfo
win32:!contains(QT_CONFIG, private_tests): SUBDIRS -= \

View File

@ -1,5 +1,5 @@
CONFIG += testcase
TARGET = tst_qabstractfileengine
QT = core testlib
QT = core-private core testlib
SOURCES = tst_qabstractfileengine.cpp
RESOURCES += qabstractfileengine.qrc

View File

@ -39,8 +39,8 @@
**
****************************************************************************/
#include <QtCore/QAbstractFileEngine>
#include <QtCore/QFSFileEngine>
#include <QtCore/private/qabstractfileengine_p.h>
#include <QtCore/private/qfsfileengine_p.h>
#include <QtCore/QMutex>
#include <QtCore/QMutexLocker>

View File

@ -1,6 +1,6 @@
CONFIG += testcase parallel_test
TARGET = tst_qdir
QT = core testlib
QT = core core-private testlib
SOURCES = tst_qdir.cpp
RESOURCES += qdir.qrc

View File

@ -49,6 +49,7 @@
#include <qstringlist.h>
#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE))
#include <QtCore/private/qfsfileengine_p.h>
#include "../../../network-settings.h"
#endif
@ -471,6 +472,7 @@ void tst_QDir::exists_data()
#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE))
QTest::newRow("This drive should exist") << "C:/" << true;
// find a non-existing drive and check if it does not exist
#ifdef QT_BUILD_INTERNAL
QFileInfoList drives = QFSFileEngine::drives();
QStringList driveLetters;
for (int i = 0; i < drives.count(); ++i) {
@ -487,6 +489,7 @@ void tst_QDir::exists_data()
QTest::newRow("This drive should not exist") << driv << false;
}
#endif
#endif
}
void tst_QDir::exists()

View File

@ -1,6 +1,6 @@
CONFIG += testcase parallel_test
TARGET = tst_qdiriterator
QT = core testlib
QT = core-private core testlib
SOURCES = tst_qdiriterator.cpp
RESOURCES += qdiriterator.qrc

View File

@ -48,6 +48,8 @@
#include <qfileinfo.h>
#include <qstringlist.h>
#include <QtCore/private/qfsfileengine_p.h>
#if defined(Q_OS_VXWORKS)
#define Q_NO_SYMLINKS
#endif
@ -454,6 +456,7 @@ void tst_QDirIterator::stopLinkLoop()
// The goal of this test is only to ensure that the test above don't malfunction
}
#ifdef QT_BUILD_INTERNAL
class EngineWithNoIterator : public QFSFileEngine
{
public:
@ -473,13 +476,18 @@ public:
return new EngineWithNoIterator(fileName);
}
};
#endif
void tst_QDirIterator::engineWithNoIterator()
{
#ifdef QT_BUILD_INTERNAL
EngineWithNoIteratorHandler handler;
QDir("entrylist").entryList();
QVERIFY(true); // test that the above line doesn't crash
#else
QSKIP("This test requires -developer-build.");
#endif
}
void tst_QDirIterator::absoluteFilePathsFromRelativeIteratorPath()

View File

@ -1,5 +1,5 @@
CONFIG += testcase
QT = core network testlib
QT = core-private core network testlib
TARGET = ../tst_qfile
SOURCES = ../tst_qfile.cpp
RESOURCES += ../qfile.qrc ../rename-fallback.qrc ../copy-fallback.qrc

View File

@ -42,13 +42,15 @@
#include <QtTest/QtTest>
#include <qplatformdefs.h>
#include <QAbstractFileEngine>
#include <QFSFileEngine>
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <private/qabstractfileengine_p.h>
#include <private/qfsfileengine_p.h>
#if !defined(Q_OS_WINCE)
#include <QHostInfo>
#endif
@ -70,7 +72,6 @@
# include <sys/statfs.h>
#elif defined(Q_OS_WINCE)
# include <qplatformdefs.h>
# include <private/qfsfileengine_p.h>
#endif
#include <stdio.h>
@ -1943,6 +1944,7 @@ void tst_QFile::longFileName()
QVERIFY(QFile::remove(newName));
}
#ifdef QT_BUILD_INTERNAL
class MyEngine : public QAbstractFileEngine
{
public:
@ -1998,6 +2000,7 @@ public:
return new MyEngine(2);
}
};
#endif
void tst_QFile::fileEngineHandler()
{
@ -2006,6 +2009,7 @@ void tst_QFile::fileEngineHandler()
QFile file("ole.bull");
QCOMPARE(file.size(), qint64(0));
#ifdef QT_BUILD_INTERNAL
// Instantiating our handler will enable the new engine.
MyHandler handler;
file.setFileName("ole.bull");
@ -2015,9 +2019,10 @@ void tst_QFile::fileEngineHandler()
MyHandler2 handler2;
file.setFileName("ole.bull");
QCOMPARE(file.size(), qint64(125));
#endif
}
#ifdef QT_BUILD_INTERNAL
class MyRecursiveHandler : public QAbstractFileEngineHandler
{
public:
@ -2032,13 +2037,18 @@ public:
return 0;
}
};
#endif
void tst_QFile::useQFileInAFileHandler()
{
#ifdef QT_BUILD_INTERNAL
// This test should not dead-lock
MyRecursiveHandler handler;
QFile file(":!tst_qfile.cpp");
QVERIFY(file.exists());
#else
QSKIP("This test requires -developer-build.");
#endif
}
void tst_QFile::getCharFF()

View File

@ -166,7 +166,6 @@ void tst_ExceptionSafety_Objects::objects_data()
NEWROW(QObject);
NEWROW(QBuffer);
NEWROW(QFile);
NEWROW(QFSFileEngine);
NEWROW(QProcess);
NEWROW(QSettings);
NEWROW(QThread);

View File

@ -41,10 +41,11 @@
#include <QDebug>
#include <QTemporaryFile>
#include <QFSFileEngine>
#include <QString>
#include <QDirIterator>
#include <private/qfsfileengine_p.h>
#include <qtest.h>
#include <stdio.h>
@ -79,7 +80,9 @@ Q_OBJECT
public:
enum BenchmarkType {
QFileBenchmark = 1,
#ifdef QT_BUILD_INTERNAL
QFSFileEngineBenchmark,
#endif
Win32Benchmark,
PosixBenchmark,
QFileFromPosixBenchmark
@ -173,7 +176,14 @@ void tst_qfile::cleanupTestCase()
}
void tst_qfile::readBigFile_QFile() { readBigFile(); }
void tst_qfile::readBigFile_QFSFileEngine() { readBigFile(); }
void tst_qfile::readBigFile_QFSFileEngine()
{
#ifdef QT_BUILD_INTERNAL
readBigFile();
#else
QSKIP("This test requires -developer-build.");
#endif
}
void tst_qfile::readBigFile_posix()
{
readBigFile();
@ -191,10 +201,15 @@ void tst_qfile::readBigFile_QFile_data()
void tst_qfile::readBigFile_QFSFileEngine_data()
{
#ifdef QT_BUILD_INTERNAL
readBigFile_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::NotOpen);
readBigFile_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered);
readBigFile_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::NotOpen);
readBigFile_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::Unbuffered);
#else
QTest::addColumn<int>("dummy");
QTest::newRow("Test will be skipped") << -1;
#endif
}
void tst_qfile::readBigFile_posix_data()
@ -255,6 +270,7 @@ void tst_qfile::readBigFile()
file.close();
}
break;
#ifdef QT_BUILD_INTERNAL
case(QFSFileEngineBenchmark): {
QFSFileEngine fse(filename);
fse.open(QIODevice::ReadOnly|textMode|bufferedMode);
@ -266,6 +282,7 @@ void tst_qfile::readBigFile()
fse.close();
}
break;
#endif
case(PosixBenchmark): {
QByteArray data = filename.toLocal8Bit();
const char* cfilename = data.constData();
@ -317,7 +334,9 @@ void tst_qfile::seek_data()
{
QTest::addColumn<tst_qfile::BenchmarkType>("testType");
QTest::newRow("QFile") << QFileBenchmark;
#ifdef QT_BUILD_INTERNAL
QTest::newRow("QFSFileEngine") << QFSFileEngineBenchmark;
#endif
QTest::newRow("Posix FILE*") << PosixBenchmark;
#ifdef Q_OS_WIN
QTest::newRow("Win32 API") << Win32Benchmark;
@ -343,6 +362,7 @@ void tst_qfile::seek()
file.close();
}
break;
#ifdef QT_BUILD_INTERNAL
case(QFSFileEngineBenchmark): {
QFSFileEngine fse(filename);
fse.open(QIODevice::ReadOnly);
@ -353,6 +373,7 @@ void tst_qfile::seek()
fse.close();
}
break;
#endif
case(PosixBenchmark): {
QByteArray data = filename.toLocal8Bit();
const char* cfilename = data.constData();
@ -396,7 +417,9 @@ void tst_qfile::open_data()
{
QTest::addColumn<tst_qfile::BenchmarkType>("testType");
QTest::newRow("QFile") << QFileBenchmark;
#ifdef QT_BUILD_INTERNAL
QTest::newRow("QFSFileEngine") << QFSFileEngineBenchmark;
#endif
QTest::newRow("Posix FILE*") << PosixBenchmark;
QTest::newRow("QFile from FILE*") << QFileFromPosixBenchmark;
#ifdef Q_OS_WIN
@ -419,6 +442,7 @@ void tst_qfile::open()
}
}
break;
#ifdef QT_BUILD_INTERNAL
case(QFSFileEngineBenchmark): {
QBENCHMARK {
QFSFileEngine fse(filename);
@ -427,7 +451,7 @@ void tst_qfile::open()
}
}
break;
#endif
case(PosixBenchmark): {
// ensure we don't account toLocal8Bit()
QByteArray data = filename.toLocal8Bit();
@ -477,7 +501,14 @@ void tst_qfile::open()
void tst_qfile::readSmallFiles_QFile() { readSmallFiles(); }
void tst_qfile::readSmallFiles_QFSFileEngine() { readSmallFiles(); }
void tst_qfile::readSmallFiles_QFSFileEngine()
{
#ifdef QT_BUILD_INTERNAL
readSmallFiles();
#else
QSKIP("This test requires -developer-build.");
#endif
}
void tst_qfile::readSmallFiles_posix()
{
readSmallFiles();
@ -498,10 +529,15 @@ void tst_qfile::readSmallFiles_QFile_data()
void tst_qfile::readSmallFiles_QFSFileEngine_data()
{
#ifdef QT_BUILD_INTERNAL
readSmallFiles_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::NotOpen);
readSmallFiles_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered);
readSmallFiles_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::NotOpen);
readSmallFiles_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::Unbuffered);
#else
QTest::addColumn<int>("dummy");
QTest::newRow("Test will be skipped") << -1;
#endif
}
void tst_qfile::readSmallFiles_posix_data()
@ -606,6 +642,7 @@ void tst_qfile::readSmallFiles()
}
}
break;
#ifdef QT_BUILD_INTERNAL
case(QFSFileEngineBenchmark): {
QList<QFSFileEngine*> fileList;
Q_FOREACH(QString file, files) {
@ -626,6 +663,7 @@ void tst_qfile::readSmallFiles()
}
}
break;
#endif
case(PosixBenchmark): {
QList<FILE*> fileList;
Q_FOREACH(QString file, files) {

View File

@ -1,6 +1,6 @@
TEMPLATE = app
TARGET = tst_bench_qfile
QT = core testlib
QT = core core-private testlib
win32: DEFINES+= _CRT_SECURE_NO_WARNINGS
SOURCES += main.cpp