From 08734e2ea0920b08dc8fd2f729f78e693836b604 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 18 May 2020 15:54:19 +0200 Subject: [PATCH] Android: Simplify debug server upload Change-Id: Ib5fad98e71c29e3b28c9ba206fe20a38a75a471e Reviewed-by: David Schulz --- src/plugins/android/androidrunnerworker.cpp | 27 +++++++++------------ 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/plugins/android/androidrunnerworker.cpp b/src/plugins/android/androidrunnerworker.cpp index 28f7fd746f3..26b2840228f 100644 --- a/src/plugins/android/androidrunnerworker.cpp +++ b/src/plugins/android/androidrunnerworker.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -342,34 +343,30 @@ bool AndroidRunnerWorker::uploadDebugServer(const QString &debugServerFileName) // the files can't be pushed directly to package because of permissions. qCDebug(androidRunWorkerLog) << "Uploading GdbServer"; - bool foundUnique = true; - auto cleanUp = [this, &foundUnique] (QString *p) { - if (foundUnique && !runAdb({"shell", "rm", "-f", *p})) - qCDebug(androidRunWorkerLog) << "Gdbserver cleanup failed."; - delete p; - }; - std::unique_ptr - tempGdbServerPath(new QString("/data/local/tmp/%1"), cleanUp); - // Get a unique temp file name for gdb/lldbserver copy + const QString tempDebugServerPathTemplate = "/data/local/tmp/%1"; int count = 0; - while (deviceFileExists(tempGdbServerPath->arg(++count))) { + while (deviceFileExists(tempDebugServerPathTemplate.arg(++count))) { if (count > GdbTempFileMaxCounter) { qCDebug(androidRunWorkerLog) << "Can not get temporary file name"; - foundUnique = false; return false; } } - *tempGdbServerPath = tempGdbServerPath->arg(count); + + const QString tempDebugServerPath = tempDebugServerPathTemplate.arg(count); + auto cleanUp = qScopeGuard([this, tempDebugServerPath] { + if (!runAdb({"shell", "rm", "-f", tempDebugServerPath})) + qCDebug(androidRunWorkerLog) << "Debug server cleanup failed."; + }); // Copy gdbserver to temp location - if (!runAdb({"push", m_debugServerPath , *tempGdbServerPath})) { - qCDebug(androidRunWorkerLog) << "Gdbserver upload to temp directory failed"; + if (!runAdb({"push", m_debugServerPath , tempDebugServerPath})) { + qCDebug(androidRunWorkerLog) << "Debug server upload to temp directory failed"; return false; } // Copy gdbserver from temp location to app directory - if (!runAdb({"shell", "run-as", m_packageName, "cp" , *tempGdbServerPath, debugServerFileName})) { + if (!runAdb({"shell", "run-as", m_packageName, "cp" , tempDebugServerPath, debugServerFileName})) { qCDebug(androidRunWorkerLog) << "Debug server copy from temp directory failed"; return false; }