From 891122ea33f211e9fb71d50c39b08ffa1bf72a1d Mon Sep 17 00:00:00 2001 From: zhaoyingzhen Date: Tue, 3 Feb 2026 17:13:06 +0800 Subject: [PATCH] feat: dde-am resolve command to full path before execution When executing commands via dde-am, resolve relative command names to their full path using QStandardPaths::findExecutable. Log: dde-am resolve command to full path before execution Pms: BUG-349699 --- apps/dde-am/src/commandexecutor.cpp | 24 ++++++++++++++++++++++-- apps/dde-am/src/commandexecutor.h | 2 +- apps/dde-am/src/main.cpp | 4 +++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/apps/dde-am/src/commandexecutor.cpp b/apps/dde-am/src/commandexecutor.cpp index 47bd2ea1..f5bcbbe0 100644 --- a/apps/dde-am/src/commandexecutor.cpp +++ b/apps/dde-am/src/commandexecutor.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include DCORE_USE_NAMESPACE @@ -26,9 +28,27 @@ void registerComplexDbusType() } } -void CommandExecutor::setProgram(const QString &program) +bool CommandExecutor::setProgram(const QString &program) { - m_program = program; + if (program.isEmpty()) { + return false; + } + + // am requires the command to be a full path + if (!QDir::isAbsolutePath(program)) { + QString fullPath = QStandardPaths::findExecutable(program); + if (fullPath.isEmpty()) { + qWarning() << "Cannot find executable for command:" << program << ", skipping action invocation."; + return false; + } + + qDebug() << "Resolved command" << program << "to full path:" << fullPath; + m_program = fullPath; + } else { + m_program = program; + } + + return true; } void CommandExecutor::setArguments(const QStringList &arguments) diff --git a/apps/dde-am/src/commandexecutor.h b/apps/dde-am/src/commandexecutor.h index bc9ba1eb..f83da222 100644 --- a/apps/dde-am/src/commandexecutor.h +++ b/apps/dde-am/src/commandexecutor.h @@ -11,7 +11,7 @@ class CommandExecutor { public: - void setProgram(const QString &program); + bool setProgram(const QString &program); void setArguments(const QStringList &arguments); void setType(const QString &type); void setRunId(const QString &runId); diff --git a/apps/dde-am/src/main.cpp b/apps/dde-am/src/main.cpp index 6185358e..32f919c7 100644 --- a/apps/dde-am/src/main.cpp +++ b/apps/dde-am/src/main.cpp @@ -62,7 +62,9 @@ int handleExecuteCommand(const QCommandLineParser &parser, const QCommandLineOption &envOption) { CommandExecutor executor; - executor.setProgram(parser.value(executeOption)); + if (!executor.setProgram(parser.value(executeOption))) { + return -1; + } if (parser.isSet(typeOption)) { executor.setType(parser.value(typeOption));