11#include <QtCore/qdebug.h>
13#ifndef QT_NO_FSFILEENGINE
17#include "private/qcore_unix_p.h"
21#if defined(Q_OS_DARWIN)
22# include <private/qcore_mac_p.h>
31# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
34# define S_ISCHR(x) (((x) & S_IFMT) == S_IFCHR)
37# define S_ISFIFO(x) false
40# define S_ISSOCK(x) false
42# ifndef INVALID_FILE_ATTRIBUTES
43# define INVALID_FILE_ATTRIBUTES (DWORD (-1))
55 "Unsupported: read/write return a type with different size as the len parameter");
102 fileHandle = INVALID_HANDLE_VALUE;
141 qWarning(
"NewOnly and ExistingOnly are mutually exclusive");
142 result.error =
"NewOnly and ExistingOnly are mutually exclusive"_L1;
147 qWarning(
"ExistingOnly must be specified alongside ReadOnly, WriteOnly, or ReadWrite");
149 "ExistingOnly must be specified alongside ReadOnly, WriteOnly, or ReadWrite"_L1;
162 result.openMode = openMode;
172 if (
d->closeFileHandle) {
175 }
else if (
d->fd != -1) {
196 std::optional<QFile::Permissions> permissions)
199 "QFSFileEngine no longer supports buffered mode; upper layer must buffer");
202 if (
d->fileEntry.isEmpty()) {
203 qWarning(
"QFSFileEngine::open: No file name specified");
214 d->openMode =
res.openMode;
215 d->lastFlushFailed =
false;
220 return d->nativeOpen(
d->openMode, permissions);
235 "QFSFileEngine no longer supports buffered mode; upper layer must buffer");
245 d->openMode =
res.openMode;
246 d->lastFlushFailed =
false;
248 d->fileEntry.clear();
252 return d->openFh(
d->openMode, fh);
261 "QFSFileEngine no longer supports buffered mode; upper layer must buffer");
271 ret = QT_FSEEK(
fh, 0, SEEK_END);
272 }
while (
ret != 0 && errno == EINTR);
307 d->openMode =
res.openMode;
308 d->lastFlushFailed =
false;
310 d->fileEntry.clear();
315 return d->openFd(
d->openMode,
fd);
333 ret = QT_LSEEK(
fd, 0, SEEK_END);
334 }
while (
ret == -1 && errno == EINTR);
357 return d->nativeClose();
394 if (!flushed || !closed) {
416 return d->nativeFlush();
427 return d->nativeSyncToDisk();
442 int ret = fflush(
fh);
461 return d->nativeSize();
469 if (!
maps.isEmpty()) {
471 for (
int i = 0;
i <
keys.size(); ++
i)
499 return d->nativePos();
509 return QT_LSEEK(
fd, 0, SEEK_CUR);
518 return d->nativeSeek(
pos);
534 return d->metaData.fileTime(
time);
560 ret = QT_FSEEK(
fh, QT_OFF_T(
pos), SEEK_SET);
561 }
while (
ret != 0 && errno == EINTR);
569 if (QT_LSEEK(
fd, QT_OFF_T(
pos), SEEK_SET) == -1) {
570 qWarning(
"QFile::at: Cannot set file position %lld",
pos);
584 return d->nativeHandle();
602 return d->nativeRead(
data, maxlen);
628 if (retry && eof &&
result == 0) {
632 QT_FSEEK(
fh, QT_FTELL(
fh), SEEK_SET);
637 }
while (!eof && (
result == 0 ? errno == EINTR : readBytes <
len));
639 }
else if (
fd != -1) {
648 UnsignedIOType chunkSize = std::numeric_limits<SignedIOType>::max();
649 if (chunkSize > wantedBytes)
650 chunkSize = wantedBytes;
657 if (!eof && readBytes == 0) {
680 return d->nativeReadLine(
data, maxlen);
690 return q->QAbstractFileEngine::readLine(
data, maxlen);
694 bool seq =
q->isSequential();
697 oldPos = QT_FTELL(
fh);
703 if (!fgets(
data,
int(maxlen + 1),
fh)) {
714 qint64 lineLength = QT_FTELL(
fh) - oldPos;
715 return lineLength > 0 ? lineLength :
qstrlen(
data);
758 result = fwrite(
data + writtenBytes, 1,
size_t(
len - writtenBytes),
fh);
760 }
while (
result == 0 ? errno == EINTR : writtenBytes <
len);
762 }
else if (
fd != -1) {
771 UnsignedIOType chunkSize = std::numeric_limits<SignedIOType>::max();
772 if (chunkSize > wantedBytes)
773 chunkSize = wantedBytes;
780 if (
len && writtenBytes == 0) {
791#ifndef QT_NO_FILESYSTEMITERATOR
823 if (
d->is_sequential == 0)
824 d->is_sequential =
d->nativeIsSequential() ? 1 : 2;
825 return d->is_sequential == 1;
853 return (returnValue->
address !=
nullptr);
1028 std::optional<QFile::Permissions> permissions)
const
The QAbstractFileEngineIterator class provides an iterator interface for custom file engines.
QFile::MemoryMapFlags flags
\inmodule QtCore \reentrant
FileTime
These are used by the fileTime() function.
void setError(QFile::FileError error, const QString &str)
Sets the error type to error, and the error string to errorString.
virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const
Requests that a list of all the files matching the filters list based on the filterNames in the file ...
QFile::FileError error() const
Returns the QFile::FileError that resulted from the last failed operation.
\inmodule QtCore\reentrant
qint64 readFdFh(char *data, qint64 maxlen)
bool openFd(QIODevice::OpenMode flags, int fd)
Opens the file descriptor fd to the file engine, using the open mode flags.
QHash< uchar *, StartAndLength > maps
qint64 writeFdFh(const char *data, qint64 len)
QIODevice::OpenMode openMode
bool doStat(QFileSystemMetaData::MetaDataFlags flags=QFileSystemMetaData::PosixStatFlags) const
QFileSystemMetaData metaData
bool isSequentialFdFh() const
qint64 readLineFdFh(char *data, qint64 maxlen)
bool openFh(QIODevice::OpenMode flags, FILE *fh)
Opens the file handle fh using the open mode flags.
LastIOCommand lastIOCommand
qint64 read(char *data, qint64 maxlen) override
\reimp
qint64 write(const char *data, qint64 len) override
\reimp
bool rmdir(const QString &dirName, bool recurseParentDirectories) const override
\reimp
bool rename(const QString &newName) override
\reimp
static QString tempPath()
Returns the temporary path (i.e., a path in which it is safe to store temporary files).
qint64 pos() const override
\reimp
bool renameOverwrite(const QString &newName) override
\reimp
bool close() override
\reimp
bool syncToDisk() override
\reimp
QFSFileEngine()
Constructs a QFSFileEngine.
qint64 size() const override
\reimp
static QString rootPath()
Returns the root path.
QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const override
QDateTime fileTime(FileTime time) const override
\reimp
bool isSequential() const override
\reimp
bool open(QIODevice::OpenMode openMode, std::optional< QFile::Permissions > permissions) override
\reimp
void setFileName(const QString &file) override
\reimp
bool seek(qint64) override
\reimp
static bool setCurrentPath(const QString &path)
Sets the current path (e.g., for QDir), to path.
bool mkdir(const QString &dirName, bool createParentDirectories, std::optional< QFile::Permissions > permissions) const override
\reimp
bool copy(const QString &newName) override
For Windows or Apple platforms, copy the file to file copyName.
bool supportsExtension(Extension extension) const override
\reimp
int handle() const override
\reimp
Iterator * endEntryList() override
bool extension(Extension extension, const ExtensionOption *option=nullptr, ExtensionReturn *output=nullptr) override
\reimp
qint64 readLine(char *data, qint64 maxlen) override
\reimp
static QString homePath()
Returns the home path of the current user.
bool remove() override
\reimp
Iterator * beginEntryList(QDir::Filters filters, const QStringList &filterNames) override
~QFSFileEngine()
Destructs the QFSFileEngine.
bool flush() override
\reimp
static bool setCurrentPath(const QFileSystemEntry &entry)
static bool copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
static bool renameOverwriteFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
static QString rootPath()
static bool createDirectory(const QFileSystemEntry &entry, bool createParents, std::optional< QFile::Permissions > permissions=std::nullopt)
static QString homePath()
static bool renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
static QString tempPath()
static bool removeFile(const QFileSystemEntry &entry, QSystemError &error)
static bool removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents)
\macro QT_RESTRICTED_CAST_FROM_ASCII
static Q_CORE_EXPORT QString stdString(int errorCode=-1)
Combined button and popup list for selecting options.
size_t qstrlen(const char *str)
#define INVALID_FILE_ATTRIBUTES
ProcessOpenModeResult processOpenModeFlags(QIODevice::OpenMode openMode)
Q_CORE_EXPORT ProcessOpenModeResult processOpenModeFlags(QIODevice::OpenMode mode)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q
GLsizei const GLchar *const * path
#define Q_ASSERT_X(cond, x, msg)
unsigned long long quint64
QT_BEGIN_NAMESPACE typedef uchar * output
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]