refactor(utils): use Qt API for command lookup#858
Conversation
Use QStandardPaths to check executable availability. 使用QStandardPaths检查可执行命令是否存在。 Log: 使用Qt接口替代外部which命令查询 Task:https://pms.uniontech.com/task-view-390623.html Influence: 仅影响dman命令存在性检查逻辑,F1帮助快捷键行为保持不变。
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: tianming-1996 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review你好!我是CodeGeeX。我已仔细审查了你提供的Git Diff,这次修改对 总体来说,这是一次非常优秀的重构。以下是针对各个维度的详细审查意见: 1. 语法逻辑 (✅ 优秀)
2. 代码质量 (✅ 显著提升)
3. 代码性能 (✅ 大幅优化)
4. 代码安全 (✅ 消除安全隐患)
💡 进阶改进建议虽然当前修改已经很好,但为了让代码达到工业级标准,我建议在性能和安全性上做进一步的微调: 1. 性能优化:传递 2. 安全性增强:校验输入合法性 改进后的代码示例: // 在头文件中修改声明
bool BaseUtils::isCommandExist(const QString& command);
// 在 cpp 文件中修改实现
bool BaseUtils::isCommandExist(const QString& command)
{
// 安全校验:如果传入的命令包含路径分隔符,直接返回 false,
// 强制只允许搜索系统 PATH 中的纯命令名,避免相对路径带来的安全隐患。
if (command.contains(QChar('/')) || command.contains(QChar('\\'))) {
return false;
}
return !QStandardPaths::findExecutable(command).isEmpty();
}总结:你的核心重构思路完全正确,极大地提升了代码质量。如果采纳上述关于常量引用和路径分隔符校验的建议,代码将更加完美! |
|
/merge |
Use QStandardPaths to check executable availability.
使用QStandardPaths检查可执行命令是否存在。
Log: 使用Qt接口替代外部which命令查询
Task:https://pms.uniontech.com/task-view-390623.html Influence: 仅影响dman命令存在性检查逻辑,F1帮助快捷键行为保持不变。