Utils: Introduce FilePath::normalizePathName()

... as wrapper around FileUtils::normalizePathName, and use it
in some places.

Change-Id: I42792e1f175b8119c8db930eae80a9f822ac70fa
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2021-08-20 13:04:02 +02:00
parent 04c1d29828
commit db014de91c
8 changed files with 20 additions and 11 deletions

View File

@@ -822,6 +822,14 @@ FilePath FilePath::absoluteFilePath(const FilePath &tail) const
return tail; return tail;
} }
FilePath FilePath::normalizePathName() const
{
FilePath result = *this;
if (!needsDevice()) // FIXME: Assumes no remote Windows and Mac for now.
result.m_data = FileUtils::normalizePathName(result.m_data);
return result;
}
/// Constructs a FilePath from \a filename /// Constructs a FilePath from \a filename
/// \a filename is not checked for validity. /// \a filename is not checked for validity.
FilePath FilePath::fromString(const QString &filepath) FilePath FilePath::fromString(const QString &filepath)

View File

@@ -120,6 +120,10 @@ public:
FilePath absoluteFilePath() const; FilePath absoluteFilePath() const;
FilePath absoluteFilePath(const FilePath &tail) const; FilePath absoluteFilePath(const FilePath &tail) const;
// makes sure that capitalization of directories is canonical
// on Windows and macOS. This is rarely needed.
FilePath normalizePathName() const;
bool operator==(const FilePath &other) const; bool operator==(const FilePath &other) const;
bool operator!=(const FilePath &other) const; bool operator!=(const FilePath &other) const;
bool operator<(const FilePath &other) const; bool operator<(const FilePath &other) const;

View File

@@ -913,8 +913,7 @@ DebuggerRunTool::DebuggerRunTool(RunControl *runControl, AllowTerminal allowTerm
m_runParameters.inferior = runnable(); m_runParameters.inferior = runnable();
// Normalize to work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch'...) // Normalize to work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch'...)
m_runParameters.inferior.workingDirectory = m_runParameters.inferior.workingDirectory = m_runParameters.inferior.workingDirectory.normalizePathName();
FilePath::fromString(FileUtils::normalizePathName(m_runParameters.inferior.workingDirectory.toString()));
setUseTerminal(allowTerminal == DoAllowTerminal && m_runParameters.useTerminal); setUseTerminal(allowTerminal == DoAllowTerminal && m_runParameters.useTerminal);
const QByteArray envBinary = qgetenv("QTC_DEBUGGER_PATH"); const QByteArray envBinary = qgetenv("QTC_DEBUGGER_PATH");

View File

@@ -255,7 +255,7 @@ void UnstartedAppWatcherDialog::startStopTimer(bool start)
void UnstartedAppWatcherDialog::findProcess() void UnstartedAppWatcherDialog::findProcess()
{ {
const QString &appName = Utils::FileUtils::normalizePathName(m_pathChooser->filePath().toString()); const QString &appName = m_pathChooser->filePath().normalizePathName().toString();
DeviceProcessItem fallback; DeviceProcessItem fallback;
foreach (const DeviceProcessItem &p, DeviceProcessList::localProcesses()) { foreach (const DeviceProcessItem &p, DeviceProcessList::localProcesses()) {
if (Utils::FileUtils::normalizePathName(p.exe) == appName) { if (Utils::FileUtils::normalizePathName(p.exe) == appName) {

View File

@@ -373,9 +373,9 @@ void ApplicationLauncherPrivate::start(const Runnable &runnable, const IDevice::
if (m_isLocal) { if (m_isLocal) {
// Work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch' ...) // Work around QTBUG-17529 (QtDeclarative fails with 'File name case mismatch' ...)
const QString fixedPath = FileUtils::normalizePathName(runnable.workingDirectory.toString()); const FilePath fixedPath = runnable.workingDirectory.normalizePathName();
m_guiProcess.setWorkingDirectory(fixedPath); m_guiProcess.setWorkingDirectory(fixedPath);
m_consoleProcess.setWorkingDirectory(FilePath::fromString(fixedPath)); m_consoleProcess.setWorkingDirectory(fixedPath);
Environment env = runnable.environment; Environment env = runnable.environment;
if (m_runAsRoot) if (m_runAsRoot)

View File

@@ -148,10 +148,8 @@ QmlProject::QmlProject(const Utils::FilePath &fileName)
QmlBuildSystem::QmlBuildSystem(Target *target) QmlBuildSystem::QmlBuildSystem(Target *target)
: BuildSystem(target) : BuildSystem(target)
{ {
const QString normalized m_canonicalProjectDir =
= Utils::FileUtils::normalizePathName(target->project() target->project()->projectFilePath().canonicalPath().normalizePathName().parentDir();
->projectFilePath().toFileInfo().canonicalFilePath());
m_canonicalProjectDir = Utils::FilePath::fromString(normalized).parentDir();
connect(target->project(), &Project::projectFileIsDirty, connect(target->project(), &Project::projectFileIsDirty,
this, &QmlBuildSystem::refreshProjectFile); this, &QmlBuildSystem::refreshProjectFile);

View File

@@ -449,7 +449,7 @@ void ExamplesListModel::parseTutorials(QXmlStreamReader *reader, const QString &
static QString resourcePath() static QString resourcePath()
{ {
// normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows // normalize paths so QML doesn't freak out if it's wrongly capitalized on Windows
return Utils::FileUtils::normalizePathName(Core::ICore::resourcePath().toString()); return Core::ICore::resourcePath().normalizePathName().toString();
} }
void ExamplesListModel::updateExamples() void ExamplesListModel::updateExamples()

View File

@@ -752,7 +752,7 @@ void MemcheckToolPrivate::heobAction()
} }
FilePath executable = sr.command.executable(); FilePath executable = sr.command.executable();
const QString workingDirectory = Utils::FileUtils::normalizePathName(sr.workingDirectory.toString()); const QString workingDirectory = sr.workingDirectory.normalizePathName().toString();
const QString commandLineArguments = sr.command.arguments(); const QString commandLineArguments = sr.command.arguments();
const QStringList envStrings = sr.environment.toStringList(); const QStringList envStrings = sr.environment.toStringList();