Unify QFSFileEngine implementations on Windows and Unix

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 <marten.nordheim@qt.io>
This commit is contained in:
Volker Hilsheimer 2019-10-30 14:17:32 +01:00
parent c3eb521a0f
commit 5b20f58c19
3 changed files with 88 additions and 175 deletions

View File

@ -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)
@ -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
@ -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
@ -984,35 +997,87 @@ bool QFSFileEngine::supportsExtension(Extension extension) const
\reimp
*/
/*! \fn bool QFSFileEngine::remove()
/*!
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;
}
/*!
\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::rename(const QString &newName)
/*!
\reimp
*/
/*! \fn bool QFSFileEngine::renameOverwrite(const QString &newName)
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 bool QFSFileEngine::rmdir(const QString &name, bool recurseParentDirectories) const
/*!
\reimp
*/
bool QFSFileEngine::mkdir(const QString &name, bool createParentDirectories) const
{
return QFileSystemEngine::createDirectory(QFileSystemEntry(name), createParentDirectories);
}
/*! \fn QString QFSFileEngine::rootPath()
Returns the root path.
\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
@ -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
*/

View File

@ -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);
@ -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()
{

View File

@ -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)
@ -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)