ShellCommand: Remove workingDir arg from 2 methods

Set a working directory for the process to run
before calling runFullySynchronous() or runSynchronous().
Make workDirectory() a private method.

Change-Id: I30f8354a3e409a06170f481cea4e97e3772da252
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2022-07-12 16:19:18 +02:00
parent 01e75d8b63
commit aebf6a9466
2 changed files with 11 additions and 15 deletions

View File

@@ -295,13 +295,15 @@ void ShellCommand::runCommand(QtcProcess &proc,
const CommandLine &command,
const FilePath &workingDirectory)
{
const FilePath dir = workDirectory(workingDirectory);
if (command.executable().isEmpty()) {
proc.setResult(ProcessResult::StartFailed);
return;
}
const FilePath dir = workDirectory(workingDirectory);
if (!dir.isEmpty())
proc.setWorkingDirectory(dir);
if (!(d->m_flags & SuppressCommandLogging))
emit appendCommand(dir, command);
@@ -309,9 +311,9 @@ void ShellCommand::runCommand(QtcProcess &proc,
if ((d->m_flags & FullySynchronously)
|| (!(d->m_flags & NoFullySync)
&& QThread::currentThread() == QCoreApplication::instance()->thread())) {
runFullySynchronous(proc, dir);
runFullySynchronous(proc);
} else {
runSynchronous(proc, dir);
runSynchronous(proc);
}
if (!d->m_aborted) {
@@ -326,14 +328,11 @@ void ShellCommand::runCommand(QtcProcess &proc,
postRunCommand(dir);
}
void ShellCommand::runFullySynchronous(QtcProcess &process, const FilePath &workingDirectory)
void ShellCommand::runFullySynchronous(QtcProcess &process)
{
// Set up process
if (d->m_disableUnixTerminal)
process.setDisableUnixTerminal();
const FilePath dir = workDirectory(workingDirectory);
if (!dir.isEmpty())
process.setWorkingDirectory(dir);
process.setEnvironment(environment());
if (d->m_flags & MergeOutputChannels)
process.setProcessChannelMode(QProcess::MergedChannels);
@@ -357,7 +356,7 @@ void ShellCommand::runFullySynchronous(QtcProcess &process, const FilePath &work
}
}
void ShellCommand::runSynchronous(QtcProcess &process, const FilePath &workingDirectory)
void ShellCommand::runSynchronous(QtcProcess &process)
{
connect(this, &ShellCommand::terminate, &process, [&process] {
process.stop();
@@ -368,9 +367,6 @@ void ShellCommand::runSynchronous(QtcProcess &process, const FilePath &workingDi
process.setCodec(d->m_codec);
if (d->m_disableUnixTerminal)
process.setDisableUnixTerminal();
const FilePath dir = workDirectory(workingDirectory);
if (!dir.isEmpty())
process.setWorkingDirectory(dir);
// connect stderr to the output window if desired
if (d->m_flags & MergeOutputChannels) {
process.setProcessChannelMode(QProcess::MergedChannels);