summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2018-11-05 16:55:08 +0100
committerJani Heikkinen <jani.heikkinen@qt.io>2019-01-13 18:18:10 +0000
commitdd5e7f1a52c51061ad54e870df7f8e04c0f06fbe (patch)
tree296fda800c780d1f2415f8fe15e66fe1ee37312f /src/corelib
parent69bd238ad86abfe725d90707f3b578f5d766ba3c (diff)
Use a more robust test for absolute paths in QDir
Its filePath() and absoluteFilePath() don't trust its own isAbsolute(), due to some infelicities on MS-Win; and kludged round a consequent problem with resource paths; but other virtual file systems weren't catered for. Replace the convoluted test there with a static bool function (so that future kludges in this area shall only need to edit one place; and can document why they're needed) and use a more robust test that handles all virtual file systems (by asking QFileInfo) but falls back to QFileSystemEntry to work round the known infelicities on MS-Win. Add regression test for asset library paths issue on iOS. Ammends 27f1f84c1c2. Moved a couple of local variables to after the early return, since it doesn't need them, in the process. Task-number: QTBUG-70237 Change-Id: Ib3954826df40ccf816beebe5c3751497e3bf6433 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/io/qdir.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index 4b63a38963..f7778943c9 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -748,6 +748,21 @@ static int drivePrefixLength(const QString &path)
}
#endif // Q_OS_WIN
+static bool treatAsAbsolute(const QString &path)
+{
+ // ### Qt 6: be consistent about absolute paths
+
+ // QFileInfo will use the right FS-engine for virtual file-systems
+ // (e.g. resource paths). Unfortunately, for real file-systems, it relies
+ // on QFileSystemEntry's isRelative(), which is flawed on MS-Win, ignoring
+ // its (correct) isAbsolute(). So only use that isAbsolute() unless there's
+ // a colon in the path.
+ // FIXME: relies on virtual file-systems having colons in their prefixes.
+ // The case of an MS-absolute C:/... path happens to work either way.
+ return (path.contains(QLatin1Char(':')) && QFileInfo(path).isAbsolute())
+ || QFileSystemEntry(path).isAbsolute();
+}
+
/*!
Returns the path name of a file in the directory. Does \e not
check if the file actually exists in the directory; but see
@@ -759,13 +774,10 @@ static int drivePrefixLength(const QString &path)
*/
QString QDir::filePath(const QString &fileName) const
{
- const QDirPrivate* d = d_ptr.constData();
- // Mistrust our own isAbsolutePath() for real files; Q_OS_WIN needs a drive.
- if (fileName.startsWith(QLatin1Char(':')) // i.e. resource path
- ? isAbsolutePath(fileName) : QFileSystemEntry(fileName).isAbsolute()) {
+ if (treatAsAbsolute(fileName))
return fileName;
- }
+ const QDirPrivate* d = d_ptr.constData();
QString ret = d->dirEntry.filePath();
if (fileName.isEmpty())
return ret;
@@ -793,13 +805,10 @@ QString QDir::filePath(const QString &fileName) const
*/
QString QDir::absoluteFilePath(const QString &fileName) const
{
- const QDirPrivate* d = d_ptr.constData();
- // Mistrust our own isAbsolutePath() for real files; Q_OS_WIN needs a drive.
- if (fileName.startsWith(QLatin1Char(':')) // i.e. resource path
- ? isAbsolutePath(fileName) : QFileSystemEntry(fileName).isAbsolute()) {
+ if (treatAsAbsolute(fileName))
return fileName;
- }
+ const QDirPrivate* d = d_ptr.constData();
d->resolveAbsoluteEntry();
const QString absoluteDirPath = d->absoluteDirEntry.filePath();
if (fileName.isEmpty())