Skip to content

fix(cli): use HOME env instead of hardcoded "/home/" path prefix check#1719

Merged
dengbo11 merged 2 commits into
OpenAtom-Linyaps:release/1.13from
dengbo11:release-1.13
Jul 2, 2026
Merged

fix(cli): use HOME env instead of hardcoded "/home/" path prefix check#1719
dengbo11 merged 2 commits into
OpenAtom-Linyaps:release/1.13from
dengbo11:release-1.13

Conversation

@dengbo11

@dengbo11 dengbo11 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator
  • Replace hardcoded "/home/" string prefix check with HOME environment variable to support non-standard home directories
  • Add null and empty string checks for HOME env to handle edge cases
  • Append trailing slash to HOME path before prefix matching to avoid false positive on paths like /home/bob-xxx
  • Fix minor indentation on LogE call

- Replace hardcoded "/home/" string prefix check with HOME environment variable to support non-standard home directories
- Add null and empty string checks for HOME env to handle edge cases
- Append trailing slash to HOME path before prefix matching to avoid false positive on paths like /home/bob-xxx
- Fix minor indentation on LogE call
@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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request replaces the hardcoded /home/ path check with a dynamic check using the HOME environment variable to avoid mapping files under the user's home directory. The review feedback correctly identifies that returning early when HOME is not set or empty will break file mapping in environments where HOME is undefined; instead, the check should be skipped so mapping can proceed.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +1790 to 1803
auto *homePath = ::getenv("HOME");
if (homePath == nullptr || homePath[0] == '\0') {
LogE("failed to get HOME env");
return target;
}

// Don't map files under the user's home directory
auto homeStr = std::string(homePath);
if (homeStr.back() != '/') {
homeStr.push_back('/');
}
if (auto tmp = target.string(); tmp.rfind(homeStr, 0) == 0) {
return target;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

If the HOME environment variable is not set or is empty, returning target early from Cli::mappingFile will completely bypass the file mapping logic (which maps files to /run/host/rootfs/...). This means that in environments where HOME is not defined (such as some systemd services, cron jobs, or restricted sandboxes), absolute paths will not be mapped at all, breaking core functionality.

Instead of returning target early when HOME is unavailable, we should simply skip the home directory check and proceed with the file mapping.

    auto *homePath = ::getenv("HOME");
    if (homePath != nullptr && homePath[0] != '\0') {
        // Don't map files under the user's home directory
        auto homeStr = std::string(homePath);
        if (homeStr.back() != '/') {
            homeStr.push_back('/');
        }
        if (auto tmp = target.string(); tmp.rfind(homeStr, 0) == 0) {
            return target;
        }
    }

@dengbo11 dengbo11 merged commit dff5088 into OpenAtom-Linyaps:release/1.13 Jul 2, 2026
12 of 14 checks passed
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
libs/linglong/src/linglong/cli/cli.cpp 0.00% 8 Missing ⚠️
Files with missing lines Coverage Δ
libs/linglong/src/linglong/cli/cli.cpp 1.75% <0.00%> (-0.01%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants