Skip to content

Commit

Permalink
Unify QFSFileEngine implementations on Windows and Unix
Browse files Browse the repository at this point in the history
The functions for standard file system operations simply delegate to
the static functions in QFileSystemEngine, which are then implemented
separately for each platform. There is no need for the wrappers in
QFSFileEngine to be separately implemented as well.

The only noticeable difference between Unix and Windows versions was
the clearing of the meta data in QFSFileEngine::remove, which was only
done on Unix. This is now also done on Windows.

As a fly-by fix, correct the (internal only) documentation about case
sensitivity.

Change-Id: I274b34d5407fdfff2e0a2157bb5220607740a92a
Reviewed-by: Mårten Nordheim <[email protected]>
  • Loading branch information
vohi committed Oct 31, 2019
1 parent c3eb521 commit 5b20f58
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 175 deletions.
116 changes: 88 additions & 28 deletions src/corelib/io/qfsfileengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,14 +911,7 @@ bool QFSFileEngine::supportsExtension(Extension extension) const
}

/*! \fn bool QFSFileEngine::caseSensitive() const
Returns \c true for Windows, false for Unix.
*/

/*! \fn bool QFSFileEngine::copy(const QString &copyName)
For Windows or Apple platforms, copy the file to file \a copyName.
Not implemented for other Unix platforms.
Returns \c false for Windows, true for Unix.
*/

/*! \fn QString QFSFileEngine::currentPath(const QString &fileName)
Expand Down Expand Up @@ -950,11 +943,34 @@ bool QFSFileEngine::supportsExtension(Extension extension) const
\reimp
*/

/*! \fn QString QFSFileEngine::homePath()
/*!
Returns the home path of the current user.
\sa rootPath()
*/
QString QFSFileEngine::homePath()
{
return QFileSystemEngine::homePath();
}

/*!
Returns the root path.
\sa homePath()
*/
QString QFSFileEngine::rootPath()
{
return QFileSystemEngine::rootPath();
}

/*!
Returns the temporary path (i.e., a path in which it is safe
to store temporary files).
*/
QString QFSFileEngine::tempPath()
{
return QFileSystemEngine::tempPath();
}

/*! \fn bool QFSFileEngine::isRelativePath() const
\reimp
Expand All @@ -968,9 +984,6 @@ bool QFSFileEngine::supportsExtension(Extension extension) const
true if successful; otherwise returns \c false.
*/

/*! \fn bool QFSFileEngine::mkdir(const QString &name, bool createParentDirectories) const
\reimp
*/

/*! \fn uint QFSFileEngine::ownerId(QAbstractFileEngine::FileOwner own) const
In Unix, if stat() is successful, the \c uid is returned if
Expand All @@ -984,35 +997,87 @@ bool QFSFileEngine::supportsExtension(Extension extension) const
\reimp
*/

/*! \fn bool QFSFileEngine::remove()
\reimp
/*!
For Windows or Apple platforms, copy the file to file \a copyName.
Not implemented for other Unix platforms.
*/
bool QFSFileEngine::copy(const QString &copyName)
{
Q_D(QFSFileEngine);
QSystemError error;
bool ret = QFileSystemEngine::copyFile(d->fileEntry, QFileSystemEntry(copyName), error);
if (!ret)
setError(QFile::CopyError, error.toString());
return ret;
}

/*! \fn bool QFSFileEngine::rename(const QString &newName)
/*!
\reimp
*/
bool QFSFileEngine::remove()
{
Q_D(QFSFileEngine);
QSystemError error;
bool ret = QFileSystemEngine::removeFile(d->fileEntry, error);
d->metaData.clear();
if (!ret)
setError(QFile::RemoveError, error.toString());
return ret;
}


/*! \fn bool QFSFileEngine::renameOverwrite(const QString &newName)
/*!
\reimp
*/

/*! \fn bool QFSFileEngine::rmdir(const QString &name, bool recurseParentDirectories) const
bool QFSFileEngine::rename(const QString &newName)
{
Q_D(QFSFileEngine);
QSystemError error;
bool ret = QFileSystemEngine::renameFile(d->fileEntry, QFileSystemEntry(newName), error);
if (!ret)
setError(QFile::RenameError, error.toString());
return ret;
}
/*!
\reimp
*/
bool QFSFileEngine::renameOverwrite(const QString &newName)
{
Q_D(QFSFileEngine);
QSystemError error;
bool ret = QFileSystemEngine::renameOverwriteFile(d->fileEntry, QFileSystemEntry(newName), error);
if (!ret)
setError(QFile::RenameError, error.toString());
return ret;
}

/*! \fn QString QFSFileEngine::rootPath()
Returns the root path.
/*!
\reimp
*/
bool QFSFileEngine::mkdir(const QString &name, bool createParentDirectories) const
{
return QFileSystemEngine::createDirectory(QFileSystemEntry(name), createParentDirectories);
}

\sa homePath()
/*!
\reimp
*/
bool QFSFileEngine::rmdir(const QString &name, bool recurseParentDirectories) const
{
return QFileSystemEngine::removeDirectory(QFileSystemEntry(name), recurseParentDirectories);
}

