Release 1.11#1566
Conversation
Changes: - Reimplement `linglong::utils::Cmd`. - Add unit tests for the new `Cmd` implementation and file operations. - Use thred-safe errorString instead of strerror. - submodules only affects git kind source. - Remove unused code. Signed-off-by: reddevillg <reddevillg@gmail.com>
97% of minimum 50% translated source file: 'po/en_US.po' on 'fr'. Sync of partially translated files: untranslated content is included with an empty translation or source language content depending on file format
Signed-off-by: reddevillg <reddevillg@gmail.com>
Signed-off-by: ComixHe <ComixHe1895@outlook.com>
Signed-off-by: ComixHe <ComixHe1895@outlook.com>
Removed custom temporary file management code from test fixtures and replaced it with the existing TempDir utility class. This change eliminates duplicate code for creating and cleaning up temporary files in multiple test files. The TempDir utility provides better resource management through RAII pattern, ensuring proper cleanup even if tests fail. This improves code maintainability and reduces the risk of resource leaks. Influence: 1. Verify all driver detection tests still pass 2. Confirm file lock functionality tests work correctly 3. Check that temporary files are properly cleaned up after tests 4. Ensure no file permission issues with new temp directory approach 5. Test inter-process locking behavior remains consistent refactor: 使用 TempDir 工具类替换手动临时文件处理 从测试夹具中移除自定义的临时文件管理代码,改用现有的 TempDir 工具类。此 更改消除了多个测试文件中创建和清理临时文件的重复代码。TempDir 工具通过 RAII 模式提供更好的资源管理,确保即使测试失败也能正确清理。这提高了代码 的可维护性并降低了资源泄漏的风险。 Influence: 1. 验证所有驱动检测测试仍然通过 2. 确认文件锁功能测试正常工作 3. 检查临时文件在测试后是否正确清理 4. 确保新的临时目录方法没有文件权限问题 5. 测试进程间锁定行为保持一致
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengbo11 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 reviewGit Diff 代码审查报告总体评价这次提交进行了大规模的代码重构,主要涉及命令执行模块的改进、配置加载逻辑的优化以及错误处理的统一化。整体来看,代码质量有显著提升,但仍有部分细节可以进一步优化。 主要改进点1. 命令执行模块重构
2. 配置管理优化
3. 错误处理统一
4. 新增 socket 通信模块
代码质量与性能问题1. Cmd 类实现问题// libs/utils/src/linglong/utils/cmd.cpp
std::filesystem::path Cmd::getCommandPath()
{
// ...
for (const auto &pathDir : pathDirs) {
std::filesystem::path fullPath = std::filesystem::path{ pathDir } / m_command;
if (std::filesystem::exists(fullPath, ec)
&& std::filesystem::is_regular_file(fullPath, ec)) {
return fullPath;
}
}
return {};
}问题:每次调用 建议:添加缓存机制,避免重复查找。 2. 环境变量处理效率// libs/utils/src/linglong/utils/cmd.cpp
// Pre-allocate environment variables before fork to avoid memory allocation issues
std::vector<std::string> envStrings;
std::vector<char *> envp;
// Copy current environment
for (char **env = environ; *env != nullptr; ++env) {
envStrings.emplace_back(*env);
}问题:每次执行命令都复制整个环境变量,效率较低。 建议:考虑使用 3. Socket 实现细节// libs/common/src/linglong/common/socket.cpp
while (true) {
n = recvmsg(socketFd, &msg, 0);
if (n < 0 && errno == EINTR) {
continue;
}
break;
}问题:没有设置超时机制,可能导致永久阻塞。 建议:添加超时参数,使用 4. 文件操作错误处理// libs/utils/src/linglong/utils/file.cpp
std::ifstream in{ filepath };
if (!in.is_open()) {
auto msg = std::string("open file:") + common::error::errorString(errno);
return LINGLONG_ERR(msg.c_str());
}问题:错误信息不够详细,缺少文件路径。 建议:修改为 安全问题1. 命令注入风险// libs/utils/src/linglong/utils/cmd.cpp
execvpe(commandPath.c_str(), argv.data(), envp.data());优点:使用 2. 文件描述符泄漏// libs/common/src/linglong/common/socket.cpp
if (received_fd != -1) {
::close(received_fd);
}问题:在某些错误路径中可能忘记关闭文件描述符。 建议:使用 RAII 包装文件描述符,确保资源释放。 3. 权限问题// libs/utils/src/linglong/utils/file.cpp
std::ofstream out{ filepath };问题:没有显式设置文件权限。 建议:在创建文件后使用 其他建议1. 测试覆盖新增的 socket 模块有较好的测试覆盖,但其他模块的测试可以进一步完善,特别是错误路径的测试。 2. 文档新增的 API 缺少详细的文档注释,建议添加 Doxygen 风格的注释。 3. 兼容性代码中使用了较新的 C++ 特性,需要确认目标平台是否支持。 结论这次提交整体质量较高,主要改进了命令执行模块和配置管理逻辑,统一了错误处理方式。但仍有一些性能和细节问题需要优化,特别是命令路径查找和环境变量处理的效率。建议在后续迭代中逐步完善这些问题。 |
No description provided.