diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-03-15 01:00:11 +0100 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-03-15 01:00:11 +0100 |
commit | 8264e495fa9220c101a8a913701a0b8834a6d58b (patch) | |
tree | 069aa1d3efab926991c1edfc5b69a3d9e58dcfba /src/corelib/io/qdir.cpp | |
parent | 80f52812f2651e6d427bb3dd2e338b60fb25d48b (diff) | |
parent | 8eb3944dac81b8c51d7bac7784204d457551b50c (diff) |
Merge remote-tracking branch 'origin/5.11' into dev
Change-Id: I8b5a10d897a926078895ae41f48cdbd2474902b8
Diffstat (limited to 'src/corelib/io/qdir.cpp')
-rw-r--r-- | src/corelib/io/qdir.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index d043b3aea5..06eacf5455 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -750,13 +750,47 @@ QString QDir::filePath(const QString &fileName) const QString QDir::absoluteFilePath(const QString &fileName) const { const QDirPrivate* d = d_ptr.constData(); - if (isAbsolutePath(fileName)) + // Don't trust our own isAbsolutePath(); Q_OS_WIN needs a drive. + if (QFileSystemEntry(fileName).isAbsolute()) return fileName; d->resolveAbsoluteEntry(); const QString absoluteDirPath = d->absoluteDirEntry.filePath(); if (fileName.isEmpty()) return absoluteDirPath; +#ifdef Q_OS_WIN + // Handle the "absolute except for drive" case (i.e. \blah not c:\blah): + int size = absoluteDirPath.length(); + if ((fileName.startsWith(QLatin1Char('/')) + || fileName.startsWith(QLatin1Char('\\'))) + && size > 1) { + // Combine absoluteDirPath's drive with fileName + int drive = 2; // length of drive prefix + if (Q_UNLIKELY(absoluteDirPath.at(1).unicode() != ':')) { + // Presumably, absoluteDirPath is an UNC path; use its //server/share + // part as "drive" - it's as sane a thing as we can do. + for (int i = 2; i-- > 0; ) { // Scan two "path fragments": + while (drive < size && absoluteDirPath.at(drive).unicode() == '/') + drive++; + if (drive >= size) { + qWarning("Base directory starts with neither a drive nor a UNC share: %s", + qPrintable(QDir::toNativeSeparators(absoluteDirPath))); + return QString(); + } + while (drive < size && absoluteDirPath.at(drive).unicode() != '/') + drive++; + } + // We'll append fileName, which starts with a slash; so omit trailing slash: + if (absoluteDirPath.at(drive).unicode() == '/') + drive--; + } else if (!absoluteDirPath.at(0).isLetter()) { + qWarning("Base directory's drive is not a letter: %s", + qPrintable(QDir::toNativeSeparators(absoluteDirPath))); + return QString(); + } + return absoluteDirPath.leftRef(drive) % fileName; + } +#endif // Q_OS_WIN if (!absoluteDirPath.endsWith(QLatin1Char('/'))) return absoluteDirPath % QLatin1Char('/') % fileName; return absoluteDirPath % fileName; |