Skip to content

fix: strip /sys prefix precisely in isPathExisted - #830

Closed
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bug/793d297254ce
Closed

add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bug/793d297254ce

Conversation

@add-uos

@add-uos add-uos commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

fix: strip /sys prefix precisely in isPathExisted

  1. Root cause: replace("/sys", "") replaced all occurrences of
    "/sys" substring in the path, not just the prefix, causing
    incorrect path matching when "/sys" appeared mid-path
  2. Fix: use startsWith("/sys") to check prefix, then remove(0, 4)
    to strip only the leading "/sys" prefix
  3. Impact: path matching now correctly strips only the prefix,
    no false matches on paths containing "/sys" elsewhere

fix: 精确剥离路径前缀 /sys

  1. 根因:replace("/sys", "") 会替换路径中所有 "/sys" 子串,
    而非仅剥离前缀,导致路径中间含 "/sys" 时匹配错误
  2. 方案:使用 startsWith("/sys") 判断前缀后 remove(0, 4)
    精确剥离路径开头的 "/sys" 前缀
  3. 影响:路径匹配仅剥离前缀,不再误删路径中间的 "/sys" 子串

PMS: BUG-4

Summary by Sourcery

Bug Fixes:

  • Ensure path existence checks remove only a leading "/sys" prefix, preventing incorrect matches when "/sys" appears elsewhere in a path.

1. Root cause: replace("/sys", "") replaced all occurrences of
   "/sys" substring in the path, not just the prefix, causing
   incorrect path matching when "/sys" appeared mid-path
2. Fix: use startsWith("/sys") to check prefix, then remove(0, 4)
   to strip only the leading "/sys" prefix
3. Impact: path matching now correctly strips only the prefix,
   no false matches on paths containing "/sys" elsewhere

fix: 精确剥离路径前缀 /sys

1. 根因:replace("/sys", "") 会替换路径中所有 "/sys" 子串,
   而非仅剥离前缀,导致路径中间含 "/sys" 时匹配错误
2. 方案:使用 startsWith("/sys") 判断前缀后 remove(0, 4)
   精确剥离路径开头的 "/sys" 前缀
3. 影响:路径匹配仅剥离前缀,不再误删路径中间的 "/sys" 子串

PMS: BUG-4
@sourcery-ai

sourcery-ai Bot commented Oct 10, 2026

Copy link
Copy Markdown

Sorry @add-uos, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 days and 3 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos

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

@sourcery-ai

sourcery-ai Bot commented Oct 10, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates DeviceInfoManager::isPathExisted to strip /sys only when it is the leading prefix, preventing incorrect path matches caused by replacing /sys substrings elsewhere in the path.

Flow diagram for precise /sys prefix stripping

flowchart TD
    A["isPathExisted(path)"] --> B["Copy path to pathT"]
    B --> C{"pathT.startsWith(/sys)"}
    C -- Yes --> D["pathT.remove(0, 4)"]
    C -- No --> E["Keep pathT unchanged"]
    D --> F["hwinfo.contains(pathT)"]
    E --> F
    F --> G["Return exists"]
Loading

File-Level Changes

Change Details Files
Make /sys normalization prefix-only before checking hardware-info path existence.
  • Initialize the match result explicitly.
  • Check whether the input path begins with /sys.
  • Remove exactly the leading four-character prefix before searching hwinfo.
  • Preserve any /sys occurrences elsewhere in the path.
deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/deviceinfomanager.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@add-uos add-uos closed this Oct 10, 2026
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