Skip to content

Commit 891122e

Browse files
committed
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
1 parent cea239a commit 891122e

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

apps/dde-am/src/commandexecutor.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <QDBusConnection>
99
#include <QDBusMetaType>
1010
#include <QDBusMessage>
11+
#include <QDir>
12+
#include <QStandardPaths>
1113

1214
DCORE_USE_NAMESPACE
1315

@@ -26,9 +28,27 @@ void registerComplexDbusType()
2628
}
2729
}
2830

29-
void CommandExecutor::setProgram(const QString &program)
31+
bool CommandExecutor::setProgram(const QString &program)
3032
{
31-
m_program = program;
33+
if (program.isEmpty()) {
34+
return false;
35+
}
36+
37+
// am requires the command to be a full path
38+
if (!QDir::isAbsolutePath(program)) {
39+
QString fullPath = QStandardPaths::findExecutable(program);
40+
if (fullPath.isEmpty()) {
41+
qWarning() << "Cannot find executable for command:" << program << ", skipping action invocation.";
42+
return false;
43+
}
44+
45+
qDebug() << "Resolved command" << program << "to full path:" << fullPath;
46+
m_program = fullPath;
47+
} else {
48+
m_program = program;
49+
}
50+
51+
return true;
3252
}
3353

3454
void CommandExecutor::setArguments(const QStringList &arguments)

apps/dde-am/src/commandexecutor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class CommandExecutor
1212
{
1313
public:
14-
void setProgram(const QString &program);
14+
bool setProgram(const QString &program);
1515
void setArguments(const QStringList &arguments);
1616
void setType(const QString &type);
1717
void setRunId(const QString &runId);

apps/dde-am/src/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ int handleExecuteCommand(const QCommandLineParser &parser,
6262
const QCommandLineOption &envOption)
6363
{
6464
CommandExecutor executor;
65-
executor.setProgram(parser.value(executeOption));
65+
if (!executor.setProgram(parser.value(executeOption))) {
66+
return -1;
67+
}
6668

6769
if (parser.isSet(typeOption)) {
6870
executor.setType(parser.value(typeOption));

0 commit comments

Comments
 (0)