forked from qt-creator/qt-creator
Utils: Move 'isWindowsHost' test to startsWithDriveLetter callers
"Fixes" one Q_SKIP and makes the implementation OS-agnostic. FilePath::osType() actually depends on the host system for not fully qualified file paths, and that doesn't seem to be the right thing to do in all cases. The caller may actually have more context to decide whether this is needed (e.g. in pathchooser.cpp in the context of "return value from a GUI element, i.e. 'host' implied). Change-Id: Iff80c17094d2deec79d34d0527223fbcf8294935 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -1001,9 +1001,7 @@ bool FilePath::endsWith(const QString &s) const
|
|||||||
*/
|
*/
|
||||||
bool FilePath::startsWithDriveLetter() const
|
bool FilePath::startsWithDriveLetter() const
|
||||||
{
|
{
|
||||||
if (needsDevice() || !HostOsInfo::isWindowsHost())
|
return !needsDevice() && m_path.size() >= 2 && isWindowsDriveLetter(m_path[0]) && m_path.at(1) == ':';
|
||||||
return false;
|
|
||||||
return m_path.size() >= 2 && isWindowsDriveLetter(m_path[0]) && m_path.at(1) == ':';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@@ -636,7 +636,7 @@ QString DockerDevice::mapToDevicePath(const Utils::FilePath &globalPath) const
|
|||||||
// C:/dev/src -> /c/dev/src
|
// C:/dev/src -> /c/dev/src
|
||||||
const FilePath normalized = FilePath::fromString(globalPath.path()).normalizedPathName();
|
const FilePath normalized = FilePath::fromString(globalPath.path()).normalizedPathName();
|
||||||
QString path = normalized.path();
|
QString path = normalized.path();
|
||||||
if (normalized.startsWithDriveLetter()) {
|
if (HostOsInfo::isWindowsHost() && normalized.startsWithDriveLetter()) {
|
||||||
const QChar lowerDriveLetter = path.at(0).toLower();
|
const QChar lowerDriveLetter = path.at(0).toLower();
|
||||||
path = '/' + lowerDriveLetter + path.mid(2); // strip C:
|
path = '/' + lowerDriveLetter + path.mid(2); // strip C:
|
||||||
}
|
}
|
||||||
|
@@ -113,7 +113,7 @@ void BuildDirectoryAspect::addToLayout(LayoutBuilder &builder)
|
|||||||
|
|
||||||
FilePath BuildDirectoryAspect::fixupDir(const FilePath &dir)
|
FilePath BuildDirectoryAspect::fixupDir(const FilePath &dir)
|
||||||
{
|
{
|
||||||
if (!dir.startsWithDriveLetter())
|
if (HostOsInfo::isWindowsHost() && !dir.startsWithDriveLetter())
|
||||||
return {};
|
return {};
|
||||||
const QString dirString = dir.toString().toLower();
|
const QString dirString = dir.toString().toLower();
|
||||||
const QStringList drives = Utils::transform(QDir::drives(), [](const QFileInfo &fi) {
|
const QStringList drives = Utils::transform(QDir::drives(), [](const QFileInfo &fi) {
|
||||||
|
@@ -789,9 +789,6 @@ void tst_fileutils::asyncLocalCopy()
|
|||||||
|
|
||||||
void tst_fileutils::startsWithDriveLetter_data()
|
void tst_fileutils::startsWithDriveLetter_data()
|
||||||
{
|
{
|
||||||
if (!HostOsInfo::isWindowsHost())
|
|
||||||
QSKIP("This test is only relevant on Windows");
|
|
||||||
|
|
||||||
QTest::addColumn<FilePath>("path");
|
QTest::addColumn<FilePath>("path");
|
||||||
QTest::addColumn<bool>("expected");
|
QTest::addColumn<bool>("expected");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user