/*! \fn bool QFSFileEngine::setCurrentPath(const QString &path)

/*!
Sets the current path (e.g., for QDir), to \a path. Returns \c true if the
new path exists; otherwise this function does nothing, and returns \c false.
\sa currentPath()
*/
bool QFSFileEngine::setCurrentPath(const QString &path)
{
return QFileSystemEngine::setCurrentPath(QFileSystemEntry(path));
}

/*! \fn bool QFSFileEngine::setPermissions(uint perms)
\reimp
Expand All @@ -1022,11 +1087,6 @@ bool QFSFileEngine::supportsExtension(Extension extension) const
\reimp
*/

/*! \fn QString QFSFileEngine::tempPath()
Returns the temporary path (i.e., a path in which it is safe
to store temporary files).
*/

/*! \fn QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions(QAbstractFileEngine::FileFlags type) const
\internal
*/
Expand Down
77 changes: 0 additions & 77 deletions src/corelib/io/qfsfileengine_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,54 +304,6 @@ bool QFSFileEnginePrivate::nativeIsSequential() const
return isSequentialFdFh();
}

bool QFSFileEngine::remove()
{
Q_D(QFSFileEngine);
QSystemError error;
bool ret = QFileSystemEngine::removeFile(d->fileEntry, error);
d->metaData.clear();
if (!ret) {
setError(QFile::RemoveError, error.toString());
}
return ret;
}

bool QFSFileEngine::copy(const QString &newName)
{
Q_D(QFSFileEngine);
QSystemError error;
bool ret = QFileSystemEngine::copyFile(d->fileEntry, QFileSystemEntry(newName), error);
if (!ret) {
setError(QFile::CopyError, error.toString());
}
return ret;
}

bool QFSFileEngine::renameOverwrite(const QString &newName)
{
Q_D(QFSFileEngine);
QSystemError error;
bool ret = QFileSystemEngine::renameOverwriteFile(d->fileEntry, QFileSystemEntry(newName), error);

if (!ret)
setError(QFile::RenameError, error.toString());

return ret;
}

bool QFSFileEngine::rename(const QString &newName)
{
Q_D(QFSFileEngine);
QSystemError error;
bool ret = QFileSystemEngine::renameFile(d->fileEntry, QFileSystemEntry(newName), error);

if (!ret) {
setError(QFile::RenameError, error.toString());
}

return ret;
}

bool QFSFileEngine::link(const QString &newName)
{
Q_D(QFSFileEngine);
Expand All @@ -368,45 +320,16 @@ qint64 QFSFileEnginePrivate::nativeSize() const
return sizeFdFh();
}

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::caseSensitive() const
{
return true;
}

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();
}

QFileInfoList QFSFileEngine::drives()
{
Expand Down
70 changes: 0 additions & 70 deletions src/corelib/io/qfsfileengine_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,66 +443,11 @@ bool QFSFileEnginePrivate::nativeIsSequential() const
#endif
}

bool QFSFileEngine::remove()
{
Q_D(QFSFileEngine);
QSystemError error;
bool ret = QFileSystemEngine::removeFile(d->fileEntry, error);
if (!ret)
setError(QFile::RemoveError, error.toString());
return ret;
}

bool QFSFileEngine::copy(const QString &copyName)
{
Q_D(QFSFileEngine);
QSystemError error;
bool ret = QFileSystemEngine::copyFile(d->fileEntry, QFileSystemEntry(copyName), error);
if (!ret)
setError(QFile::CopyError, error.toString());
return ret;
}

bool QFSFileEngine::rename(const QString &newName)
{
Q_D(QFSFileEngine);
QSystemError error;
bool ret = QFileSystemEngine::renameFile(d->fileEntry, QFileSystemEntry(newName), error);
if (!ret)
setError(QFile::RenameError, error.toString());
return ret;
}

bool QFSFileEngine::renameOverwrite(const QString &newName)
{
Q_D(QFSFileEngine);
QSystemError error;
bool ret = QFileSystemEngine::renameOverwriteFile(d->fileEntry, QFileSystemEntry(newName), error);
if (!ret)
setError(QFile::RenameError, error.toString());
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::caseSensitive() const
{
return false;
}

bool QFSFileEngine::setCurrentPath(const QString &path)
{
return QFileSystemEngine::setCurrentPath(QFileSystemEntry(path));
}

QString QFSFileEngine::currentPath(const QString &fileName)
{
#if !defined(Q_OS_WINRT)
Expand Down Expand Up @@ -530,21 +475,6 @@ QString QFSFileEngine::currentPath(const QString &fileName)
#endif // Q_OS_WINRT
}

QString QFSFileEngine::homePath()
{
return QFileSystemEngine::homePath();
}

QString QFSFileEngine::rootPath()
{
return QFileSystemEngine::rootPath();
}

QString QFSFileEngine::tempPath()
{
return QFileSystemEngine::tempPath();
}

#if !defined(Q_OS_WINRT)
// cf QStorageInfo::isReady
static inline bool isDriveReady(const wchar_t *path)
Expand Down

0 comments on commit 5b20f58

Please sign in to comment.