From 2574ecd5a5f1242367f690b0b7c6c0bc674ab070 Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Thu, 29 Jul 2021 11:48:31 +0200 Subject: Fix isChildPathOf --- src/common/filesystembase.cpp | 13 ++++++------- src/common/filesystembase.h | 5 ++++- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src/common') diff --git a/src/common/filesystembase.cpp b/src/common/filesystembase.cpp index a4f99ccaa..b57b5d75e 100644 --- a/src/common/filesystembase.cpp +++ b/src/common/filesystembase.cpp @@ -535,15 +535,14 @@ QString FileSystem::pathtoUNC(const QString &_str) } #endif -bool FileSystem::isChildPathOf(QStringView child, QStringView parent) +bool FileSystem::isChildPathOf(const QString &child, const QString &parent) { - static const auto Casing = Utility::fsCasePreserving() ? Qt::CaseInsensitive : Qt::CaseSensitive; - // ignore additional / in the assert - Q_ASSERT(parent.startsWith(QFileInfo(parent.toString()).canonicalFilePath(), Casing)); - Q_ASSERT(child.startsWith(QFileInfo(child.toString()).canonicalFilePath(), Casing)); - return child.startsWith(parent, Casing); + // if it is a relative path assume a local file, resolve it based on root + const auto sensitivity = Utility::fsCaseSensitivity(); + return (child.startsWith(parent.endsWith(QLatin1Char('/')) ? parent : parent + QLatin1Char('/'), sensitivity) + // clear trailing slashes etc + || QString::compare(QDir::cleanPath(parent), QDir::cleanPath(child), sensitivity) == 0); } - } // namespace OCC #include "moc_filesystembase.cpp" diff --git a/src/common/filesystembase.h b/src/common/filesystembase.h index a7556240d..b4ace754c 100644 --- a/src/common/filesystembase.h +++ b/src/common/filesystembase.h @@ -164,7 +164,10 @@ namespace FileSystem { */ bool OCSYNC_EXPORT isJunction(const QString &filename); - bool OCSYNC_EXPORT isChildPathOf(QStringView child, QStringView parent); + /** + * Returns whether a Path is a child of another + */ + bool OCSYNC_EXPORT isChildPathOf(const QString &child, const QString &parent); } /** @} */ -- cgit v1.2.3