Skip to content

chore: cherry-pick commits from release/eagle branch#113

Merged
deepin-bot[bot] merged 4 commits intolinuxdeepin:masterfrom
re2zero:cherry-eagle
Nov 28, 2025
Merged

chore: cherry-pick commits from release/eagle branch#113
deepin-bot[bot] merged 4 commits intolinuxdeepin:masterfrom
re2zero:cherry-eagle

Conversation

@re2zero
Copy link
Contributor

@re2zero re2zero commented Nov 28, 2025

Cherry pick the commits from release/eagle branch which has fixed some issues.

Log: cherry-pick commits from release/eagle branch.

Command execution rectification

Log: Command execution rectification
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @re2zero, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

下载移除dht文件

Task: https://pms.uniontech.com/task-view-368187.html
Log: 下载移除dht文件
Added conditional compilation for Qt6 to handle the different split method signature and added bounds checking to prevent accessing array index 6 when the parts array has fewer elements.

Log: Fix Qt6 build.
@deepin-ci-robot
Copy link
Contributor

deepin pr auto review

我来对这段代码进行审查:

  1. 代码重复问题:
  • runPipeProcess函数在多个文件中重复定义,这违反了DRY(Don't Repeat Yourself)原则。建议将其移到一个公共的工具类中。
  1. 进程管理改进:
  • 在killAria2cProc函数中,使用kill -9强制终止进程可能过于粗暴。建议先尝试使用SIGTERM(15)信号,给进程一个优雅退出的机会,如果失败再使用SIGKILL(9)。
  1. 错误处理不足:
  • runPipeProcess函数没有错误处理机制,比如process.waitForFinished()应该检查返回值。
  • QProcess操作都应该添加错误处理和超时机制。
  1. 安全性问题:
  • 在runPipeProcess中直接执行shell命令可能存在命令注入风险。建议使用QProcess的参数化方式执行命令,而不是直接拼接字符串。
  1. 性能优化:
  • 在checkAria2cProc函数中,可以使用ps的-o参数只获取需要的字段,而不是获取所有信息后再解析。
  • runPipeProcess函数可以考虑添加缓存机制,避免频繁执行相同的命令。
  1. 代码可维护性:
  • 建议将硬编码的路径和命令提取为常量。
  • 添加更多的注释说明关键逻辑。
  1. 具体修改建议:
// 1. 将runPipeProcess移到工具类中
class ProcessUtils {
public:
    static QStringList runPipeProcess(const QString &command, const QString &filter, int timeoutMs = 30000) {
        QProcess process;
        process.start(command);
        if (!process.waitForFinished(timeoutMs)) {
            qWarning() << "Command timeout:" << command;
            process.kill();
            return QStringList();
        }

        if (process.exitCode() != 0) {
            qWarning() << "Command failed with exit code:" << process.exitCode();
            return QStringList();
        }

        QString output = process.readAllStandardOutput();
        QStringList lines = output.split('\n', Qt::SkipEmptyParts);
        
        if (filter.isEmpty()) {
            return lines;
        }

        return lines.filter(filter, Qt::CaseInsensitive);
    }
};

// 2. 改进进程终止逻辑
int Aria2RPCInterface::killAria2cProc() {
    QStringList pids = ProcessUtils::runPipeProcess("ps -eo pid,cmd", m_aria2cCmd);
    for (const QString &pid : pids) {
        QProcess killProcess;
        killProcess.start("kill", QStringList() << "-TERM" << pid);
        if (!killProcess.waitForFinished(5000)) {
            qWarning() << "Failed to gracefully terminate process" << pid << ", forcing kill";
            killProcess.start("kill", QStringList() << "-KILL" << pid);
            killProcess.waitForFinished(5000);
        }
    }
    return 0;
}

// 3. 使用常量定义路径和命令
namespace Constants {
    const QString SESSION_CACHE_PATH = QDir::homePath() + "/.cache/uos-aria2c.session";
    const QString ARIA2C_CMD = "aria2c";
    // ... 其他常量
}
  1. 其他建议:
  • 考虑使用QProcess::startDetached的参数化版本,而不是字符串拼接。
  • 在updateDHTFile函数中删除的DHT文件更新逻辑可能需要重新评估其必要性。
  • 建议添加日志记录机制,便于问题排查。

这些修改将提高代码的可维护性、安全性和性能。

@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, re2zero

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@re2zero
Copy link
Contributor Author

re2zero commented Nov 28, 2025

/merge

@deepin-bot deepin-bot bot merged commit 5d95f10 into linuxdeepin:master Nov 28, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants