Skip to content

fix: cherry-pick 2 bugs of release/eagle#359

Merged
deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
LiHua000:master
Dec 18, 2025
Merged

fix: cherry-pick 2 bugs of release/eagle#359
deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
LiHua000:master

Conversation

@LiHua000

@LiHua000 LiHua000 commented Dec 18, 2025

Copy link
Copy Markdown
Contributor

fix: handle empty package version in conflict resolution
fix: empty value check (#348)

Summary by Sourcery

Handle package conflict and replacement rules correctly when the conflicting or replacement package version is unspecified.

Bug Fixes:

  • Treat conflicts as satisfied when the conflict version is empty instead of requiring a version comparison.
  • Treat replacement rules as valid when the replacement package version is empty instead of requiring a version comparison.

LiHua000 and others added 2 commits December 18, 2025 09:32
log: Add check for empty conflict_version in isConflictSatisfy to prevent installation failures when conflict version is missing
…#346)

- Add check for empty package version in replace logic
- Fix potential issue when replace.packageVersion() is empty
- Improve conflict resolution reliability

When checking if a package can replace a conflicting package,
the code now properly handles cases where the replace version
is empty, preventing potential comparison issues.
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

我来对这段代码变更进行审查:

  1. 语法逻辑:
    代码修改主要是在版本比较前增加了对版本号是否为空的检查。这个修改是合理的,因为在某些情况下可能没有版本号信息,此时应该跳过版本比较。修改后的逻辑更加健壮。

  2. 代码质量:

  • 优点:增加了空值检查,提高了代码的健壮性
  • 建议:可以考虑将空值检查逻辑抽取为一个单独的函数,避免重复代码。例如:
bool isValidVersionCheck(const QString& version, Package::CompareResult result, Package::RelationType type) {
    return version.isEmpty() || dependencyVersionMatch(result, type);
}
  1. 代码性能:
  • 性能影响很小,只是增加了一个字符串空值检查
  • 建议:如果这个函数被频繁调用,可以考虑在函数入口处预先检查版本号,避免不必要的版本比较操作
  1. 代码安全:
  • 修改增加了对空版本号的处理,提高了安全性
  • 建议:建议在代码注释中说明为什么需要检查空版本号,以及这种情况在什么场景下会发生

总体评价:
这是一个好的改进,提高了代码的健壮性和安全性。主要改进点是:

  1. 增加了对空版本号的处理,避免了可能的空指针或无效比较
  2. 保持了原有逻辑的正确性
  3. 代码可读性良好

建议后续改进:

  1. 考虑抽取公共的版本检查逻辑
  2. 增加更详细的注释说明
  3. 考虑在代码中添加单元测试来验证空版本号的处理逻辑

@sourcery-ai

sourcery-ai Bot commented Dec 18, 2025

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

Reviewer's Guide

Adjusts conflict resolution logic in the Debian package manager to gracefully handle conflicts and replacements when the conflict or replacement package version is empty.

Sequence diagram for updated conflict resolution when conflict_version may be empty

sequenceDiagram
    participant PackagesManager
    participant Package
    participant DependencyMatcher as DependencyVersionMatcher

    PackagesManager->>Package: compareVersion(installed_version, conflict_version)
    Package-->>PackagesManager: result

    alt conflict_version is empty
        PackagesManager->>PackagesManager: treat as non_matching_conflict
        PackagesManager->>PackagesManager: package = nullptr
        PackagesManager->>PackagesManager: continue to next package
    else conflict_version is not empty
        PackagesManager->>DependencyMatcher: dependencyVersionMatch(result, type)
        alt version does not match
            PackagesManager->>PackagesManager: package = nullptr
            PackagesManager->>PackagesManager: continue to next package
        else version matches
            PackagesManager->>PackagesManager: keep package as conflicting
        end
    end
Loading

Sequence diagram for updated replace resolution when replace.packageVersion may be empty

sequenceDiagram
    participant PackagesManager
    participant Package
    participant Replace
    participant DependencyMatcher as DependencyVersionMatcher

    loop for each replace rule
        PackagesManager->>Replace: relationType()
        Replace-->>PackagesManager: replaceType

        PackagesManager->>Replace: packageVersion()
        Replace-->>PackagesManager: replaceVersion

        alt replaceVersion is empty
            PackagesManager->>PackagesManager: consider replace rule satisfied
            PackagesManager->>PackagesManager: conflict_yes = false
        else replaceVersion is not empty
            PackagesManager->>Package: compareVersion(installed_version, replaceVersion)
            Package-->>PackagesManager: versionCompare

            PackagesManager->>DependencyMatcher: dependencyVersionMatch(versionCompare, replaceType)
            alt version matches
                PackagesManager->>PackagesManager: conflict_yes = false
            else version does not match
                PackagesManager->>PackagesManager: continue to next replace rule
            end
        end
    end
Loading

Class diagram for updated PackagesManager conflict and replace handling

classDiagram
    class PackagesManager {
        +ConflictResult isConflictSatisfy(QString arch, QString packageName, QString version)
        -bool dependencyVersionMatch(int compareResult, RelationType type)
    }

    class Package {
        +static int compareVersion(QString versionA, QString versionB)
    }

    class Replace {
        +RelationType relationType()
        +QString packageVersion()
    }

    class ConflictResult {
        +bool conflict_yes
        +QString conflictingPackageName
    }

    class RelationType

    PackagesManager --> Package : uses
    PackagesManager --> Replace : evaluates
    PackagesManager --> ConflictResult : returns
    PackagesManager --> RelationType : uses
    Replace --> RelationType : returns
Loading

File-Level Changes

Change Details Files
Update conflict handling to treat conflicts with empty conflict versions as non-matching and therefore non-conflicting.
  • Compute version comparison result between installed and conflict versions as before.
  • Extend the conditional check so that conflicts with an empty conflict version immediately result in the conflict being ignored.
  • Ensure that when the conflict version is empty, the package pointer is cleared and iteration continues without treating it as a conflict.
src/deb-installer/manager/packagesmanager.cpp
Update replacement handling to treat replacements without a version constraint as always matching.
  • Compare installed package version against the replacement package version as before.
  • Extend the replacement condition to short-circuit as true when the replacement package version is empty.
  • Maintain existing behavior where a matching version constraint causes the replacement to be considered valid and breaks out of conflict handling.
src/deb-installer/manager/packagesmanager.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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • In both new conditions, consider documenting the intended semantics of an empty version (e.g., treating it as ‘no version constraint’) so future readers understand why isEmpty() short-circuits the usual version comparison.
  • In the replace-handling block, you call replace.packageVersion() twice; capturing this in a local const auto &version = replace.packageVersion(); would avoid duplication and make the logic slightly clearer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In both new conditions, consider documenting the intended semantics of an empty version (e.g., treating it as ‘no version constraint’) so future readers understand why `isEmpty()` short-circuits the usual version comparison.
- In the replace-handling block, you call `replace.packageVersion()` twice; capturing this in a local `const auto &version = replace.packageVersion();` would avoid duplication and make the logic slightly clearer.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: LiHua000, lzwind

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

@LiHua000

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot

deepin-bot Bot commented Dec 18, 2025

Copy link
Copy Markdown
Contributor

This pr cannot be merged! (status: unstable)

@LiHua000

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot deepin-bot Bot merged commit c97f7a2 into linuxdeepin:master Dec 18, 2025
21 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.

3 participants