Skip to content

Release 1.11#1566

Merged
dengbo11 merged 6 commits into
OpenAtom-Linyaps:release/1.11from
dengbo11:release-1.11
Jan 22, 2026
Merged

Release 1.11#1566
dengbo11 merged 6 commits into
OpenAtom-Linyaps:release/1.11from
dengbo11:release-1.11

Conversation

@dengbo11

Copy link
Copy Markdown
Collaborator

No description provided.

reddevillg and others added 6 commits January 22, 2026 20:54
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. 测试进程间锁定行为保持一致
@deepin-ci-robot

Copy link
Copy Markdown
Collaborator

[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.

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

@deepin-ci-robot

Copy link
Copy Markdown
Collaborator

deepin pr auto review

Git Diff 代码审查报告

总体评价

这次提交进行了大规模的代码重构,主要涉及命令执行模块的改进、配置加载逻辑的优化以及错误处理的统一化。整体来看,代码质量有显著提升,但仍有部分细节可以进一步优化。

主要改进点

1. 命令执行模块重构

  • utils::command::Cmd 重构为 utils::Cmd,移除了对 Qt 的依赖
  • 新增了 toStdin 方法支持向子进程写入数据
  • 使用原生 POSIX API 替代 QProcess,减少了依赖
  • 使用 epoll 实现非阻塞 I/O,提高了性能

2. 配置管理优化

  • 简化了配置加载逻辑,移除了 projectBuildConfigPathsnonProjectBuildConfigPaths 函数
  • 将配置初始化逻辑移入 initDefaultBuildConfig 函数
  • 使用 std::filesystem::path 替代 QString 处理路径

3. 错误处理统一

  • 新增 linglong::common::error::errorString 函数统一错误信息格式
  • 使用 LogELogW 等宏替代 qCriticalqWarning 等 Qt 日志函数
  • 错误信息格式更加一致

4. 新增 socket 通信模块

  • 新增 linglong::common::socket 命名空间,提供文件描述符传输功能
  • 实现了 recvFdWithPayloadsendFdWithPayload 函数
  • 添加了相应的单元测试

代码质量与性能问题

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 {};
}

问题:每次调用 getCommandPath 都会遍历 PATH,效率较低。

建议:添加缓存机制,避免重复查找。

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);
}

问题:每次执行命令都复制整个环境变量,效率较低。

建议:考虑使用 execvpe 直接传递当前环境,只在需要修改时才复制。

3. Socket 实现细节

// libs/common/src/linglong/common/socket.cpp
while (true) {
    n = recvmsg(socketFd, &msg, 0);
    if (n < 0 && errno == EINTR) {
        continue;
    }
    break;
}

问题:没有设置超时机制,可能导致永久阻塞。

建议:添加超时参数,使用 setsockopt 设置接收超时。

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());
}

问题:错误信息不够详细,缺少文件路径。

建议:修改为 fmt::format("open file {}: {}", filepath, common::error::errorString(errno))

安全问题

1. 命令注入风险

// libs/utils/src/linglong/utils/cmd.cpp
execvpe(commandPath.c_str(), argv.data(), envp.data());

优点:使用 execvpe 而非 system,避免了命令注入风险。

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 };

问题:没有显式设置文件权限。

建议:在创建文件后使用 chmod 设置适当的权限。

其他建议

1. 测试覆盖

新增的 socket 模块有较好的测试覆盖,但其他模块的测试可以进一步完善,特别是错误路径的测试。

2. 文档

新增的 API 缺少详细的文档注释,建议添加 Doxygen 风格的注释。

3. 兼容性

代码中使用了较新的 C++ 特性,需要确认目标平台是否支持。

结论

这次提交整体质量较高,主要改进了命令执行模块和配置管理逻辑,统一了错误处理方式。但仍有一些性能和细节问题需要优化,特别是命令路径查找和环境变量处理的效率。建议在后续迭代中逐步完善这些问题。

@codecov

codecov Bot commented Jan 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 45.78588% with 238 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
libs/utils/src/linglong/utils/cmd.cpp 55.81% 44 Missing and 32 partials ⚠️
libs/common/src/linglong/common/socket.cpp 53.42% 13 Missing and 21 partials ⚠️
libs/utils/src/linglong/utils/file.cpp 23.07% 8 Missing and 12 partials ⚠️
libs/linglong/src/linglong/builder/config.cpp 56.41% 7 Missing and 10 partials ⚠️
...s/linglong/src/linglong/package/layer_packager.cpp 21.05% 4 Missing and 11 partials ⚠️
libs/linglong/src/linglong/repo/ostree_repo.cpp 14.28% 12 Missing ⚠️
libs/utils/src/linglong/utils/namespace.cpp 0.00% 11 Missing ⚠️
libs/utils/src/linglong/utils/overlayfs.cpp 0.00% 10 Missing ⚠️
libs/linglong/src/linglong/package/uab_file.cpp 52.94% 6 Missing and 2 partials ⚠️
libs/utils/src/linglong/utils/env.cpp 57.89% 3 Missing and 5 partials ⚠️
... and 11 more
Files with missing lines Coverage Δ
libs/common/src/linglong/common/error.cpp 100.00% <100.00%> (ø)
...s/linglong/src/linglong/builder/source_fetcher.cpp 71.15% <100.00%> (+1.15%) ⬆️
...ibs/linglong/src/linglong/builder/source_fetcher.h 100.00% <100.00%> (ø)
apps/ll-cli/src/main.cpp 0.00% <0.00%> (ø)
apps/ll-driver-detect/src/main.cpp 0.00% <0.00%> (ø)
libs/linglong/src/linglong/package/layer_file.cpp 29.09% <0.00%> (ø)
...g/src/linglong/package_manager/package_manager.cpp 1.38% <0.00%> (ø)
apps/ll-builder/src/main.cpp 0.00% <0.00%> (ø)
libs/linglong/src/linglong/cli/cli.cpp 1.00% <0.00%> (+<0.01%) ⬆️
...ps/ll-driver-detect/src/nvidia_driver_detector.cpp 23.25% <0.00%> (+0.52%) ⬆️
... and 14 more

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dengbo11 dengbo11 merged commit 401f418 into OpenAtom-Linyaps:release/1.11 Jan 22, 2026
16 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.

5 participants