The function was already marked as internal.
By moving access to the underlying file engine to private API this
supports the effort to completely drop file engines from public API. In
the future, the goal is to completely drop the file-engine abstraction
as it exists today.
Change-Id: I332fa56e70c87e83c1e08bb9f75e04df7c93fec7
Reviewed-by: Jonas Gastal <jgastal@profusion.mobi>
Reviewed-by: Anselmo L. S. Melo <anselmo.melo@openbossa.org>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
+QAbstractFileEngine *QFilePrivate::engine() const
+{
+ if (!fileEngine)
+ fileEngine = QAbstractFileEngine::create(fileName);
+ return fileEngine;
+}
+
inline bool QFilePrivate::ensureFlushed() const
{
// This function ensures that the write buffer has been flushed (const
inline bool QFilePrivate::ensureFlushed() const
{
// This function ensures that the write buffer has been flushed (const
*/
QString QFile::fileName() const
{
*/
QString QFile::fileName() const
{
- return fileEngine()->fileName(QAbstractFileEngine::DefaultName);
+ Q_D(const QFile);
+ return d->engine()->fileName(QAbstractFileEngine::DefaultName);
bool
QFile::exists() const
{
bool
QFile::exists() const
{
// 0x1000000 = QAbstractFileEngine::Refresh, forcing an update
// 0x1000000 = QAbstractFileEngine::Refresh, forcing an update
- return (fileEngine()->fileFlags(QAbstractFileEngine::FlagsMask
+ return (d->engine()->fileFlags(QAbstractFileEngine::FlagsMask
| QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag);
}
| QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag);
}
QString
QFile::readLink() const
{
QString
QFile::readLink() const
{
- return fileEngine()->fileName(QAbstractFileEngine::LinkName);
+ Q_D(const QFile);
+ return d->engine()->fileName(QAbstractFileEngine::LinkName);
unsetError();
close();
if(error() == QFile::NoError) {
unsetError();
close();
if(error() == QFile::NoError) {
- if(fileEngine()->remove()) {
+ if (d->engine()->remove()) {
unsetError();
return true;
}
unsetError();
return true;
}
unsetError();
close();
if(error() == QFile::NoError) {
unsetError();
close();
if(error() == QFile::NoError) {
- if (fileEngine()->rename(newName)) {
+ if (d->engine()->rename(newName)) {
unsetError();
// engine was able to handle the new name so we just reset it
d->fileEngine->setFileName(newName);
unsetError();
// engine was able to handle the new name so we just reset it
d->fileEngine->setFileName(newName);
return false;
}
QFileInfo fi(linkName);
return false;
}
QFileInfo fi(linkName);
- if(fileEngine()->link(fi.absoluteFilePath())) {
+ if (d->engine()->link(fi.absoluteFilePath())) {
unsetError();
return true;
}
unsetError();
return true;
}
unsetError();
close();
if(error() == QFile::NoError) {
unsetError();
close();
if(error() == QFile::NoError) {
- if(fileEngine()->copy(newName)) {
+ if (d->engine()->copy(newName)) {
unsetError();
return true;
} else {
unsetError();
return true;
} else {
}
// QIODevice provides the buffering, so there's no need to request it from the file engine.
}
// QIODevice provides the buffering, so there's no need to request it from the file engine.
- if (fileEngine()->open(mode | QIODevice::Unbuffered)) {
+ if (d->engine()->open(mode | QIODevice::Unbuffered)) {
QIODevice::open(mode);
if (mode & Append)
seek(size());
QIODevice::open(mode);
if (mode & Append)
seek(size());
uchar *QFile::map(qint64 offset, qint64 size, MemoryMapFlags flags)
{
Q_D(QFile);
uchar *QFile::map(qint64 offset, qint64 size, MemoryMapFlags flags)
{
Q_D(QFile);
&& d->fileEngine->supportsExtension(QAbstractFileEngine::MapExtension)) {
unsetError();
uchar *address = d->fileEngine->map(offset, size, flags);
&& d->fileEngine->supportsExtension(QAbstractFileEngine::MapExtension)) {
unsetError();
uchar *address = d->fileEngine->map(offset, size, flags);
bool QFile::unmap(uchar *address)
{
Q_D(QFile);
bool QFile::unmap(uchar *address)
{
Q_D(QFile);
&& d->fileEngine->supportsExtension(QAbstractFileEngine::UnMapExtension)) {
unsetError();
bool success = d->fileEngine->unmap(address);
&& d->fileEngine->supportsExtension(QAbstractFileEngine::UnMapExtension)) {
unsetError();
bool success = d->fileEngine->unmap(address);
Q_D(QFile);
if (!d->ensureFlushed())
return false;
Q_D(QFile);
if (!d->ensureFlushed())
return false;
if (isOpen() && d->fileEngine->pos() > sz)
seek(sz);
if(d->fileEngine->setSize(sz)) {
if (isOpen() && d->fileEngine->pos() > sz)
seek(sz);
if(d->fileEngine->setSize(sz)) {
QFile::Permissions
QFile::permissions() const
{
QFile::Permissions
QFile::permissions() const
{
- QAbstractFileEngine::FileFlags perms = fileEngine()->fileFlags(QAbstractFileEngine::PermsMask) & QAbstractFileEngine::PermsMask;
+ Q_D(const QFile);
+ QAbstractFileEngine::FileFlags perms = d->engine()->fileFlags(QAbstractFileEngine::PermsMask) & QAbstractFileEngine::PermsMask;
return QFile::Permissions((int)perms); //ewww
}
return QFile::Permissions((int)perms); //ewww
}
QFile::setPermissions(Permissions permissions)
{
Q_D(QFile);
QFile::setPermissions(Permissions permissions)
{
Q_D(QFile);
- if(fileEngine()->setPermissions(permissions)) {
+ if (d->engine()->setPermissions(permissions)) {
unsetError();
return true;
}
unsetError();
return true;
}
Q_D(const QFile);
if (!d->ensureFlushed())
return 0;
Q_D(const QFile);
if (!d->ensureFlushed())
return 0;
- d->cachedSize = fileEngine()->size();
+ d->cachedSize = d->engine()->size();
- \internal
- Returns the QIOEngine for this QFile object.
-*/
-QAbstractFileEngine *QFile::fileEngine() const
-{
- Q_D(const QFile);
- if(!d->fileEngine)
- d->fileEngine = QAbstractFileEngine::create(d->fileName);
- return d->fileEngine;
-}
-
-/*!
Returns the file error status.
The I/O device status returns an error code. For example, if open()
Returns the file error status.
The I/O device status returns an error code. For example, if open()
-
-class QAbstractFileEngine;
class QFilePrivate;
class Q_CORE_EXPORT QFile : public QIODevice
class QFilePrivate;
class Q_CORE_EXPORT QFile : public QIODevice
uchar *map(qint64 offset, qint64 size, MemoryMapFlags flags = NoOptions);
bool unmap(uchar *address);
uchar *map(qint64 offset, qint64 size, MemoryMapFlags flags = NoOptions);
bool unmap(uchar *address);
- virtual QAbstractFileEngine *fileEngine() const;
-
protected:
#ifdef QT_NO_QOBJECT
QFile(QFilePrivate &dd);
protected:
#ifdef QT_NO_QOBJECT
QFile(QFilePrivate &dd);
qint64 readLineData(char *data, qint64 maxlen);
private:
qint64 readLineData(char *data, qint64 maxlen);
private:
+ friend class QTemporaryFile;
class QFilePrivate : public QIODevicePrivate
{
Q_DECLARE_PUBLIC(QFile)
class QFilePrivate : public QIODevicePrivate
{
Q_DECLARE_PUBLIC(QFile)
+ friend class QTemporaryFile;
protected:
QFilePrivate();
protected:
QFilePrivate();
bool openExternalFile(int flags, int fd, QFile::FileHandleFlags handleFlags);
bool openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handleFlags);
bool openExternalFile(int flags, int fd, QFile::FileHandleFlags handleFlags);
bool openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handleFlags);
+ virtual QAbstractFileEngine *engine() const;
+
QString fileName;
mutable QAbstractFileEngine *fileEngine;
QString fileName;
mutable QAbstractFileEngine *fileEngine;
QTemporaryFilePrivate();
~QTemporaryFilePrivate();
QTemporaryFilePrivate();
~QTemporaryFilePrivate();
+ QAbstractFileEngine *engine() const;
+
bool autoRemove;
QString templateName;
};
bool autoRemove;
QString templateName;
};
+QAbstractFileEngine *QTemporaryFilePrivate::engine() const
+{
+ if (!fileEngine) {
+ if (fileName.isEmpty())
+ fileEngine = new QTemporaryFileEngine(templateName);
+ else
+ fileEngine = new QTemporaryFileEngine(fileName, false);
+ }
+ return fileEngine;
+}
+
static QString defaultTemplateName()
{
QString baseName;
static QString defaultTemplateName()
{
QString baseName;
Q_D(const QTemporaryFile);
if(d->fileName.isEmpty())
return QString();
Q_D(const QTemporaryFile);
if(d->fileName.isEmpty())
return QString();
- return fileEngine()->fileName(QAbstractFileEngine::DefaultName);
+ return d->engine()->fileName(QAbstractFileEngine::DefaultName);
*/
QTemporaryFile *QTemporaryFile::createLocalFile(QFile &file)
{
*/
QTemporaryFile *QTemporaryFile::createLocalFile(QFile &file)
{
- if (QAbstractFileEngine *engine = file.fileEngine()) {
+ if (QAbstractFileEngine *engine = file.d_func()->engine()) {
if(engine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::LocalDiskFlag)
return 0; //local already
//cache
if(engine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::LocalDiskFlag)
return 0; //local already
//cache
- \internal
-*/
-
-QAbstractFileEngine *QTemporaryFile::fileEngine() const
-{
- Q_D(const QTemporaryFile);
- if(!d->fileEngine) {
- if (d->fileName.isEmpty())
- d->fileEngine = new QTemporaryFileEngine(d->templateName);
- else
- d->fileEngine = new QTemporaryFileEngine(d->fileName, false);
- }
- return d->fileEngine;
-}
-
-/*!
\reimp
Creates a unique file name for the temporary file, and opens it. You can
\reimp
Creates a unique file name for the temporary file, and opens it. You can
{
Q_D(QTemporaryFile);
if (!d->fileName.isEmpty()) {
{
Q_D(QTemporaryFile);
if (!d->fileName.isEmpty()) {
- if (static_cast<QTemporaryFileEngine*>(fileEngine())->isReallyOpen()) {
+ if (static_cast<QTemporaryFileEngine*>(d->engine())->isReallyOpen()) {
setOpenMode(flags);
return true;
}
setOpenMode(flags);
return true;
}
{ QFile file(fileName); return createLocalFile(file); }
static QTemporaryFile *createLocalFile(QFile &file);
{ QFile file(fileName); return createLocalFile(file); }
static QTemporaryFile *createLocalFile(QFile &file);
- virtual QAbstractFileEngine *fileEngine() const;
-
protected:
bool open(OpenMode flags);
protected:
bool open(OpenMode flags);