Utils: Move meta char policy handling from FilePath to ConsoleProcess

Currently the only place that's using it and the scope is much smaller.

Change-Id: I1a43d14f0e2c69a16f76e6f83b82436bbeeac1c9
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-07-23 12:39:05 +02:00
parent 8b72e92167
commit fa81f76237
6 changed files with 13 additions and 13 deletions

View File

@@ -63,6 +63,7 @@ public:
~ConsoleProcess() override; ~ConsoleProcess() override;
void setCommand(const Utils::CommandLine &command); void setCommand(const Utils::CommandLine &command);
void setAbortOnMetaChars(bool abort);
void setWorkingDirectory(const QString &dir); void setWorkingDirectory(const QString &dir);
QString workingDirectory() const; QString workingDirectory() const;

View File

@@ -60,6 +60,7 @@ struct ConsoleProcessPrivate {
QTemporaryFile *m_tempFile = nullptr; QTemporaryFile *m_tempFile = nullptr;
QProcess::ProcessError m_error = QProcess::UnknownError; QProcess::ProcessError m_error = QProcess::UnknownError;
QString m_errorString; QString m_errorString;
bool m_abortOnMetaChars = true;
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
QProcess m_process; QProcess m_process;

View File

@@ -65,6 +65,11 @@ void ConsoleProcess::setCommand(const Utils::CommandLine &command)
d->m_commandLine = command; d->m_commandLine = command;
} }
void ConsoleProcess::setAbortOnMetaChars(bool abort)
{
d->m_abortOnMetaChars = abort;
}
void ConsoleProcess::setSettings(QSettings *settings) void ConsoleProcess::setSettings(QSettings *settings)
{ {
d->m_settings = settings; d->m_settings = settings;
@@ -84,8 +89,8 @@ bool ConsoleProcess::start()
HostOsInfo::hostOs(), HostOsInfo::hostOs(),
&d->m_environment, &d->m_environment,
&d->m_workingDir, &d->m_workingDir,
d->m_commandLine.metaCharMode() d->m_abortOnMetaChars);
== CommandLine::MetaCharMode::Abort);
QString pcmd; QString pcmd;
if (perr == QtcProcess::SplitOk) { if (perr == QtcProcess::SplitOk) {
pcmd = d->m_commandLine.executable().toString(); pcmd = d->m_commandLine.executable().toString();

View File

@@ -86,9 +86,8 @@ CommandLine::CommandLine(const QString &exe, const QStringList &args)
: CommandLine(FilePath::fromString(exe), args) : CommandLine(FilePath::fromString(exe), args)
{} {}
CommandLine::CommandLine(const FilePath &exe, const QStringList &args, MetaCharMode metaCharMode) CommandLine::CommandLine(const FilePath &exe, const QStringList &args)
: m_executable(exe) : m_executable(exe)
, m_metaCharMode(metaCharMode)
{ {
addArgs(args); addArgs(args);
} }

View File

@@ -132,15 +132,12 @@ class QTCREATOR_UTILS_EXPORT CommandLine
{ {
public: public:
enum RawType { Raw }; enum RawType { Raw };
enum class MetaCharMode { Abort, Ignore };
CommandLine() {} CommandLine() {}
explicit CommandLine(const QString &executable); explicit CommandLine(const QString &executable);
explicit CommandLine(const FilePath &executable); explicit CommandLine(const FilePath &executable);
CommandLine(const QString &exe, const QStringList &args); CommandLine(const QString &exe, const QStringList &args);
CommandLine(const FilePath &exe, CommandLine(const FilePath &exe, const QStringList &args);
const QStringList &args,
MetaCharMode metaCharMode = MetaCharMode::Abort);
CommandLine(const FilePath &exe, const QString &unparsedArgs, RawType); CommandLine(const FilePath &exe, const QString &unparsedArgs, RawType);
void addArg(const QString &arg, OsType osType = HostOsInfo::hostOs()); void addArg(const QString &arg, OsType osType = HostOsInfo::hostOs());
@@ -152,13 +149,11 @@ public:
FilePath executable() const { return m_executable; } FilePath executable() const { return m_executable; }
QString arguments() const { return m_arguments; } QString arguments() const { return m_arguments; }
MetaCharMode metaCharMode() const { return m_metaCharMode; }
QStringList splitArguments(OsType osType = HostOsInfo::hostOs()) const; QStringList splitArguments(OsType osType = HostOsInfo::hostOs()) const;
private: private:
FilePath m_executable; FilePath m_executable;
QString m_arguments; QString m_arguments;
MetaCharMode m_metaCharMode;
}; };
class QTCREATOR_UTILS_EXPORT FileUtils { class QTCREATOR_UTILS_EXPORT FileUtils {

View File

@@ -201,9 +201,8 @@ void SshDeviceProcess::handleConnected()
this, &SshDeviceProcess::handleProcessStarted); this, &SshDeviceProcess::handleProcessStarted);
connect(&d->consoleProcess, &ConsoleProcess::stubStopped, connect(&d->consoleProcess, &ConsoleProcess::stubStopped,
this, [this] { handleProcessFinished(d->consoleProcess.errorString()); }); this, [this] { handleProcessFinished(d->consoleProcess.errorString()); });
d->consoleProcess.setCommand({FilePath::fromString(cmdLine.first()), d->consoleProcess.setAbortOnMetaChars(false);
cmdLine.mid(1), d->consoleProcess.setCommand({cmdLine.first(), cmdLine.mid(1)});
CommandLine::MetaCharMode::Ignore});
d->consoleProcess.start(); d->consoleProcess.start();
} else { } else {
connect(d->process.get(), &QSsh::SshRemoteProcess::started, connect(d->process.get(), &QSsh::SshRemoteProcess::started,