From b485890b1999950fbe0b53d2cb784b44636f7ac5 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 8 Sep 2021 12:23:23 +0200 Subject: [PATCH] Utils: Guard QFileInfo usages of non local FilePaths Helps keeping track of usages of potential wrong paths and partially makes sure to not leave the correct device. Change-Id: I19fff7ae8abc3fa6045f7d4459f1140ba71e4f16 Reviewed-by: hjk Reviewed-by: Qt CI Bot --- src/libs/utils/filepath.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index a14c44101fb..07544638a5c 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -438,6 +438,7 @@ FilePath FilePath::fromFileInfo(const QFileInfo &info) /// \returns a QFileInfo QFileInfo FilePath::toFileInfo() const { + QTC_ASSERT(!needsDevice(), return QFileInfo()); return QFileInfo(m_data); } @@ -831,6 +832,7 @@ FilePath FilePath::parentDir() const FilePath FilePath::absolutePath() const { + QTC_ASSERT(!needsDevice(), return *this); FilePath result = *this; result.m_data = QFileInfo(m_data).absolutePath(); return result; @@ -838,6 +840,7 @@ FilePath FilePath::absolutePath() const FilePath FilePath::absoluteFilePath() const { + QTC_ASSERT(!needsDevice(), return *this); FilePath result = *this; result.m_data = QFileInfo(m_data).absoluteFilePath(); return result; @@ -1056,6 +1059,7 @@ FilePath FilePath::relativeChildPath(const FilePath &parent) const /// FilePath FilePath::relativePath(const FilePath &anchor) const { + QTC_ASSERT(!needsDevice(), return *this); const QFileInfo fileInfo(m_data); QString absolutePath; QString filename;