mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-23 18:32:55 +00:00
merge QFSFileEngine into QAbstractFileEngine
that finally happened Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
d7f76da3b1
commit
f23acad20e
24 changed files with 945 additions and 1712 deletions
|
@ -44,7 +44,6 @@ include/katie/QtCore/QElapsedTimer
|
|||
include/katie/QtCore/QEvent
|
||||
include/katie/QtCore/QEventLoop
|
||||
include/katie/QtCore/QExplicitlySharedDataPointer
|
||||
include/katie/QtCore/QFSFileEngine
|
||||
include/katie/QtCore/QFile
|
||||
include/katie/QtCore/QFileInfo
|
||||
include/katie/QtCore/QFileInfoList
|
||||
|
@ -211,7 +210,6 @@ include/katie/QtCore/qeventloop.h
|
|||
include/katie/QtCore/qfile.h
|
||||
include/katie/QtCore/qfileinfo.h
|
||||
include/katie/QtCore/qfilesystemwatcher.h
|
||||
include/katie/QtCore/qfsfileengine.h
|
||||
include/katie/QtCore/qglobal.h
|
||||
include/katie/QtCore/qhash.h
|
||||
include/katie/QtCore/qiodevice.h
|
||||
|
|
|
@ -207,7 +207,6 @@ classlist = [
|
|||
"QFontMetricsF",
|
||||
"QFormLayout",
|
||||
"QFrame",
|
||||
"QFSFileEngine",
|
||||
"QFtp",
|
||||
"QFuture",
|
||||
"QFutureInterface",
|
||||
|
|
|
@ -35,7 +35,6 @@ set(CORE_PUBLIC_HEADERS
|
|||
QStandardPaths
|
||||
QPlugin
|
||||
QPluginLoader
|
||||
QFSFileEngine
|
||||
QLine
|
||||
QIODevice
|
||||
QPair
|
||||
|
@ -129,9 +128,6 @@ set(CORE_HEADERS
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/io/qsettings.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qsettings_p.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qstandardpaths.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qfsfileengine.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qfsfileengine_p.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qfsfileengine_iterator_p.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qfilesystemwatcher.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qfilesystemwatcher_p.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qfilesystemwatcher_unix_p.h
|
||||
|
@ -252,12 +248,9 @@ set(CORE_SOURCES
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/io/qurl.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qsettings.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qstandardpaths.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qfsfileengine.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qfsfileengine_iterator.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qfilesystemwatcher.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qfilesystemwatcher_unix.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qfilesystementry.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qfsfileengine_unix.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qfilesystemengine_unix.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qprocess_unix.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/io/qfilesystemiterator_unix.cpp
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -28,7 +28,6 @@
|
|||
#error qabstractfileengine.h must be included before any header file that defines open
|
||||
#endif
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QVariant;
|
||||
|
@ -86,42 +85,42 @@ public:
|
|||
AccessTime
|
||||
};
|
||||
|
||||
virtual ~QAbstractFileEngine();
|
||||
~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 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;
|
||||
virtual bool open(QIODevice::OpenMode openMode); // virtual for QTemporaryFile
|
||||
virtual bool close(); // virtual for QTemporaryFile
|
||||
bool flush();
|
||||
qint64 size() const;
|
||||
qint64 pos() const;
|
||||
bool seek(qint64 pos);
|
||||
bool isSequential() const;
|
||||
virtual bool remove(); // virtual for QTemporaryFile
|
||||
bool copy(const QString &newName);
|
||||
virtual bool rename(const QString &newName); // virtual for QTemporaryFile
|
||||
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 isRelativePath() const;
|
||||
QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
|
||||
FileFlags fileFlags(FileFlags type=FileInfoAll) const;
|
||||
bool setPermissions(uint perms);
|
||||
QString fileName(FileName file=DefaultName) const;
|
||||
uint ownerId(FileOwner) const;
|
||||
QString owner(FileOwner) const;
|
||||
QDateTime fileTime(FileTime time) const;
|
||||
virtual void setFileName(const QString &file); // virtual for QTemporaryFile
|
||||
int handle() const;
|
||||
uchar *map(qint64 offset, qint64 size);
|
||||
bool unmap(uchar *ptr);
|
||||
|
||||
typedef QAbstractFileEngineIterator Iterator;
|
||||
virtual Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames);
|
||||
virtual Iterator *endEntryList();
|
||||
Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames);
|
||||
Iterator *endEntryList();
|
||||
|
||||
virtual qint64 read(char *data, qint64 maxlen);
|
||||
virtual qint64 readLine(char *data, qint64 maxlen);
|
||||
virtual qint64 write(const char *data, qint64 len);
|
||||
qint64 read(char *data, qint64 maxlen);
|
||||
qint64 readLine(char *data, qint64 maxlen);
|
||||
qint64 write(const char *data, qint64 len);
|
||||
|
||||
QFile::FileError error() const;
|
||||
QString errorString() const;
|
||||
|
@ -151,12 +150,20 @@ public:
|
|||
uchar *address;
|
||||
};
|
||||
|
||||
virtual bool extension(Extension extension, const ExtensionOption *option = nullptr, ExtensionReturn *output = nullptr);
|
||||
virtual bool supportsExtension(Extension extension) const;
|
||||
bool extension(Extension extension, const ExtensionOption *option = nullptr, ExtensionReturn *output = nullptr);
|
||||
bool supportsExtension(Extension extension) const;
|
||||
|
||||
// Factory
|
||||
static QAbstractFileEngine *create(const QString &fileName);
|
||||
|
||||
//FS only!!
|
||||
bool open(QIODevice::OpenMode flags, int fd, 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();
|
||||
|
||||
protected:
|
||||
void setError(QFile::FileError error, const QString &str);
|
||||
|
||||
|
@ -167,8 +174,9 @@ protected:
|
|||
private:
|
||||
Q_DECLARE_PRIVATE(QAbstractFileEngine)
|
||||
Q_DISABLE_COPY(QAbstractFileEngine)
|
||||
};
|
||||
|
||||
friend class QFilePrivate;
|
||||
};
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractFileEngine::FileFlags)
|
||||
|
||||
class QAbstractFileEngineIteratorPrivate;
|
||||
|
@ -176,17 +184,17 @@ class Q_CORE_EXPORT QAbstractFileEngineIterator
|
|||
{
|
||||
public:
|
||||
QAbstractFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters);
|
||||
virtual ~QAbstractFileEngineIterator();
|
||||
~QAbstractFileEngineIterator();
|
||||
|
||||
virtual QString next() = 0;
|
||||
virtual bool hasNext() const = 0;
|
||||
QString next();
|
||||
bool hasNext() const;
|
||||
|
||||
QString path() const;
|
||||
QStringList nameFilters() const;
|
||||
QDir::Filters filters() const;
|
||||
|
||||
virtual QString currentFileName() const = 0;
|
||||
virtual QFileInfo currentFileInfo() const;
|
||||
QString currentFileName() const;
|
||||
QFileInfo currentFileInfo() const;
|
||||
QString currentFilePath() const;
|
||||
|
||||
private:
|
||||
|
@ -199,5 +207,4 @@ private:
|
|||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
||||
#endif // QABSTRACTFILEENGINE_H
|
||||
|
|
|
@ -34,6 +34,10 @@
|
|||
//
|
||||
|
||||
#include "QtCore/qabstractfileengine.h"
|
||||
#include "qfilesystementry_p.h"
|
||||
#include "qfilesystemmetadata_p.h"
|
||||
#include "qfilesystemiterator_p.h"
|
||||
#include "qhash.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
@ -43,14 +47,32 @@ public:
|
|||
inline QAbstractFileEnginePrivate()
|
||||
: fileError(QFile::UnspecifiedError)
|
||||
{
|
||||
init();
|
||||
}
|
||||
inline virtual ~QAbstractFileEnginePrivate() { }
|
||||
|
||||
QFile::FileError fileError;
|
||||
QString errorString;
|
||||
|
||||
QFileSystemEntry fileEntry;
|
||||
QIODevice::OpenMode openMode;
|
||||
|
||||
uchar *map(qint64 offset, qint64 size);
|
||||
bool unmap(uchar *ptr);
|
||||
|
||||
mutable QFileSystemMetaData metaData;
|
||||
|
||||
QHash<uchar *, QPair<int /*offset % PageSize*/, size_t /*length + offset % PageSize*/> > maps;
|
||||
int fd;
|
||||
|
||||
bool closeFileHandle;
|
||||
|
||||
bool doStat(QFileSystemMetaData::MetaDataFlags flags) const;
|
||||
|
||||
QAbstractFileEngine *q_ptr;
|
||||
Q_DECLARE_PUBLIC(QAbstractFileEngine)
|
||||
|
||||
protected:
|
||||
void init();
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "qdebug.h"
|
||||
#endif
|
||||
#include "qdiriterator.h"
|
||||
#include "qfsfileengine.h"
|
||||
#include "qdatetime.h"
|
||||
#include "qstring.h"
|
||||
#include "qregexp.h"
|
||||
|
|
|
@ -79,7 +79,6 @@
|
|||
#include "qfilesystementry_p.h"
|
||||
#include "qfilesystemmetadata_p.h"
|
||||
#include "qfilesystemengine_p.h"
|
||||
#include "qfsfileengine.h"
|
||||
#include "qfileinfo_p.h"
|
||||
#include "qscopedpointer.h"
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "qplatformdefs.h"
|
||||
#include "qdebug.h"
|
||||
#include "qfile.h"
|
||||
#include "qfsfileengine.h"
|
||||
#include "qtemporaryfile.h"
|
||||
#include "qlist.h"
|
||||
#include "qfileinfo.h"
|
||||
|
@ -59,9 +58,8 @@ QFilePrivate::openExternalFile(int flags, int fd, QFile::FileHandleFlags handleF
|
|||
#else
|
||||
delete fileEngine;
|
||||
fileEngine = 0;
|
||||
QFSFileEngine *fe = new QFSFileEngine;
|
||||
fileEngine = fe;
|
||||
return fe->open(QIODevice::OpenMode(flags), fd, handleFlags);
|
||||
fileEngine = new QAbstractFileEngine();
|
||||
return fileEngine->open(QIODevice::OpenMode(flags), fd, handleFlags);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -28,17 +28,14 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
class QDir;
|
||||
class QDateTime;
|
||||
class QDirIteratorPrivate;
|
||||
class QFSFileEngineIterator;
|
||||
class QFileInfoPrivate;
|
||||
|
||||
class Q_CORE_EXPORT QFileInfo
|
||||
{
|
||||
friend class QDirIteratorPrivate;
|
||||
friend class QFSFileEngineIterator;
|
||||
friend class QAbstractFileEngineIteratorPrivate;
|
||||
public:
|
||||
QFileInfo();
|
||||
QFileInfo(const QString &file);
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
#include "qplatformdefs.h"
|
||||
#include "qfilesystemengine_p.h"
|
||||
#include "qfsfileengine.h"
|
||||
#include "qfile.h"
|
||||
#include "qcore_unix_p.h"
|
||||
#include "qcorecommon_p.h"
|
||||
|
@ -476,7 +475,7 @@ QFileSystemEntry QFileSystemEngine::currentPath()
|
|||
|
||||
#ifndef QT_NO_DEBUG
|
||||
if (result.isEmpty())
|
||||
qWarning("QFSFileEngine::currentPath: " GETCWDFUNCNAME "() failed");
|
||||
qWarning("QAbstractFileEngine::currentPath: " GETCWDFUNCNAME "() failed");
|
||||
#endif
|
||||
#undef GETCWDFUNCNAME
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "qfilesystementry_p.h"
|
||||
#include "qdir.h"
|
||||
#include "qfile.h"
|
||||
#include "qfsfileengine_p.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
|
@ -1,554 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Copyright (C) 2016 Ivailo Monev
|
||||
**
|
||||
** This file is part of the QtCore module of the Katie 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.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qfsfileengine_p.h"
|
||||
#include "qfsfileengine_iterator_p.h"
|
||||
#include "qfilesystemengine_p.h"
|
||||
#include "qdatetime.h"
|
||||
#include "qdiriterator.h"
|
||||
#include "qset.h"
|
||||
#include "qdebug.h"
|
||||
#include "qcore_unix_p.h"
|
||||
|
||||
#ifndef QT_NO_FSFILEENGINE
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
/*! \class QFSFileEngine
|
||||
\brief The QFSFileEngine class implements Qt's default file engine.
|
||||
\since 4.1
|
||||
|
||||
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.
|
||||
|
||||
QFSFileEngine is the default file engine for accessing regular files. It
|
||||
is provided for convenience; by subclassing this class, you can alter its
|
||||
behavior slightly, without having to write a complete QAbstractFileEngine
|
||||
subclass
|
||||
|
||||
It can also be useful to create a QFSFileEngine object directly if you
|
||||
need to use the local file system inside QAbstractFileEngine::create(), in
|
||||
order to avoid recursion (as higher-level classes tend to call
|
||||
QAbstractFileEngine::create()).
|
||||
*/
|
||||
|
||||
//**************** QFSFileEnginePrivate
|
||||
QFSFileEnginePrivate::QFSFileEnginePrivate() : QAbstractFileEnginePrivate()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
void QFSFileEnginePrivate::init()
|
||||
{
|
||||
metaData.clear();
|
||||
openMode = QIODevice::NotOpen;
|
||||
fd = -1;
|
||||
closeFileHandle = false;
|
||||
}
|
||||
|
||||
/*!
|
||||
Constructs a QFSFileEngine for the file name \a file.
|
||||
*/
|
||||
QFSFileEngine::QFSFileEngine(const QString &file)
|
||||
: QAbstractFileEngine(*new QFSFileEnginePrivate)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
d->fileEntry = QFileSystemEntry(file);
|
||||
}
|
||||
|
||||
/*!
|
||||
Constructs a QFSFileEngine.
|
||||
*/
|
||||
QFSFileEngine::QFSFileEngine() : QAbstractFileEngine(*new QFSFileEnginePrivate)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
QFSFileEngine::QFSFileEngine(QFSFileEnginePrivate &dd)
|
||||
: QAbstractFileEngine(dd)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
Destructs the QFSFileEngine.
|
||||
*/
|
||||
QFSFileEngine::~QFSFileEngine()
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
if (d->closeFileHandle) {
|
||||
if (d->fd != -1) {
|
||||
qt_safe_close(d->fd);
|
||||
}
|
||||
}
|
||||
QList<uchar*> keys = d->maps.keys();
|
||||
for (int i = 0; i < keys.count(); ++i)
|
||||
unmap(keys.at(i));
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
void QFSFileEngine::setFileName(const QString &file)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
d->init();
|
||||
d->fileEntry = QFileSystemEntry(file);
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QFSFileEngine::open(QIODevice::OpenMode openMode)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
if (Q_UNLIKELY(d->fileEntry.isEmpty())) {
|
||||
qWarning("QFSFileEngine::open: No file name specified");
|
||||
setError(QFile::OpenError, QLatin1String("No file name specified"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Append implies WriteOnly.
|
||||
if (openMode & QFile::Append)
|
||||
openMode |= QFile::WriteOnly;
|
||||
|
||||
// WriteOnly implies Truncate if neither ReadOnly nor Append are sent.
|
||||
if ((openMode & QFile::WriteOnly) && !(openMode & (QFile::ReadOnly | QFile::Append)))
|
||||
openMode |= QFile::Truncate;
|
||||
|
||||
d->openMode = openMode;
|
||||
d->metaData.clear();
|
||||
d->fd = -1;
|
||||
|
||||
int flags = QT_OPEN_RDONLY;
|
||||
|
||||
if ((d->openMode & QFile::ReadWrite) == QFile::ReadWrite) {
|
||||
flags = QT_OPEN_RDWR | QT_OPEN_CREAT;
|
||||
} else if (d->openMode & QFile::WriteOnly) {
|
||||
flags = QT_OPEN_WRONLY | QT_OPEN_CREAT;
|
||||
}
|
||||
|
||||
if (d->openMode & QFile::Append) {
|
||||
flags |= QT_OPEN_APPEND;
|
||||
} else if (d->openMode & QFile::WriteOnly) {
|
||||
if ((d->openMode & QFile::Truncate) || !(d->openMode & QFile::ReadOnly))
|
||||
flags |= QT_OPEN_TRUNC;
|
||||
}
|
||||
|
||||
if (d->openMode & QFile::Unbuffered) {
|
||||
#ifdef O_DSYNC
|
||||
flags |= O_DSYNC;
|
||||
#else
|
||||
flags |= O_SYNC;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Try to open the file.
|
||||
const QByteArray native = d->fileEntry.nativeFilePath();
|
||||
d->fd = qt_safe_open(native.constData(), flags, 0666);
|
||||
|
||||
// On failure, return and report the error.
|
||||
if (d->fd == -1) {
|
||||
setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError,
|
||||
qt_error_string(errno));
|
||||
d->openMode = QIODevice::NotOpen;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Refuse to open directories, EISDIR is not a thing (by standards) for
|
||||
// non-write modes.
|
||||
QT_STATBUF statbuf;
|
||||
if (QT_FSTAT(d->fd, &statbuf) == 0 && S_ISDIR(statbuf.st_mode)) {
|
||||
setError(QFile::OpenError, QLatin1String("file to open is a directory"));
|
||||
qt_safe_close(d->fd);
|
||||
d->openMode = QIODevice::NotOpen;
|
||||
d->fd = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Seek to the end when in Append mode.
|
||||
if (d->openMode & QFile::Append) {
|
||||
if (QT_LSEEK(d->fd, 0, SEEK_END) == -1) {
|
||||
setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError,
|
||||
qt_error_string(errno));
|
||||
qt_safe_close(d->fd);
|
||||
d->openMode = QIODevice::NotOpen;
|
||||
d->fd = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
d->closeFileHandle = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
Opens the file descriptor \a fd in \a openMode mode. Returns true
|
||||
on success; otherwise returns false.
|
||||
|
||||
The \a handleFlags argument specifies whether the file handle will be
|
||||
closed by Katie. See the QFile::FileHandleFlags documentation for more
|
||||
information.
|
||||
*/
|
||||
bool QFSFileEngine::open(QIODevice::OpenMode openMode, int fd, QFile::FileHandleFlags handleFlags)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
|
||||
// Append implies WriteOnly.
|
||||
if (openMode & QFile::Append)
|
||||
openMode |= QFile::WriteOnly;
|
||||
|
||||
// WriteOnly implies Truncate if neither ReadOnly nor Append are sent.
|
||||
if ((openMode & QFile::WriteOnly) && !(openMode & (QFile::ReadOnly | QFile::Append)))
|
||||
openMode |= QFile::Truncate;
|
||||
|
||||
d->openMode = openMode;
|
||||
d->closeFileHandle = (handleFlags & QFile::AutoCloseHandle);
|
||||
d->fileEntry.clear();
|
||||
d->fd = fd;
|
||||
d->metaData.clear();
|
||||
|
||||
// Seek to the end when in Append mode.
|
||||
if (d->openMode & QFile::Append) {
|
||||
if (QT_LSEEK(d->fd, 0, SEEK_END) == -1) {
|
||||
setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError,
|
||||
qt_error_string(errno));
|
||||
if (d->closeFileHandle) {
|
||||
qt_safe_close(d->fd);
|
||||
}
|
||||
d->openMode = QIODevice::NotOpen;
|
||||
d->fd = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QFSFileEngine::close()
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
d->openMode = QIODevice::NotOpen;
|
||||
|
||||
if (d->fd == -1)
|
||||
return false;
|
||||
|
||||
d->metaData.clear();
|
||||
|
||||
// Close the file if we created the handle.
|
||||
if (d->closeFileHandle) {
|
||||
int ret = qt_safe_close(d->fd);
|
||||
|
||||
// We must reset these guys regardless; calling close again after a
|
||||
// failed close causes crashes on some systems.
|
||||
d->fd = -1;
|
||||
|
||||
// Report errors.
|
||||
if (ret != 0) {
|
||||
setError(QFile::UnspecifiedError, qt_error_string(errno));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QFSFileEngine::flush()
|
||||
{
|
||||
Q_D(const QFSFileEngine);
|
||||
return (d->fd != -1);
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
qint64 QFSFileEngine::size() const
|
||||
{
|
||||
Q_D(const QFSFileEngine);
|
||||
|
||||
if (!d->doStat(QFileSystemMetaData::SizeAttribute))
|
||||
return 0;
|
||||
return d->metaData.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
qint64 QFSFileEngine::pos() const
|
||||
{
|
||||
Q_D(const QFSFileEngine);
|
||||
return (qint64)QT_LSEEK(d->fd, 0, SEEK_CUR);
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QFSFileEngine::seek(qint64 pos)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
|
||||
if (pos < 0 || pos != qint64(QT_OFF_T(pos)))
|
||||
return false;
|
||||
|
||||
if (Q_UNLIKELY(QT_LSEEK(d->fd, QT_OFF_T(pos), SEEK_SET) == -1)) {
|
||||
qWarning() << "QFile::at: Cannot set file position" << pos;
|
||||
setError(QFile::PositionError, qt_error_string(errno));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
int QFSFileEngine::handle() const
|
||||
{
|
||||
Q_D(const QFSFileEngine);
|
||||
return d->fd;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
qint64 QFSFileEngine::read(char *data, qint64 maxlen)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
|
||||
if (maxlen < 0) {
|
||||
setError(QFile::ReadError, qt_error_string(EINVAL));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qint64 readBytes = 0;
|
||||
bool eof = false;
|
||||
|
||||
if (d->fd != -1) {
|
||||
ssize_t result;
|
||||
do {
|
||||
result = QT_READ(d->fd, data + readBytes, size_t(maxlen - readBytes));
|
||||
} while ((result == -1 && errno == EINTR)
|
||||
|| (result > 0 && (readBytes += result) < maxlen));
|
||||
|
||||
eof = !(result == -1);
|
||||
}
|
||||
|
||||
if (!eof && readBytes == 0) {
|
||||
readBytes = -1;
|
||||
setError(QFile::ReadError, qt_error_string(errno));
|
||||
}
|
||||
|
||||
return readBytes;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
qint64 QFSFileEngine::write(const char *data, qint64 len)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
|
||||
if (len < 0 || len != qint64(size_t(len))) {
|
||||
setError(QFile::WriteError, qt_error_string(EINVAL));
|
||||
return -1;
|
||||
}
|
||||
|
||||
qint64 writtenBytes = 0;
|
||||
|
||||
if (d->fd != -1) {
|
||||
ssize_t result;
|
||||
do {
|
||||
result = QT_WRITE(d->fd, data + writtenBytes, size_t(len - writtenBytes));
|
||||
} while ((result == -1 && errno == EINTR)
|
||||
|| (result > 0 && (writtenBytes += result) < len));
|
||||
}
|
||||
|
||||
if (len && writtenBytes == 0) {
|
||||
writtenBytes = -1;
|
||||
setError(errno == ENOSPC ? QFile::ResourceError : QFile::WriteError, qt_error_string(errno));
|
||||
}
|
||||
|
||||
d->metaData.clearFlags(QFileSystemMetaData::SizeAttribute);
|
||||
|
||||
return writtenBytes;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_FILESYSTEMITERATOR
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
QAbstractFileEngine::Iterator *QFSFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames)
|
||||
{
|
||||
return new QFSFileEngineIterator(filters, filterNames);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QFSFileEngine::isSequential() const
|
||||
{
|
||||
Q_D(const QFSFileEngine);
|
||||
if (d->doStat(QFileSystemMetaData::SequentialType))
|
||||
return d->metaData.isSequential();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QFSFileEngine::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
|
||||
if (extension == MapExtension) {
|
||||
const MapExtensionOption *options = (MapExtensionOption*)(option);
|
||||
MapExtensionReturn *returnValue = static_cast<MapExtensionReturn*>(output);
|
||||
returnValue->address = d->map(options->offset, options->size);
|
||||
return (returnValue->address != 0);
|
||||
} else if (extension == UnMapExtension) {
|
||||
UnMapExtensionOption *options = (UnMapExtensionOption*)option;
|
||||
return d->unmap(options->address);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
bool QFSFileEngine::supportsExtension(Extension extension) const
|
||||
{
|
||||
Q_D(const QFSFileEngine);
|
||||
if (extension == FastReadLineExtension && d->fd != -1 && isSequential())
|
||||
return true;
|
||||
if (extension == UnMapExtension || extension == MapExtension)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*! \fn bool QFSFileEngine::copy(const QString ©Name)
|
||||
|
||||
Copy the file to file \a copyName.
|
||||
*/
|
||||
|
||||
/*! \fn QString QFSFileEngine::currentPath(const QString &fileName)
|
||||
For Unix, returns the current working directory for the file
|
||||
engine.
|
||||
|
||||
\sa setCurrentPath()
|
||||
*/
|
||||
|
||||
/*! \fn QString QFSFileEngine::fileName(FileName file) const
|
||||
\reimp
|
||||
*/
|
||||
|
||||
/*! \fn QDateTime QFSFileEngine::fileTime(FileTime time) const
|
||||
\reimp
|
||||
*/
|
||||
|
||||
/*! \fn QString QFSFileEngine::homePath()
|
||||
Returns the home path of the current user.
|
||||
|
||||
\sa rootPath()
|
||||
*/
|
||||
|
||||
/*! \fn bool QFSFileEngine::isRelativePath() const
|
||||
\reimp
|
||||
*/
|
||||
|
||||
/*! \fn bool QFSFileEngine::link(const QString &newName)
|
||||
|
||||
Creates a link from the file currently specified by fileName() to
|
||||
\a newName. What a link is depends on the underlying filesystem
|
||||
(be it a shortcut on Windows or a symbolic link on Unix). Returns
|
||||
true if successful; otherwise returns false.
|
||||
*/
|
||||
|
||||
/*! \fn bool QFSFileEngine::mkdir(const QString &name, bool createParentDirectories) const
|
||||
\reimp
|
||||
*/
|
||||
|
||||
/*! \fn uint QFSFileEngine::ownerId(FileOwner own) const
|
||||
In Unix, if stat() is successful, the \c uid is returned if
|
||||
\a own is the owner. Otherwise the \c gid is returned. If stat()
|
||||
is unsuccessful, -2 is returned.
|
||||
*/
|
||||
|
||||
/*! \fn QString QFSFileEngine::owner(FileOwner own) const
|
||||
\reimp
|
||||
*/
|
||||
|
||||
/*! \fn bool QFSFileEngine::remove()
|
||||
\reimp
|
||||
*/
|
||||
|
||||
/*! \fn bool QFSFileEngine::rename(const QString &newName)
|
||||
\reimp
|
||||
*/
|
||||
|
||||
/*! \fn bool QFSFileEngine::rmdir(const QString &name, bool recurseParentDirectories) const
|
||||
\reimp
|
||||
*/
|
||||
|
||||
/*! \fn QString QFSFileEngine::rootPath()
|
||||
Returns the root path.
|
||||
|
||||
\sa homePath()
|
||||
*/
|
||||
|
||||
/*! \fn bool QFSFileEngine::setCurrentPath(const QString &path)
|
||||
Sets the current path (e.g., for QDir), to \a path. Returns true if the
|
||||
new path exists; otherwise this function does nothing, and returns false.
|
||||
|
||||
\sa currentPath()
|
||||
*/
|
||||
|
||||
/*! \fn bool QFSFileEngine::setPermissions(uint perms)
|
||||
\reimp
|
||||
*/
|
||||
|
||||
/*! \fn bool QFSFileEngine::setSize(qint64 size)
|
||||
\reimp
|
||||
*/
|
||||
|
||||
/*! \fn QString QFSFileEngine::tempPath()
|
||||
Returns the temporary path (i.e., a path in which it is safe
|
||||
to store temporary files).
|
||||
*/
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_FSFILEENGINE
|
|
@ -1,94 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Copyright (C) 2016 Ivailo Monev
|
||||
**
|
||||
** This file is part of the QtCore module of the Katie 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.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QFSFILEENGINE_H
|
||||
#define QFSFILEENGINE_H
|
||||
|
||||
#include <QtCore/qabstractfileengine.h>
|
||||
|
||||
#ifndef QT_NO_FSFILEENGINE
|
||||
|
||||
|
||||
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 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 isRelativePath() 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;
|
||||
|
||||
#ifndef QT_NO_FILESYSTEMITERATOR
|
||||
Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames);
|
||||
#endif
|
||||
|
||||
qint64 read(char *data, qint64 maxlen);
|
||||
qint64 write(const char *data, qint64 len);
|
||||
|
||||
bool extension(Extension extension, const ExtensionOption *option = nullptr, ExtensionReturn *output = nullptr);
|
||||
bool supportsExtension(Extension extension) const;
|
||||
|
||||
//FS only!!
|
||||
bool open(QIODevice::OpenMode flags, int fd, 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();
|
||||
|
||||
protected:
|
||||
QFSFileEngine(QFSFileEnginePrivate &dd);
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
||||
#endif // QT_NO_FSFILEENGINE
|
||||
|
||||
#endif // QFSFILEENGINE_H
|
|
@ -1,91 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Copyright (C) 2016 Ivailo Monev
|
||||
**
|
||||
** This file is part of the QtCore module of the Katie 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.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qfsfileengine_iterator_p.h"
|
||||
#include "qfileinfo_p.h"
|
||||
#include "qvariant.h"
|
||||
|
||||
#ifndef QT_NO_FSFILEENGINE
|
||||
#ifndef QT_NO_FILESYSTEMITERATOR
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QFSFileEngineIterator::QFSFileEngineIterator(QDir::Filters filters, const QStringList &filterNames)
|
||||
: QAbstractFileEngineIterator(filters, filterNames)
|
||||
, nativeIterator(nullptr)
|
||||
, done(false)
|
||||
{
|
||||
}
|
||||
|
||||
QFSFileEngineIterator::~QFSFileEngineIterator()
|
||||
{
|
||||
delete nativeIterator;
|
||||
}
|
||||
|
||||
bool QFSFileEngineIterator::hasNext() const
|
||||
{
|
||||
if (!done && !nativeIterator) {
|
||||
nativeIterator = new QFileSystemIterator(QFileSystemEntry(path()));
|
||||
advance();
|
||||
}
|
||||
|
||||
return !done;
|
||||
}
|
||||
|
||||
QString QFSFileEngineIterator::next()
|
||||
{
|
||||
if (!hasNext())
|
||||
return QString();
|
||||
|
||||
advance();
|
||||
return currentFilePath();
|
||||
}
|
||||
|
||||
void QFSFileEngineIterator::advance() const
|
||||
{
|
||||
currentInfo = nextInfo;
|
||||
|
||||
QFileSystemEntry entry;
|
||||
QFileSystemMetaData data;
|
||||
if (nativeIterator->advance(entry, data)) {
|
||||
nextInfo = QFileInfo(new QFileInfoPrivate(entry, data));
|
||||
} else {
|
||||
done = true;
|
||||
delete nativeIterator;
|
||||
nativeIterator = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
QString QFSFileEngineIterator::currentFileName() const
|
||||
{
|
||||
return currentInfo.fileName();
|
||||
}
|
||||
|
||||
QFileInfo QFSFileEngineIterator::currentFileInfo() const
|
||||
{
|
||||
return currentInfo;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_FILESYSTEMITERATOR
|
||||
|
||||
#endif // QT_NO_FSFILEENGINE
|
|
@ -1,72 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Copyright (C) 2016 Ivailo Monev
|
||||
**
|
||||
** This file is part of the QtCore module of the Katie 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.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QFSFILEENGINE_ITERATOR_P_H
|
||||
#define QFSFILEENGINE_ITERATOR_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Katie API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include "qabstractfileengine.h"
|
||||
#include "qfilesystemiterator_p.h"
|
||||
#include "qdir.h"
|
||||
|
||||
#ifndef QT_NO_FSFILEENGINE
|
||||
#ifndef QT_NO_FILESYSTEMITERATOR
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QFSFileEngineIteratorPrivate;
|
||||
|
||||
class QFSFileEngineIterator : public QAbstractFileEngineIterator
|
||||
{
|
||||
public:
|
||||
QFSFileEngineIterator(QDir::Filters filters, const QStringList &filterNames);
|
||||
~QFSFileEngineIterator();
|
||||
|
||||
QString next();
|
||||
bool hasNext() const;
|
||||
|
||||
QString currentFileName() const;
|
||||
QFileInfo currentFileInfo() const;
|
||||
|
||||
private:
|
||||
void advance() const;
|
||||
mutable QFileSystemIterator* nativeIterator;
|
||||
mutable QFileInfo currentInfo;
|
||||
mutable QFileInfo nextInfo;
|
||||
mutable bool done;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_FILESYSTEMITERATOR
|
||||
#endif // QT_NO_FSFILEENGINE
|
||||
|
||||
#endif // QFSFILEENGINE_ITERATOR_P_H
|
|
@ -1,77 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Copyright (C) 2016 Ivailo Monev
|
||||
**
|
||||
** This file is part of the QtCore module of the Katie 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.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QFSFILEENGINE_P_H
|
||||
#define QFSFILEENGINE_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Katie API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include "qplatformdefs.h"
|
||||
#include "qfsfileengine.h"
|
||||
#include "qabstractfileengine_p.h"
|
||||
#include "qfilesystementry_p.h"
|
||||
#include "qfilesystemmetadata_p.h"
|
||||
#include "qhash.h"
|
||||
|
||||
#ifndef QT_NO_FSFILEENGINE
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class Q_AUTOTEST_EXPORT QFSFileEnginePrivate : public QAbstractFileEnginePrivate
|
||||
{
|
||||
Q_DECLARE_PUBLIC(QFSFileEngine)
|
||||
|
||||
public:
|
||||
QFileSystemEntry fileEntry;
|
||||
QIODevice::OpenMode openMode;
|
||||
|
||||
uchar *map(qint64 offset, qint64 size);
|
||||
bool unmap(uchar *ptr);
|
||||
|
||||
mutable QFileSystemMetaData metaData;
|
||||
|
||||
QHash<uchar *, QPair<int /*offset % PageSize*/, size_t /*length + offset % PageSize*/> > maps;
|
||||
int fd;
|
||||
|
||||
bool closeFileHandle;
|
||||
|
||||
bool doStat(QFileSystemMetaData::MetaDataFlags flags) const;
|
||||
|
||||
protected:
|
||||
QFSFileEnginePrivate();
|
||||
|
||||
void init();
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_FSFILEENGINE
|
||||
|
||||
#endif // QFSFILEENGINE_P_H
|
|
@ -1,381 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Copyright (C) 2016 Ivailo Monev
|
||||
**
|
||||
** This file is part of the QtCore module of the Katie 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.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qplatformdefs.h"
|
||||
#include "qabstractfileengine.h"
|
||||
#include "qfsfileengine_p.h"
|
||||
#include "qcore_unix_p.h"
|
||||
#include "qfilesystementry_p.h"
|
||||
#include "qfilesystemengine_p.h"
|
||||
|
||||
#ifndef QT_NO_FSFILEENGINE
|
||||
|
||||
#include "qfile.h"
|
||||
#include "qdir.h"
|
||||
#include "qdatetime.h"
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
bool QFSFileEnginePrivate::doStat(QFileSystemMetaData::MetaDataFlags flags) const
|
||||
{
|
||||
if (!metaData.hasFlags(flags)) {
|
||||
if (!fileEntry.isEmpty())
|
||||
QFileSystemEngine::fillMetaData(fileEntry, metaData, metaData.missingFlags(flags));
|
||||
|
||||
if (metaData.missingFlags(flags) && fd != -1)
|
||||
QFileSystemEngine::fillMetaData(fd, metaData);
|
||||
}
|
||||
|
||||
return metaData.exists();
|
||||
}
|
||||
|
||||
uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size)
|
||||
{
|
||||
Q_Q(QFSFileEngine);
|
||||
if (openMode == QIODevice::NotOpen) {
|
||||
q->setError(QFile::PermissionsError, qt_error_string(EACCES));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (offset < 0 || offset != qint64(QT_OFF_T(offset))
|
||||
|| size < 0 || quint64(size) > quint64(size_t(-1))) {
|
||||
q->setError(QFile::UnspecifiedError, qt_error_string(EINVAL));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// If we know the mapping will extend beyond EOF, fail early to avoid
|
||||
// undefined behavior. Otherwise, let mmap have its say.
|
||||
if (doStat(QFileSystemMetaData::SizeAttribute)
|
||||
&& (QT_OFF_T(size) > metaData.size() - QT_OFF_T(offset)))
|
||||
qWarning("QFSFileEngine::map: Mapping a file beyond its size is not portable");
|
||||
|
||||
int access = 0;
|
||||
if (openMode & QIODevice::ReadOnly) access |= PROT_READ;
|
||||
if (openMode & QIODevice::WriteOnly) access |= PROT_WRITE;
|
||||
|
||||
static const int pageSize = ::getpagesize();
|
||||
const int extra = offset % pageSize;
|
||||
|
||||
if (quint64(size + extra) > quint64((size_t)-1)) {
|
||||
q->setError(QFile::UnspecifiedError, qt_error_string(EINVAL));
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t realSize = (size_t)size + extra;
|
||||
QT_OFF_T realOffset = QT_OFF_T(offset);
|
||||
realOffset &= ~(QT_OFF_T(pageSize - 1));
|
||||
|
||||
void *mapAddress = QT_MMAP(nullptr, realSize,
|
||||
access, MAP_SHARED, fd, realOffset);
|
||||
if (mapAddress != MAP_FAILED) {
|
||||
uchar *address = extra + static_cast<uchar*>(mapAddress);
|
||||
maps[address] = QPair<int,size_t>(extra, realSize);
|
||||
return address;
|
||||
}
|
||||
|
||||
switch(errno) {
|
||||
case EBADF:
|
||||
q->setError(QFile::PermissionsError, qt_error_string(EACCES));
|
||||
break;
|
||||
case ENFILE:
|
||||
case ENOMEM:
|
||||
q->setError(QFile::ResourceError, qt_error_string(errno));
|
||||
break;
|
||||
case EINVAL:
|
||||
// size are out of bounds
|
||||
default:
|
||||
q->setError(QFile::UnspecifiedError, qt_error_string(errno));
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool QFSFileEnginePrivate::unmap(uchar *ptr)
|
||||
{
|
||||
Q_Q(QFSFileEngine);
|
||||
if (!maps.contains(ptr)) {
|
||||
q->setError(QFile::PermissionsError, qt_error_string(EACCES));
|
||||
return false;
|
||||
}
|
||||
|
||||
uchar *start = ptr - maps[ptr].first;
|
||||
size_t len = maps[ptr].second;
|
||||
if (::munmap(start, len) == -1) {
|
||||
q->setError(QFile::UnspecifiedError, qt_error_string(errno));
|
||||
return false;
|
||||
}
|
||||
maps.remove(ptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QFSFileEngine::remove()
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
int error;
|
||||
bool ret = QFileSystemEngine::removeFile(d->fileEntry, &error);
|
||||
d->metaData.clear();
|
||||
if (!ret) {
|
||||
setError(QFile::RemoveError, qt_error_string(error));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool QFSFileEngine::copy(const QString &newName)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
int error;
|
||||
bool ret = QFileSystemEngine::copyFile(d->fileEntry, QFileSystemEntry(newName), &error);
|
||||
if (!ret) {
|
||||
setError(QFile::CopyError, qt_error_string(error));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool QFSFileEngine::rename(const QString &newName)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
int error;
|
||||
bool ret = QFileSystemEngine::renameFile(d->fileEntry, QFileSystemEntry(newName), &error);
|
||||
d->metaData.clear();
|
||||
if (!ret) {
|
||||
setError(QFile::RenameError, qt_error_string(error));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool QFSFileEngine::link(const QString &newName)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
int error;
|
||||
bool ret = QFileSystemEngine::createLink(d->fileEntry, QFileSystemEntry(newName), &error);
|
||||
if (!ret) {
|
||||
setError(QFile::RenameError, qt_error_string(error));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool QFSFileEngine::mkdir(const QString &name, bool createParentDirectories) const
|
||||
{
|
||||
return QFileSystemEngine::createDirectory(QFileSystemEntry(name), createParentDirectories);
|
||||
}
|
||||
|
||||
bool QFSFileEngine::rmdir(const QString &name, bool recurseParentDirectories) const
|
||||
{
|
||||
return QFileSystemEngine::removeDirectory(QFileSystemEntry(name), recurseParentDirectories);
|
||||
}
|
||||
|
||||
bool QFSFileEngine::setCurrentPath(const QString &path)
|
||||
{
|
||||
return QFileSystemEngine::setCurrentPath(QFileSystemEntry(path));
|
||||
}
|
||||
|
||||
QString QFSFileEngine::currentPath(const QString &)
|
||||
{
|
||||
return QFileSystemEngine::currentPath().filePath();
|
||||
}
|
||||
|
||||
QString QFSFileEngine::homePath()
|
||||
{
|
||||
return QFileSystemEngine::homePath();
|
||||
}
|
||||
|
||||
QString QFSFileEngine::rootPath()
|
||||
{
|
||||
return QFileSystemEngine::rootPath();
|
||||
}
|
||||
|
||||
QString QFSFileEngine::tempPath()
|
||||
{
|
||||
return QFileSystemEngine::tempPath();
|
||||
}
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(FileFlags type) const
|
||||
{
|
||||
Q_D(const QFSFileEngine);
|
||||
|
||||
if (type & Refresh)
|
||||
d->metaData.clear();
|
||||
|
||||
QAbstractFileEngine::FileFlags ret = 0;
|
||||
|
||||
if (type & FlagsMask)
|
||||
ret |= LocalDiskFlag;
|
||||
|
||||
QFileSystemMetaData::MetaDataFlags queryFlags =
|
||||
QFileSystemMetaData::MetaDataFlags(uint(type))
|
||||
& QFileSystemMetaData::Permissions;
|
||||
queryFlags |= QFileSystemMetaData::LinkType;
|
||||
|
||||
if (type & TypesMask)
|
||||
queryFlags |= QFileSystemMetaData::LinkType
|
||||
| QFileSystemMetaData::FileType
|
||||
| QFileSystemMetaData::DirectoryType;
|
||||
|
||||
if (type & FlagsMask)
|
||||
queryFlags |= QFileSystemMetaData::HiddenAttribute
|
||||
| QFileSystemMetaData::ExistsAttribute;
|
||||
|
||||
bool exists = d->doStat(queryFlags);
|
||||
|
||||
if (!exists && !d->metaData.isLink())
|
||||
return ret;
|
||||
|
||||
if (exists && (type & PermsMask))
|
||||
ret |= FileFlags(uint(d->metaData.permissions()));
|
||||
|
||||
if (type & TypesMask) {
|
||||
if ((type & LinkType) && d->metaData.isLink())
|
||||
ret |= LinkType;
|
||||
if (exists) {
|
||||
if (d->metaData.isFile()) {
|
||||
ret |= FileType;
|
||||
} else if (d->metaData.isDirectory()) {
|
||||
ret |= DirectoryType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type & FlagsMask) {
|
||||
if (exists)
|
||||
ret |= ExistsFlag;
|
||||
if (d->fileEntry.isRoot())
|
||||
ret |= RootFlag;
|
||||
else if (d->metaData.isHidden())
|
||||
ret |= HiddenFlag;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
QString QFSFileEngine::fileName(FileName file) const
|
||||
{
|
||||
Q_D(const QFSFileEngine);
|
||||
if (file == BaseName) {
|
||||
return d->fileEntry.fileName();
|
||||
} else if (file == PathName) {
|
||||
return d->fileEntry.path();
|
||||
} else if (file == AbsoluteName || file == AbsolutePathName) {
|
||||
QFileSystemEntry entry(QFileSystemEngine::absoluteName(d->fileEntry));
|
||||
if (file == AbsolutePathName) {
|
||||
return entry.path();
|
||||
}
|
||||
return entry.filePath();
|
||||
} else if (file == CanonicalName || file == CanonicalPathName) {
|
||||
QFileSystemEntry entry(QFileSystemEngine::canonicalName(d->fileEntry, d->metaData));
|
||||
if (file == CanonicalPathName)
|
||||
return entry.path();
|
||||
return entry.filePath();
|
||||
} else if (file == LinkName) {
|
||||
if (!d->metaData.hasFlags(QFileSystemMetaData::LinkType))
|
||||
QFileSystemEngine::fillMetaData(d->fileEntry, d->metaData, QFileSystemMetaData::LinkType);
|
||||
if (d->metaData.isLink()) {
|
||||
QFileSystemEntry entry = QFileSystemEngine::getLinkTarget(d->fileEntry, d->metaData);
|
||||
return entry.filePath();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
return d->fileEntry.filePath();
|
||||
}
|
||||
|
||||
bool QFSFileEngine::isRelativePath() const
|
||||
{
|
||||
Q_D(const QFSFileEngine);
|
||||
return d->fileEntry.filePath().length() ? d->fileEntry.filePath()[0] != QLatin1Char('/') : true;
|
||||
}
|
||||
|
||||
uint QFSFileEngine::ownerId(FileOwner own) const
|
||||
{
|
||||
Q_D(const QFSFileEngine);
|
||||
|
||||
if (d->doStat(QFileSystemMetaData::OwnerIds)) {
|
||||
if (own == QAbstractFileEngine::OwnerUser)
|
||||
return d->metaData.userId();
|
||||
return d->metaData.groupId();
|
||||
}
|
||||
|
||||
return QFileSystemMetaData::nobodyID;
|
||||
}
|
||||
|
||||
QString QFSFileEngine::owner(FileOwner own) const
|
||||
{
|
||||
if (own == QAbstractFileEngine::OwnerUser)
|
||||
return QFileSystemEngine::resolveUserName(ownerId(own));
|
||||
return QFileSystemEngine::resolveGroupName(ownerId(own));
|
||||
}
|
||||
|
||||
bool QFSFileEngine::setPermissions(uint perms)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
int error;
|
||||
if (!QFileSystemEngine::setPermissions(d->fileEntry, QFile::Permissions(perms), &error)) {
|
||||
setError(QFile::PermissionsError, qt_error_string(error));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QFSFileEngine::setSize(qint64 size)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
int ret = 0;
|
||||
if (d->fd != -1) {
|
||||
Q_EINTR_LOOP(ret, QT_FTRUNCATE(d->fd, size));
|
||||
} else {
|
||||
Q_EINTR_LOOP(ret, QT_TRUNCATE(d->fileEntry.nativeFilePath().constData(), size));
|
||||
}
|
||||
d->metaData.clearFlags(QFileSystemMetaData::SizeAttribute);
|
||||
if (ret == -1) {
|
||||
setError(QFile::ResizeError, qt_error_string(errno));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QDateTime QFSFileEngine::fileTime(FileTime time) const
|
||||
{
|
||||
Q_D(const QFSFileEngine);
|
||||
|
||||
if (d->doStat(QFileSystemMetaData::Times)) {
|
||||
switch (time) {
|
||||
case QAbstractFileEngine::ModificationTime:
|
||||
return d->metaData.modificationTime();
|
||||
case QAbstractFileEngine::AccessTime:
|
||||
return d->metaData.accessTime();
|
||||
case QAbstractFileEngine::CreationTime:
|
||||
return d->metaData.creationTime();
|
||||
}
|
||||
}
|
||||
|
||||
return QDateTime();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_NO_FSFILEENGINE
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include "qplatformdefs.h"
|
||||
#include "qfile_p.h"
|
||||
#include "qfsfileengine_p.h"
|
||||
#include "qabstractfileengine_p.h"
|
||||
#include "qfilesystemengine_p.h"
|
||||
#include "qcore_unix_p.h"
|
||||
#include "qcorecommon_p.h"
|
||||
|
@ -35,18 +35,18 @@
|
|||
QT_BEGIN_NAMESPACE
|
||||
|
||||
//************* QTemporaryFileEngine
|
||||
class QTemporaryFileEngine : public QFSFileEngine
|
||||
class QTemporaryFileEngine : public QAbstractFileEngine
|
||||
{
|
||||
Q_DECLARE_PRIVATE(QFSFileEngine)
|
||||
Q_DECLARE_PRIVATE(QAbstractFileEngine)
|
||||
public:
|
||||
QTemporaryFileEngine(const QString &file, bool fileIsTemplate = true)
|
||||
: QFSFileEngine(), filePathIsTemplate(fileIsTemplate)
|
||||
: QAbstractFileEngine(), filePathIsTemplate(fileIsTemplate)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
Q_D(QAbstractFileEngine);
|
||||
d->fileEntry = QFileSystemEntry(file);
|
||||
|
||||
if (!filePathIsTemplate)
|
||||
QFSFileEngine::setFileName(file);
|
||||
QAbstractFileEngine::setFileName(file);
|
||||
}
|
||||
|
||||
~QTemporaryFileEngine();
|
||||
|
@ -65,12 +65,12 @@ public:
|
|||
|
||||
QTemporaryFileEngine::~QTemporaryFileEngine()
|
||||
{
|
||||
QFSFileEngine::close();
|
||||
QAbstractFileEngine::close();
|
||||
}
|
||||
|
||||
bool QTemporaryFileEngine::isReallyOpen()
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
Q_D(QAbstractFileEngine);
|
||||
return (d->fd != -1);
|
||||
|
||||
}
|
||||
|
@ -78,26 +78,26 @@ bool QTemporaryFileEngine::isReallyOpen()
|
|||
void QTemporaryFileEngine::setFileName(const QString &file)
|
||||
{
|
||||
// Really close the file, so we don't leak
|
||||
QFSFileEngine::close();
|
||||
QFSFileEngine::setFileName(file);
|
||||
QAbstractFileEngine::close();
|
||||
QAbstractFileEngine::setFileName(file);
|
||||
}
|
||||
|
||||
void QTemporaryFileEngine::setFileTemplate(const QString &fileTemplate)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
Q_D(QAbstractFileEngine);
|
||||
if (filePathIsTemplate)
|
||||
d->fileEntry = QFileSystemEntry(fileTemplate);
|
||||
}
|
||||
|
||||
bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
Q_D(QAbstractFileEngine);
|
||||
Q_ASSERT(!isReallyOpen());
|
||||
|
||||
openMode |= QIODevice::ReadWrite;
|
||||
|
||||
if (!filePathIsTemplate)
|
||||
return QFSFileEngine::open(openMode);
|
||||
return QAbstractFileEngine::open(openMode);
|
||||
|
||||
QString qfilename = d->fileEntry.filePath();
|
||||
|
||||
|
@ -166,11 +166,11 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
|
|||
|
||||
bool QTemporaryFileEngine::remove()
|
||||
{
|
||||
Q_D(QFSFileEngine);
|
||||
Q_D(QAbstractFileEngine);
|
||||
// Since the QTemporaryFileEngine::close() does not really close the file,
|
||||
// we must explicitly call QFSFileEngine::close() before we remove it.
|
||||
QFSFileEngine::close();
|
||||
if (QFSFileEngine::remove()) {
|
||||
// we must explicitly call QAbstractFileEngine::close() before we remove it.
|
||||
QAbstractFileEngine::close();
|
||||
if (QAbstractFileEngine::remove()) {
|
||||
d->fileEntry.clear();
|
||||
return true;
|
||||
}
|
||||
|
@ -179,8 +179,8 @@ bool QTemporaryFileEngine::remove()
|
|||
|
||||
bool QTemporaryFileEngine::rename(const QString &newName)
|
||||
{
|
||||
QFSFileEngine::close();
|
||||
return QFSFileEngine::rename(newName);
|
||||
QAbstractFileEngine::close();
|
||||
return QAbstractFileEngine::rename(newName);
|
||||
}
|
||||
|
||||
bool QTemporaryFileEngine::close()
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
#include "qfileinfogatherer_p.h"
|
||||
#include "qdebug.h"
|
||||
#include "qfsfileengine.h"
|
||||
#include "qdiriterator.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
|
|
@ -58,13 +58,10 @@ set(BOOTSTRAP_SOURCES
|
|||
${CMAKE_SOURCE_DIR}/src/core/io/qfile.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/io/qfileinfo.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/io/qfilesystementry.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/io/qfsfileengine.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/io/qfsfileengine_iterator.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/io/qiodevice.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/io/qtextstream.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/io/qfilesystemengine_unix.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/io/qfilesystemiterator_unix.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/io/qfsfileengine_unix.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/kernel/qmetatype.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/tools/qbitarray.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/tools/qbytearray.cpp
|
||||
|
|
|
@ -190,7 +190,6 @@ static const struct ClassTblData {
|
|||
{ QLatin1String("QErrorMessage"), QLatin1String("QtGui/qerrormessage.h") },
|
||||
{ QLatin1String("QEvent"), QLatin1String("QtCore/qcoreevent.h") },
|
||||
{ QLatin1String("QEventLoop"), QLatin1String("QtCore/qeventloop.h") },
|
||||
{ QLatin1String("QFSFileEngine"), QLatin1String("QtCore/qfsfileengine.h") },
|
||||
{ QLatin1String("QFile"), QLatin1String("QtCore/qfile.h") },
|
||||
{ QLatin1String("QFileDialog"), QLatin1String("QtGui/qfiledialog.h") },
|
||||
{ QLatin1String("QFileIconProvider"), QLatin1String("QtGui/qfileiconprovider.h") },
|
||||
|
|
|
@ -452,7 +452,7 @@ void tst_QFile::open()
|
|||
}
|
||||
|
||||
if (filename.isEmpty())
|
||||
QTest::ignoreMessage(QtWarningMsg, "QFSFileEngine::open: No file name specified");
|
||||
QTest::ignoreMessage(QtWarningMsg, "QAbstractFileEngine::open: No file name specified");
|
||||
|
||||
if (ok) {
|
||||
QVERIFY2(f.open(QIODevice::OpenMode(mode)),
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
#include <QDebug>
|
||||
#include <QTemporaryFile>
|
||||
#include <QFSFileEngine>
|
||||
#include <QString>
|
||||
#include <QDirIterator>
|
||||
#include <qtest.h>
|
||||
|
@ -55,7 +54,6 @@ Q_OBJECT
|
|||
public:
|
||||
enum BenchmarkType {
|
||||
QFileBenchmark = 1,
|
||||
QFSFileEngineBenchmark,
|
||||
PosixBenchmark,
|
||||
QFileFromPosixBenchmark
|
||||
};
|
||||
|
@ -69,19 +67,15 @@ private slots:
|
|||
void seek();
|
||||
|
||||
void readSmallFiles_QFile();
|
||||
void readSmallFiles_QFSFileEngine();
|
||||
void readSmallFiles_posix();
|
||||
|
||||
void readSmallFiles_QFile_data();
|
||||
void readSmallFiles_QFSFileEngine_data();
|
||||
void readSmallFiles_posix_data();
|
||||
|
||||
void readBigFile_QFile_data();
|
||||
void readBigFile_QFSFileEngine_data();
|
||||
void readBigFile_posix_data();
|
||||
|
||||
void readBigFile_QFile();
|
||||
void readBigFile_QFSFileEngine();
|
||||
void readBigFile_posix();
|
||||
|
||||
void writeFileSequential_data();
|
||||
|
@ -151,7 +145,6 @@ void tst_qfile::cleanupTestCase()
|
|||
}
|
||||
|
||||
void tst_qfile::readBigFile_QFile() { readBigFile(); }
|
||||
void tst_qfile::readBigFile_QFSFileEngine() { readBigFile(); }
|
||||
void tst_qfile::readBigFile_posix()
|
||||
{
|
||||
readBigFile();
|
||||
|
@ -166,14 +159,6 @@ void tst_qfile::readBigFile_QFile_data()
|
|||
|
||||
}
|
||||
|
||||
void tst_qfile::readBigFile_QFSFileEngine_data()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
void tst_qfile::readBigFile_posix_data()
|
||||
{
|
||||
readBigFile_data(PosixBenchmark, QIODevice::NotOpen, QIODevice::NotOpen);
|
||||
|
@ -219,19 +204,8 @@ void tst_qfile::readBigFile()
|
|||
file.reset();
|
||||
}
|
||||
file.close();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case(QFSFileEngineBenchmark): {
|
||||
QFSFileEngine fse(filename);
|
||||
fse.open(QIODevice::ReadOnly|textMode|bufferedMode);
|
||||
QBENCHMARK {
|
||||
//qWarning() << fse.supportsExtension(QAbstractFileEngine::MapExtension);
|
||||
while(fse.read(buffer, blockSize));
|
||||
fse.seek(0);
|
||||
}
|
||||
fse.close();
|
||||
}
|
||||
break;
|
||||
case(PosixBenchmark): {
|
||||
QByteArray data = filename.toLocal8Bit();
|
||||
const char* cfilename = data.constData();
|
||||
|
@ -242,12 +216,12 @@ void tst_qfile::readBigFile()
|
|||
QT_FSEEK(cfile, 0, SEEK_SET);
|
||||
}
|
||||
::fclose(cfile);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case(QFileFromPosixBenchmark): {
|
||||
// No gain in benchmarking this case
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
removeFile();
|
||||
|
@ -258,7 +232,6 @@ void tst_qfile::seek_data()
|
|||
{
|
||||
QTest::addColumn<tst_qfile::BenchmarkType>("testType");
|
||||
QTest::newRow("QFile") << QFileBenchmark;
|
||||
QTest::newRow("QFSFileEngine") << QFSFileEngineBenchmark;
|
||||
QTest::newRow("Posix FILE*") << PosixBenchmark;
|
||||
}
|
||||
|
||||
|
@ -279,18 +252,8 @@ void tst_qfile::seek()
|
|||
file.seek(seekpos[i]);
|
||||
}
|
||||
file.close();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case(QFSFileEngineBenchmark): {
|
||||
QFSFileEngine fse(filename);
|
||||
fse.open(QIODevice::ReadOnly);
|
||||
QBENCHMARK {
|
||||
i=(i+1)%sp_size;
|
||||
fse.seek(seekpos[i]);
|
||||
}
|
||||
fse.close();
|
||||
}
|
||||
break;
|
||||
case(PosixBenchmark): {
|
||||
QByteArray data = filename.toLocal8Bit();
|
||||
const char* cfilename = data.constData();
|
||||
|
@ -300,12 +263,12 @@ void tst_qfile::seek()
|
|||
QT_FSEEK(cfile, seekpos[i], SEEK_SET);
|
||||
}
|
||||
::fclose(cfile);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case(QFileFromPosixBenchmark): {
|
||||
// No gain in benchmarking this case
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
removeFile();
|
||||
|
@ -315,7 +278,6 @@ void tst_qfile::open_data()
|
|||
{
|
||||
QTest::addColumn<tst_qfile::BenchmarkType>("testType");
|
||||
QTest::newRow("QFile") << QFileBenchmark;
|
||||
QTest::newRow("QFSFileEngine") << QFSFileEngineBenchmark;
|
||||
QTest::newRow("Posix FILE*") << PosixBenchmark;
|
||||
QTest::newRow("QFile from FILE*") << QFileFromPosixBenchmark;
|
||||
}
|
||||
|
@ -333,17 +295,8 @@ void tst_qfile::open()
|
|||
file.open( QIODevice::ReadOnly );
|
||||
file.close();
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case(QFSFileEngineBenchmark): {
|
||||
QBENCHMARK {
|
||||
QFSFileEngine fse(filename);
|
||||
fse.open(QIODevice::ReadOnly);
|
||||
fse.close();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case(PosixBenchmark): {
|
||||
// ensure we don't account toLocal8Bit()
|
||||
QByteArray data = filename.toLocal8Bit();
|
||||
|
@ -353,8 +306,8 @@ void tst_qfile::open()
|
|||
FILE* cfile = QT_FOPEN(cfilename, "rb");
|
||||
::fclose(cfile);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case(QFileFromPosixBenchmark): {
|
||||
// ensure we don't account toLocal8Bit()
|
||||
QByteArray data = filename.toLocal8Bit();
|
||||
|
@ -367,8 +320,8 @@ void tst_qfile::open()
|
|||
file.close();
|
||||
}
|
||||
::fclose(cfile);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
removeFile();
|
||||
|
@ -376,7 +329,6 @@ void tst_qfile::open()
|
|||
|
||||
|
||||
void tst_qfile::readSmallFiles_QFile() { readSmallFiles(); }
|
||||
void tst_qfile::readSmallFiles_QFSFileEngine() { readSmallFiles(); }
|
||||
void tst_qfile::readSmallFiles_posix()
|
||||
{
|
||||
readSmallFiles();
|
||||
|
@ -391,14 +343,6 @@ void tst_qfile::readSmallFiles_QFile_data()
|
|||
|
||||
}
|
||||
|
||||
void tst_qfile::readSmallFiles_QFSFileEngine_data()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
void tst_qfile::readSmallFiles_posix_data()
|
||||
{
|
||||
readSmallFiles_data(PosixBenchmark, QIODevice::NotOpen, QIODevice::NotOpen);
|
||||
|
@ -484,28 +428,8 @@ void tst_qfile::readSmallFiles()
|
|||
file->close();
|
||||
delete file;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case(QFSFileEngineBenchmark): {
|
||||
QList<QFSFileEngine*> fileList;
|
||||
Q_FOREACH(QString file, files) {
|
||||
QFSFileEngine *fse = new QFSFileEngine(tmpDirName + QLatin1Char('/') + file);
|
||||
fse->open(QIODevice::ReadOnly|textMode|bufferedMode);
|
||||
fileList.append(fse);
|
||||
}
|
||||
|
||||
QBENCHMARK {
|
||||
Q_FOREACH(QFSFileEngine *fse, fileList) {
|
||||
while (fse->read(buffer, blockSize));
|
||||
}
|
||||
}
|
||||
|
||||
Q_FOREACH(QFSFileEngine *fse, fileList) {
|
||||
fse->close();
|
||||
delete fse;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case(PosixBenchmark): {
|
||||
QList<FILE*> fileList;
|
||||
Q_FOREACH(QString file, files) {
|
||||
|
@ -523,12 +447,12 @@ void tst_qfile::readSmallFiles()
|
|||
Q_FOREACH(FILE* cfile, fileList) {
|
||||
::fclose(cfile);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case(QFileFromPosixBenchmark): {
|
||||
// No gain in benchmarking this case
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
removeSmallFiles();
|
||||
|
|
Loading…
Add table
Reference in a new issue