fix: use preservePaths in batch extraction to keep correct directory …#417
Conversation
…structure fix incorrect params Log: fix bug Bug: https://pms.uniontech.com/bug-view-362685.html
deepin pr auto review你好!我是CodeGeeX。我已仔细审查了你提供的Git Diff代码。本次修改主要涉及两处变更:一是将子进程的工作目录设置方式从 下面我将从语法逻辑、代码质量、代码性能和代码安全四个维度对这段代码进行审查,并提供改进意见。 1. 语法与逻辑审查 (高风险 🚨)问题:
问题:
2. 代码质量审查问题:阻塞式调用
问题:代码重复
3. 代码性能审查问题:
4. 代码安全审查 (高风险 🚨)问题:工作目录劫持与路径穿越风险
💡 综合改进建议代码示例基于以上分析,我建议的修改方案如下(回退工作目录修改,提取公共代码): // 建议提取的私有方法
void CliInterface::startExtractProcess(const QString &targetPath, const QList<FileEntry> &files, bool preserveLongName, const QString &pwd)
{
// 1. 安全性:仅设置子进程的工作目录,绝不改变全局CWD
pProcess->setWorkingDirectory(targetPath);
pProcess->setPtyChannels(KPtyProcess::StdinChannel);
pProcess->setOutputChannelMode(KProcess::MergedChannels);
pProcess->setNextOpenMode(QIODevice::ReadWrite | QIODevice::Unbuffered | QIODevice::Text);
// 2. 逻辑:根据需求传入长文件名参数
pProcess->setProgram(m_cliProps->property("extractProgram").toString(),
m_cliProps->extractArgs(targetPath, files, preserveLongName, pwd));
pProcess->start();
}
// 原代码修改处 1
bool CliInterface::handleLongNameExtract(const QList<FileEntry> &files)
{
qInfo() << "handleLongNameExtract: batch extract files:" << allFileList.count();
if (!allFileList.isEmpty()) {
// 调用重构后的方法,传入 true 保留长文件名
startExtractProcess(options.strTargetPath, allFileList, true, password);
if (password.isEmpty()) {
// ... 密码处理逻辑 ...
}
// ...
}
}
// 原代码修改处 2 (重试逻辑处)
// ...
startExtractProcess(options.strTargetPath, allFileList, true, password);
// 注意:强烈建议将下方的 waitForFinished(-1) 改为异步信号槽处理
// pProcess->waitForFinished(-1); 总结:本次Diff中最核心的问题是 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: LiHua000, max-lvs 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 |
|
/merge |
…structure
fix incorrect params
Log: fix bug
Bug: https://pms.uniontech.com/bug-view-362685.html