Compare commits

...

5 Commits

Author SHA1 Message Date
8ca6a6d5a8 chore: release dde-application-manager 1.2.16.2
Some checks failed
backup to gitlab / backup-to-gitlabwh (push) Has been cancelled
backup to gitlab / backup-to-gitee (push) Has been cancelled
Call build-distribution / check_job (push) Has been cancelled
Log:
2025-04-10 13:35:19 +08:00
ComixHe
74d95e8240 fix: correct the ordering of application args
Signed-off-by: ComixHe <heyuming@deepin.org>
2025-04-10 13:32:24 +08:00
ComixHe
1c4ae3f700 fix: processing all input files lazily
Signed-off-by: ComixHe <heyuming@deepin.org>
2025-04-10 13:32:06 +08:00
3345c0c023 chore: release dde-application-manager 1.2.16.1
Log:
2025-04-09 18:26:44 +08:00
ComixHe
0b0c75849c refactor: reimplement unescapeExec
adjusted patch from master branch (originally 2f0f34a44fb)

Signed-off-by: ComixHe <heyuming@deepin.org>
2025-04-09 18:23:22 +08:00
4 changed files with 250 additions and 159 deletions

15
debian/changelog vendored
View File

@ -1,3 +1,18 @@
dde-application-manager (1.2.16.2) unstable; urgency=medium
* release 1.2.16.2
* fix: processing all input files lazily
* fix: correct the ordering of application args
-- Gary Wang <wangzichong@deepin.org> Thu, 10 Apr 2025 13:34:00 +0800
dde-application-manager (1.2.16.1) unstable; urgency=medium
* release 1.2.16.1
* fix unable to process Exec keys with %% escaping
-- Gary Wang <wangzichong@deepin.org> Wed, 09 Apr 2025 18:26:00 +0800
dde-application-manager (1.2.16) unstable; urgency=medium dde-application-manager (1.2.16) unstable; urgency=medium
* release 1.2.16 * release 1.2.16

View File

