5#include "qplatformdefs.h"
13#include "private/qiodevice_p.h"
14#include "private/qfile_p.h"
15#include "private/qfilesystemengine_p.h"
16#include "private/qsystemerror_p.h"
17#include "private/qtemporaryfile_p.h"
18#if defined(QT_BUILD_CORE_LIB)
23#define tr(X) QString::fromLatin1(X)
49#ifdef QT_NO_FSFILEENGINE
54 auto fs = std::make_unique<QFSFileEngine>();
64#ifdef QT_NO_FSFILEENGINE
69 auto fs = std::make_unique<QFSFileEngine>();
309 d->fileEngine.reset();
422 if (
d->fileName.isEmpty() &&
424 qWarning(
"QFile::remove: Empty or null file name");
430 if (
d->engine()->remove()) {
488 if (
d->fileName.isEmpty() &&
490 qWarning(
"QFile::remove: Empty or null file name");
560 qWarning(
"QFile::rename: Empty or null file name");
563 if (
d->fileName == newName) {
575 bool changingCase =
false;
579 d->fileEngine->id() :
587#if defined(Q_OS_LINUX) && QT_CONFIG(temporaryfile)
593 for (
int attempt = 0; attempt < 16; ++attempt) {
602 d->fileEngine->setFileName(newName);
603 d->fileName = newName;
614 tr(
"Error while renaming: %1").
arg(
error.toString())
616 +
tr(
"Unable to restore from %1: %2").
621 tr(
"Error while renaming: %1").
arg(
error.toString()));
628 if (changingCase ?
d->engine()->renameOverwrite(newName) :
d->engine()->rename(newName)) {
631 d->fileEngine->setFileName(newName);
632 d->fileName = newName;
647 while ((bytes =
read(block,
sizeof(block))) > 0) {
648 if (bytes !=
out.write(block, bytes)) {
667 d->fileEngine->setFileName(newName);
677 tr(
"Cannot open destination file: %1").
arg(
out.errorString()));
700 return QFile(oldName).rename(newName);
724 qWarning(
"QFile::link: Empty or null file name");
728 if (
d->engine()->link(fi.absoluteFilePath())) {
769 qWarning(
"QFile::copy: Empty or null file name");
782 if (
d->engine()->copy(newName)) {
791 const auto fileTemplate =
"%1/qt_temp.XXXXXX"_L1;
792#if !QT_CONFIG(temporaryfile)
809 if (!
d->engine()->cloneTo(
out.d_func()->engine())) {
817 if (
in !=
out.write(block,
in)) {
826 if (totalRead !=
size()) {
835 out.d_func()->fileEngine->syncToDisk();
837 if (!
out.rename(newName)) {
841 .
arg(newName,
out.errorString()));
844#if !QT_CONFIG(temporaryfile)
849 out.setAutoRemove(
false);
914 qWarning(
"QIODevice::open: File access not specified");
928 d->setError(err,
d->fileEngine->errorString());
959 qWarning(
"QIODevice::open: File access not specified");
973 d->setError(err,
d->fileEngine->errorString());
1029 qWarning(
"QFile::open: File access not specified");
1081 qWarning(
"QFile::open: File access not specified");
1379#ifndef QT_NO_QOBJECT
1380#include "moc_qfile.cpp"
\inmodule QtCore \reentrant
static std::unique_ptr< QAbstractFileEngine > create(const QString &fileName)
Creates and returns a QAbstractFileEngine suitable for processing fileName.
int compare(QByteArrayView a, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
bool isNull() const noexcept
Returns true if this byte array is null; otherwise returns false.
static QString tempPath()
Returns the absolute canonical path of the system's temporary directory.
static QString toNativeSeparators(const QString &pathName)
virtual bool isUnnamedFile() const
std::unique_ptr< QAbstractFileEngine > fileEngine
QFileDevice::FileHandleFlags handleFlags
qint64 pos() const override
\reimp
bool seek(qint64 offset) override
For random-access devices, this function sets the current position to pos, returning true on success,...
qint64 size() const override
Returns the size of the file.
void unsetError()
Sets the file's error to QFileDevice::NoError.
virtual bool resize(qint64 sz)
Sets the file size (in bytes) sz.
bool atEnd() const override
Returns true if the end of the file has been reached; otherwise returns false.
FileError error() const
Returns the file error status.
bool isSequential() const override
Returns true if the file can only be manipulated sequentially; otherwise returns false.
virtual QString fileName() const
Returns the name of the file.
FileError
This enum describes the errors that may be returned by the error() function.
virtual bool setPermissions(Permissions permissionSpec)
Sets the permissions for the file to the permissions specified.
void close() override
Calls QFileDevice::flush() and closes the file.
virtual Permissions permissions() const
Returns the complete OR-ed together combination of QFile::Permission for the file.
QString symLinkTarget() const
bool exists() const
Returns true if the file system entry this QFileInfo refers to exists; otherwise returns false.
QAbstractFileEngine * engine() const override
bool openExternalFile(QIODevice::OpenMode flags, int fd, QFile::FileHandleFlags handleFlags)
static QByteArray id(const QFileSystemEntry &entry)
static bool moveFileToTrash(const QFileSystemEntry &source, QFileSystemEntry &newLocation, QSystemError &error)
static bool renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
Q_AUTOTEST_EXPORT QString filePath() const
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
bool setPermissions(Permissions permissionSpec) override
Sets the permissions for the file to the permissions specified.
QFile()
Constructs a QFile object.
QString symLinkTarget() const
bool link(const QString &newName)
Creates a link named linkName that points to the file currently specified by fileName().
bool copy(const QString &newName)
Copies the file named fileName() to newName.
bool remove()
Removes the file specified by fileName().
void setFileName(const QString &name)
Sets the name of the file.
QString fileName() const override
Returns the name set by setFileName() or to the QFile constructors.
Permissions permissions() const override
\reimp
~QFile()
Destroys the file object, closing it if necessary.
bool rename(const QString &newName)
Renames the file currently specified by fileName() to newName.
friend class QTemporaryFile
bool exists() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
qint64 size() const override
\reimp
bool resize(qint64 sz) override
\reimp
virtual bool open(QIODeviceBase::OpenMode mode)
Opens the device and sets its OpenMode to mode.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
QString errorString() const
Returns a human-readable description of the last device error that occurred.
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success,...
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Combined button and popup list for selecting options.
#define Q_DECL_COLD_FUNCTION
static Q_DECL_COLD_FUNCTION bool file_already_open(QFile &file, const char *where=nullptr)
static QByteArray fileId(HANDLE handle)
GLsizei const GLchar *const * path
#define qUtf16Printable(string)
QTextStream out(stdout)
[7]