Android: Fix uploading file on Windows

Quoting of arguments on Windows behaves differently
depending on the used start() overload of QProcess.
Setting the program and arguments before calling start()
with only the QIODevice::OpenMode parameter allows to
preserve the wanted quoting.

Task-number: QTCREATORBUG-21547
Done-with: Oliver Wolff <oliver.wolff@qt.io>
Change-Id: I644ea0737d51d6114facb19a0ad70f10aeb79f2c
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Stenger
2018-11-20 15:19:32 +01:00
parent c76411a55e
commit 04b20a1a46
2 changed files with 8 additions and 2 deletions

View File

@@ -455,7 +455,11 @@ SynchronousProcessResponse SynchronousProcess::run(const QString &binary,
// executable cannot be found in the path. Do not start the // executable cannot be found in the path. Do not start the
// event loop in that case. // event loop in that case.
d->m_binary = binary; d->m_binary = binary;
d->m_process.start(binary, args, writeData.isEmpty() ? QIODevice::ReadOnly : QIODevice::ReadWrite); // using QProcess::start() and passing program, args and OpenMode results in a different
// quoting of arguments than using QProcess::setArguments() beforehand and calling start()
// only with the OpenMode
d->m_process.setProgram(binary);
d->m_process.setArguments(args);
connect(&d->m_process, &QProcess::started, this, [this, writeData] { connect(&d->m_process, &QProcess::started, this, [this, writeData] {
if (!writeData.isEmpty()) { if (!writeData.isEmpty()) {
int pos = 0; int pos = 0;
@@ -469,6 +473,8 @@ SynchronousProcessResponse SynchronousProcess::run(const QString &binary,
} }
d->m_process.closeWriteChannel(); d->m_process.closeWriteChannel();
}); });
d->m_process.start(writeData.isEmpty() ? QIODevice::ReadOnly : QIODevice::ReadWrite);
if (!d->m_startFailure) { if (!d->m_startFailure) {
d->m_timer.start(); d->m_timer.start();
if (isGuiThread()) if (isGuiThread())

View File

@@ -278,7 +278,7 @@ bool AndroidRunnerWorker::uploadFile(const QString &from, const QString &to, con
if (!f.open(QIODevice::ReadOnly)) if (!f.open(QIODevice::ReadOnly))
return false; return false;
runAdb({"shell", "run-as", m_packageName, "rm", to}); runAdb({"shell", "run-as", m_packageName, "rm", to});
auto res = runAdb({"shell", "run-as", m_packageName, "sh", "-c", QString("'cat > %1'").arg(to)}, 60, f.readAll()); auto res = runAdb({"shell", "run-as", m_packageName, QString("sh -c 'cat > %1'").arg(to)}, 60, f.readAll());
if (!res) if (!res)
return false; return false;
return runAdb({"shell", "run-as", m_packageName, "chmod", flags, to}); return runAdb({"shell", "run-as", m_packageName, "chmod", flags, to});