@ -250,8 +250,8 @@ ApplicationService::Launch(const QString &action, const QStringList &fields, con
execStr = toString(actionExec.value()); execStr = toString(actionExec.value());
if (execStr.isEmpty()) { if (execStr.isEmpty()) {
qWarning() << "exec value to string failed, try default action."; // we need this log. qWarning() << "exec value to string failed, try default action."; // we need this log.
break;
} }
break; break;
} }
@ -286,8 +286,7 @@ ApplicationService::Launch(const QString &action, const QStringList &fields, con
return {}; return {};
} }
auto [bin, execCmds, res] = std::move(task); if (task.LaunchBin.isEmpty()) {
if (bin.isEmpty()) {
qCritical() << "error command is detected, abort."; qCritical() << "error command is detected, abort.";
safe_sendErrorReply(QDBusError::Failed); safe_sendErrorReply(QDBusError::Failed);
return {}; return {};
@ -295,55 +294,60 @@ ApplicationService::Launch(const QString &action, const QStringList &fields, con
if (terminal()) { if (terminal()) {
// don't change this sequence // don't change this sequence
execCmds.push_front("-e"); // run all original execution commands in deepin-terminal cmds.push_back("deepin-terminal");
execCmds.push_front("--keep-open"); // keep terminal open, prevent exit immediately cmds.push_back("--keep-open"); // keep terminal open, prevent exit immediately
execCmds.push_front("deepin-terminal"); cmds.push_back("-e"); // run all original execution commands in deepin-terminal
} }
cmds.append(std::move(execCmds));
auto &jobManager = parent()->jobManager(); auto &jobManager = parent()->jobManager();
return jobManager.addJob( return jobManager.addJob(
m_applicationPath.path(), m_applicationPath.path(),
[this, binary = std::move(bin), commands = std::move(cmds)](const QVariant &variantValue) -> QVariant { [this, task, cmds = std::move(cmds)](const QVariant &value) -> QVariant { // do not change it to mutable lambda
auto resourceFile = variantValue.toString();
auto instanceRandomUUID = QUuid::createUuid().toString(QUuid::Id128); auto instanceRandomUUID = QUuid::createUuid().toString(QUuid::Id128);
auto objectPath = m_applicationPath.path() + "/" + instanceRandomUUID; auto objectPath = m_applicationPath.path() + "/" + instanceRandomUUID;
auto newCommands = commands; auto newCommands = cmds;
newCommands.push_front(QString{"--SourcePath=%1"}.arg(m_desktopSource.sourcePath())); if (value.isNull()) {
auto location = newCommands.indexOf(R"(%f)"); newCommands.push_front(QString{"--SourcePath=%1"}.arg(m_desktopSource.sourcePath()));
if (location != -1) { // due to std::move, there only remove once
newCommands.remove(location);
}
if (resourceFile.isEmpty()) {
newCommands.push_front(QString{R"(--unitName=app-DDE-%1@%2.service)"}.arg( newCommands.push_front(QString{R"(--unitName=app-DDE-%1@%2.service)"}.arg(
escapeApplicationId(this->id()), instanceRandomUUID)); // launcher should use this instanceId escapeApplicationId(this->id()), instanceRandomUUID)); // launcher should use this instanceId
newCommands.append(task.command);
QProcess process; QProcess process;
qDebug() << "run with commands:" << newCommands; qDebug() << "launcher :" << m_launcher << "run with commands:" << newCommands;
process.start(m_launcher, newCommands); process.start(m_launcher, newCommands);
process.waitForFinished(); process.waitForFinished();
if (auto code = process.exitCode(); code != 0) { if (auto code = process.exitCode(); code != 0) {
qWarning() << "Launch Application Failed"; qWarning() << "Launch Application Failed";
return QDBusError::Failed; return QDBusError::Failed;
} }
return objectPath; return objectPath;
} }
auto url = QUrl::fromUserInput(resourceFile); auto rawRes = value.toString();
if (!url.isValid()) { // if url is invalid, passing to launcher directly if (task.argNum != -1) {
auto scheme = url.scheme(); if (task.argNum >= newCommands.size()) {
if (!scheme.isEmpty()) { qCritical() << "task.argNum >= task.command.size()";
// TODO: resourceFile = processRemoteFile(resourceFile); return QDBusError::Failed;
} }
auto tmp = task.command;
if (task.fieldLocation == -1) {
tmp.insert(task.argNum + 1, rawRes);
} else {
auto arg = tmp.at(task.argNum);
arg.insert(task.fieldLocation, rawRes);
tmp[task.argNum] = arg;
}
newCommands.append(std::move(tmp));
} }
newCommands.push_front(QString{"--SourcePath=%1"}.arg(m_desktopSource.sourcePath()));
// NOTE: resourceFile must be available in the following contexts
newCommands.insert(location, resourceFile);
newCommands.push_front(QString{R"(--unitName=DDE-%1@%2.service)"}.arg(this->id(), instanceRandomUUID)); newCommands.push_front(QString{R"(--unitName=DDE-%1@%2.service)"}.arg(this->id(), instanceRandomUUID));
QProcess process; QProcess process;
qDebug() << "run with commands:" << newCommands; qDebug().noquote() << "launcher :" << m_launcher << "run with commands:" << newCommands;
process.start(getApplicationLauncherBinary(), newCommands); process.start(getApplicationLauncherBinary(), newCommands);
process.waitForFinished(); process.waitForFinished();
auto exitCode = process.exitCode(); auto exitCode = process.exitCode();
@ -351,9 +355,10 @@ ApplicationService::Launch(const QString &action, const QStringList &fields, con
qWarning() << "Launch Application Failed"; qWarning() << "Launch Application Failed";
return QDBusError::Failed; return QDBusError::Failed;
} }
return objectPath; return objectPath;
}, },
std::move(res)); std::move(task.Resources));
} }
bool ApplicationService::SendToDesktop() const noexcept bool ApplicationService::SendToDesktop() const noexcept
@ -957,162 +962,227 @@ std::optional<QStringList> ApplicationService::unescapeExecArgs(const QString &s
return execList; return execList;
} }
LaunchTask ApplicationService::unescapeExec(const QString &str, const QStringList &fields) noexcept LaunchTask ApplicationService::unescapeExec(const QString &str, QStringList fields) noexcept
{ {
LaunchTask task; LaunchTask task;
auto opt = unescapeExecArgs(str); auto args = unescapeExecArgs(str);
if (!opt.has_value()) { if (!args) {
qWarning() << "unescapeExecArgs failed."; qWarning() << "unescapeExecArgs failed.";
return {}; return {};
} }
auto execList = std::move(opt).value(); if (args->isEmpty()) {
if (execList.isEmpty()) {
qWarning() << "exec format is invalid."; qWarning() << "exec format is invalid.";
return {}; return {};
} }
task.LaunchBin = execList.first(); auto processUrl = [](const QString &str) {
QRegularExpression re{"%[fFuUickdDnNvm]"}; auto url = QUrl::fromUserInput(str);
auto matcher = re.match(str); if (!url.isValid()) {
if (!matcher.hasMatch()) { qDebug() << "url is invalid, pass to exec directly.";
task.command.append(std::move(execList)); return str;
task.Resources.emplace_back(QString{""}); // mapReduce should run once at least }
return task;
}
auto list = matcher.capturedTexts(); if (url.isLocalFile()) {
if (list.count() != 1) { return url.toLocalFile();
qWarning() << "invalid exec format, all filed code will be ignored.";
for (const auto &code : list) {
execList.removeOne(code);
} }
task.command.append(std::move(execList));
return task;
}
auto filesCode = list.first().back().toLatin1(); return url.toString();
auto codeStr = QString(R"(%%1)").arg(filesCode); };
auto location = execList.indexOf(codeStr);
if (location == -1) {
qWarning() << "invalid exec format, all filed code will be ignored.";
return {};
}
switch (filesCode) { task.LaunchBin = args->first();
case 'f': { // Defer to async job const QChar percentage{'%'};
task.command.append(std::move(execList)); bool exclusiveField{false};
for (const auto &field : fields) {
task.Resources.emplace_back(field); for (auto arg = args->begin(); arg != args->end(); ++arg) {
} QString newArg;
} break;
case 'u': { for (const auto *it = arg->cbegin(); it != arg->cend();) {
execList.removeAt(location); if (*it != percentage) {
if (fields.empty()) { newArg.append(*(it++));
task.command.append(execList); continue;
break;
}
if (fields.count() > 1) {
qDebug() << R"(fields count is greater than one, %u will only take first element.)";
}
execList.insert(location, fields.first());
task.command.append(execList);
} break;
case 'F': {
execList.remove(location);
auto it = execList.begin() + location;
for (const auto &field : fields) {
auto tmp = QUrl::fromUserInput(field);
if (auto scheme = tmp.scheme(); scheme.startsWith("file") or scheme.isEmpty()) {
it = execList.insert(it, tmp.toLocalFile());
} else {
qWarning() << "shouldn't replace %F with an URL:" << field;
it = execList.insert(it, field);
} }
++it;
} const auto *code = it + 1;
task.command.append(std::move(execList)); if (code == arg->cend()) {
} break; qWarning() << R"(content of exec is invalid, a unterminated % is detected.)";
case 'U': { return {};
execList.removeAt(location); }
auto it = execList.begin() + location;
for (const auto &field : fields) { if (*code == percentage) {
it = execList.insert(it, field); newArg.append(percentage);
++it; it += 2;
} continue;
task.command.append(std::move(execList)); }
} break;
case 'i': { switch (auto c = code->toLatin1(); c) {
execList.removeAt(location); case 'f':
auto val = m_entry->value(DesktopFileEntryKey, "Icon"); [[fallthrough]];
if (!val) { case 'F': { // Defer to async job
qDebug() << R"(Application Icons can't be found. %i will be ignored.)"; if (exclusiveField) {
task.command.append(std::move(execList)); qDebug() << QString{"exclusive field is detected again, %%1 will be ignored."}.arg(c);
return task; break;
}
exclusiveField = true;
if (fields.empty()) {
qDebug() << QString{"fields is empty, %%1 will be ignored."}.arg(c);
break;
}
if (c == 'F') {
task.Resources.emplace_back(fields.join(' '));
} else {
std::for_each(
fields.begin(), fields.end(), [&task](QString &str) { task.Resources.emplace_back(std::move(str)); });
}
task.argNum = std::distance(args->begin(), arg) - 1;
task.fieldLocation = std::distance(arg->cbegin(), it) - 1;
} break;
case 'u':
case 'U': {
if (exclusiveField) {
qDebug() << QString{"exclusive field is detected again, %%1 will be ignored."}.arg(c);
break;
}
exclusiveField = true;
if (fields.empty()) {
qDebug() << QString{"fields is empty, %%1 will be ignored."}.arg(c);
break;
}
QStringList urls;
std::transform(fields.cbegin(), fields.cend(), std::back_inserter(urls), processUrl);
fields.clear();
if (c == 'U') {
task.Resources.emplace_back(urls.join(' '));
} else {
std::for_each(
urls.begin(), urls.end(), [&task](QString &url) { task.Resources.emplace_back(std::move(url)); });
}
task.argNum = std::distance(args->begin(), arg) - 1;
task.fieldLocation = std::distance(arg->cbegin(), it) - 1;
} break;
case 'i': {
auto val = m_entry->value(DesktopFileEntryKey, "Icon");
if (!val) {
qDebug() << R"(Application Icons can't be found. %i will be ignored.)";
break;
}
auto iconStr = toIconString(val.value());
if (iconStr.isEmpty()) {
qDebug() << R"(Icons Convert to string failed. %i will be ignored.)";
break;
}
// split at the end of loop
newArg.append(QString{"--icon %1"}.arg(iconStr));
} break;
case 'c': {
auto val = m_entry->value(DesktopFileEntryKey, "Name");
if (!val) {
qDebug() << R"(Application Name can't be found. %c will be ignored.)";
break;
}
const auto &rawValue = val.value();
if (!rawValue.canConvert<QStringMap>()) {
qDebug() << "Name's underlying type mismatch:" << "QStringMap" << rawValue.metaType().name();
break;
}
auto NameStr = toLocaleString(rawValue.value<QStringMap>(), getUserLocale());
if (NameStr.isEmpty()) {
qDebug() << R"(Name Convert to locale string failed. %c will be ignored.)";
break;
}
newArg.append(NameStr);
} break;
case 'k': { // ignore all desktop file location for now.
newArg.append(m_desktopSource.sourcePath());
} break;
case 'd':
case 'D':
case 'n':
case 'N':
case 'v':
[[fallthrough]]; // Deprecated field codes should be removed from the command line and ignored.
case 'm': {
qDebug() << "field code" << *code << "has been deprecated.";
} break;
default: {
qDebug() << "unknown field code:" << *code << ", ignore it.";
}
}
it += 2; // skip filed code
} }
auto iconStr = toIconString(val.value()); auto newArgList = newArg.split(' ', Qt::SkipEmptyParts);
if (iconStr.isEmpty()) { if (!newArgList.isEmpty()) {
qDebug() << R"(Icons Convert to string failed. %i will be ignored.)"; task.command.append(std::move(newArgList));
task.command.append(std::move(execList));
return task;
} }
auto it = execList.insert(location, iconStr);
execList.insert(it, "--icon");
task.command.append(std::move(execList));
} break;
case 'c': {
execList.removeAt(location);
auto val = m_entry->value(DesktopFileEntryKey, "Name");
if (!val) {
qDebug() << R"(Application Name can't be found. %c will be ignored.)";
task.command.append(std::move(execList));
return task;
}
const auto &rawValue = val.value();
if (!rawValue.canConvert<QStringMap>()) {
qDebug() << "Name's underlying type mismatch:" << "QStringMap" << rawValue.metaType().name();
task.command.append(std::move(execList));
return task;
}
auto NameStr = toLocaleString(rawValue.value<QStringMap>(), getUserLocale());
if (NameStr.isEmpty()) {
qDebug() << R"(Name Convert to locale string failed. %c will be ignored.)";
task.command.append(std::move(execList));
return task;
}
execList.insert(location, NameStr);
task.command.append(std::move(execList));
} break;
case 'k': { // ignore all desktop file location for now.
execList.removeAt(location);
task.command.append(std::move(execList));
} break;
case 'd':
case 'D':
case 'n':
case 'N':
case 'v':
[[fallthrough]]; // Deprecated field codes should be removed from the command line and ignored.
case 'm': {
execList.removeAt(location);
task.command.append(std::move(execList));
} break;
default: {
qDebug() << "unrecognized file code.";
}
} }
if (task.Resources.isEmpty()) { if (task.Resources.isEmpty()) {
task.Resources.emplace_back(QString{""}); // mapReduce should run once at least task.Resources.emplace_back(QVariant{}); // mapReduce should run once at least
} }
qInfo() << "after unescape exec:" << task.LaunchBin << task.command << task.Resources;
return task; return task;
} }
void ApplicationService::unescapeEens(QVariantMap &options) noexcept
{
if (options.find("env") == options.end()) {
return;
}
QStringList result;
auto envs = options["env"];
for (const QString &var : envs.toStringList()) {
wordexp_t p;
if (wordexp(var.toStdString().c_str(), &p, 0) == 0) {
for (size_t i = 0; i < p.we_wordc; i++) {
result << QString::fromLocal8Bit(p.we_wordv[i]); // 将结果转换为QString
}
wordfree(&p);
} else {
return;
}
}
options.insert("env", result);
}
void ApplicationService::autoRemoveFromDesktop() const noexcept
{
auto dir = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
if (dir.isEmpty()) {
return;
}
QFileInfo desktopFile{QDir{dir}.filePath(m_desktopSource.desktopId() + ".desktop")};
if (!desktopFile.isSymbolicLink()) {
qDebug() << desktopFile.filePath() << " is not symbolicLink";
return;
}
QFile file{desktopFile.filePath()};
auto success = file.remove();
if (!success) {
qWarning() << "remove desktop file failed:" << file.errorString();
return;
}
}
QVariant ApplicationService::findEntryValue(const QString &group, QVariant ApplicationService::findEntryValue(const QString &group,
const QString &valueKey, const QString &valueKey,
EntryValueType type, EntryValueType type,

View File

@ -134,8 +134,10 @@ public:
EntryValueType type, EntryValueType type,
const QLocale &locale = getUserLocale()) const noexcept; const QLocale &locale = getUserLocale()) const noexcept;
[[nodiscard]] LaunchTask unescapeExec(const QString &str, const QStringList &fields) noexcept; [[nodiscard]] LaunchTask unescapeExec(const QString &str, QStringList fields) noexcept;
[[nodiscard]] static std::optional<QStringList> unescapeExecArgs(const QString &str) noexcept; [[nodiscard]] static std::optional<QStringList> unescapeExecArgs(const QString &str) noexcept;
void unescapeEens(QVariantMap&) noexcept;
void autoRemoveFromDesktop() const noexcept;
public Q_SLOTS: public Q_SLOTS:
// NOTE: 'realExec' only for internal implementation // NOTE: 'realExec' only for internal implementation

View File

@ -29,9 +29,13 @@ struct LaunchTask
LaunchTask &operator=(const LaunchTask &) = default; LaunchTask &operator=(const LaunchTask &) = default;
LaunchTask &operator=(LaunchTask &&) = default; LaunchTask &operator=(LaunchTask &&) = default;
explicit operator bool() const { return !LaunchBin.isEmpty() and !command.isEmpty(); } explicit operator bool() const { return !LaunchBin.isEmpty() and !command.isEmpty(); }
QString LaunchBin; QString LaunchBin;
QStringList command; QStringList command;
QVariantList Resources; QVariantList Resources;
bool singleInstance{false};
int argNum{-1};
int fieldLocation{-1};
}; };
Q_DECLARE_METATYPE(LaunchTask) Q_DECLARE_METATYPE(LaunchTask)