From f2df5c64bde5a3837048347b18c246e674de5caa Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 12 Jun 2017 15:31:53 +0200 Subject: QFileSystemEntry: Export static helper function checking for the root path This provides a helper function which does the check on the string. QFileInfo::isRoot() in addition checks for the existence of the directory, which can cause hangs with network drives. Use the new function in appropriate places in QtWidgets. Task-number: QTBUG-6039 Change-Id: I54d0d860713e82b28fa4069a5345b042337f9c52 Reviewed-by: Joerg Bornemann --- src/corelib/io/qfilesystementry.cpp | 30 ++++++++++++++++++++---------- src/corelib/io/qfilesystementry_p.h | 3 +++ 2 files changed, 23 insertions(+), 10 deletions(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qfilesystementry.cpp b/src/corelib/io/qfilesystementry.cpp index de4c852068..cbff17d0f1 100644 --- a/src/corelib/io/qfilesystementry.cpp +++ b/src/corelib/io/qfilesystementry.cpp @@ -297,23 +297,27 @@ bool QFileSystemEntry::isAbsolute() const bool QFileSystemEntry::isDriveRoot() const { resolveFilePath(); + return QFileSystemEntry::isDriveRootPath(m_filePath); +} + +bool QFileSystemEntry::isDriveRootPath(const QString &path) +{ #ifndef Q_OS_WINRT - return (m_filePath.length() == 3 - && m_filePath.at(0).isLetter() && m_filePath.at(1) == QLatin1Char(':') - && m_filePath.at(2) == QLatin1Char('/')); + return (path.length() == 3 + && path.at(0).isLetter() && path.at(1) == QLatin1Char(':') + && path.at(2) == QLatin1Char('/')); #else // !Q_OS_WINRT - return m_filePath == QDir::rootPath(); + return path == QDir::rootPath(); #endif // !Q_OS_WINRT } -#endif +#endif // Q_OS_WIN -bool QFileSystemEntry::isRoot() const +bool QFileSystemEntry::isRootPath(const QString &path) { - resolveFilePath(); - if (m_filePath == QLatin1String("/") + if (path == QLatin1String("/") #if defined(Q_OS_WIN) - || isDriveRoot() - || isUncRoot(m_filePath) + || isDriveRootPath(path) + || isUncRoot(path) #endif ) return true; @@ -321,6 +325,12 @@ bool QFileSystemEntry::isRoot() const return false; } +bool QFileSystemEntry::isRoot() const +{ + resolveFilePath(); + return isRootPath(m_filePath); +} + bool QFileSystemEntry::isEmpty() const { return m_filePath.isEmpty() && m_nativeFilePath.isEmpty(); diff --git a/src/corelib/io/qfilesystementry_p.h b/src/corelib/io/qfilesystementry_p.h index 300a375377..700696d09e 100644 --- a/src/corelib/io/qfilesystementry_p.h +++ b/src/corelib/io/qfilesystementry_p.h @@ -94,6 +94,7 @@ public: #if defined(Q_OS_WIN) bool isDriveRoot() const; + static bool isDriveRootPath(const QString &path); #endif bool isRoot() const; @@ -103,6 +104,8 @@ public: *this = QFileSystemEntry(); } + Q_CORE_EXPORT static bool isRootPath(const QString &path); + private: // creates the QString version out of the bytearray version void resolveFilePath() const; -- cgit v1.2.3