Utils: Make path cleaning platform agnostic

Unfortunately, QDir::cleanPath() only cleans according to the rules
of the host system, which can be wrong in remote setups.

As the implementation is not accessible/tweakable from the outside,
copy the relevant code and remove the platform #ifdef's.

Change-Id: Ife9a925412a12d3cef21ed3721a387c61c152ddf
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2022-07-14 15:04:44 +02:00
parent 712311b20c
commit dd585c601c
5 changed files with 256 additions and 31 deletions

View File

@@ -763,25 +763,6 @@ bool FileUtils::isRelativePath(const QString &path)
return isRelativePathHelper(path, HostOsInfo::hostOs());
}
// Cleans part after optional :// scheme separator, similar to QDir::cleanPath()
// - directory separators normalized (that is, platform-native
// separators converted to "/") and redundant ones removed, and "."s and ".."s
// resolved (as far as possible).
// Symbolic links are kept. This function does not return the
// canonical path, but rather the simplest version of the input.
// For example, "./local" becomes "local", "local/../bin" becomes
// "bin" and "/local/usr/../bin" becomes "/local/bin".
// FIXME: This should not use the host-platform dependent QDir::cleanPath()
QString doCleanPath(const QString &input)
{
const int pos = input.indexOf("://");
if (pos == -1)
return QDir::cleanPath(input);
return input.left(pos + 3) + QDir::cleanPath(input.mid(pos + 3));
}
FilePath FileUtils::commonPath(const FilePath &oldCommonPath, const FilePath &filePath)
{
FilePath newCommonPath = oldCommonPath;