Skip to content

cherry-pick 2 commits of release/eagle#353

Closed
LiHua000 wants to merge 2 commits into
linuxdeepin:masterfrom
LiHua000:master
Closed

cherry-pick 2 commits of release/eagle#353
LiHua000 wants to merge 2 commits into
linuxdeepin:masterfrom
LiHua000:master

Conversation

@LiHua000

@LiHua000 LiHua000 commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

fix: correct package removal logic for Breaks/Conflicts dependencies (#318)
fix: 空值判断 (#348)

Summary by Sourcery

Fix package removal and conflict satisfaction logic by properly handling empty version constraints and centralising version-based comparisons

Bug Fixes:

  • Correct package removal logic for Breaks/Conflicts dependencies by checking version relations
  • Fix handling of empty conflict_version in conflict satisfaction checks

Enhancements:

  • Add needRemoveByVersion helper to centralise relation-based version comparison logic

log: 修复因冲突包无法安装的问题
…inuxdeepin#318)

1. Version check for package removal:
   - Add version comparison logic in setMarkedPackages method
   - Only add packages to removal list when version conditions are met
2. Improve dependency handling:
   - Fix incorrect handling of Breaks/Conflicts relationships
   - Ensure proper version comparison for all relation types

Log: Fix incorrect "Will remove" warning when installing packages
     with Breaks/Conflicts dependencies where installed version
     is higher than specified version.

Bug: https://pms.uniontech.com/bug-view-311145.html
@sourcery-ai

sourcery-ai Bot commented Sep 12, 2025

Copy link
Copy Markdown

Reviewer's Guide

Cherry-pick of two commits that correct package removal logic for Breaks/Conflicts dependencies and add null/empty value checks by extracting version-based removal logic into a helper and ensuring empty conflict versions are treated appropriately.

File-Level Changes

Change Details Files
Extract package removal logic into a dedicated helper and apply it when marking packages for removal
  • Add needRemoveByVersion to encapsulate empty-version and relation-based comparisons
  • Update setMarkedPackages to use needRemoveByVersion when filtering installed packages
src/deb-installer/utils/deb_package.cpp
Handle empty conflict_version in conflict satisfaction checks
  • Treat empty conflict_version as always unmet conflict
  • Augment isConflictSatisfy to skip packages when conflict_version.isEmpty() or version check fails
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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

我来审查这段代码,并提出一些改进意见:

  1. 代码逻辑和功能:
  • 新增的 needRemoveByVersion 函数用于判断是否需要根据版本条件移除包,逻辑清晰完整
  • setMarkedPackages 中增加了版本检查条件,提高了判断的准确性
  • 对空版本字符串的处理增加了保护,避免了潜在的空指针异常
  1. 代码质量:
  • 代码格式规范,缩进和空格使用一致
  • 函数命名清晰,表达了其功能
  • 使用了 QApt 库的枚举类型,保持了与库的一致性
  1. 性能考虑:
  • 版本比较操作可能会频繁执行,可以考虑缓存比较结果
  • needRemoveByVersion 函数中的 switch 语句可以优化为查找表以提高性能
  1. 安全性:
  • conflict_version 进行了空字符串检查,提高了安全性
  • 使用 QApt 库提供的版本比较函数,避免了手动解析版本号可能带来的安全问题
  1. 改进建议:
  • needRemoveByVersion 函数中,默认返回 true 可能不够明确,可以考虑抛出异常或返回 false
  • 可以添加注释说明函数的预期行为和边界条件
  • 对于 needRemoveByVersion 函数,可以考虑使用 std::unordered_map 或类似结构来优化 switch 语句的性能
  1. 其他建议:
  • 考虑添加单元测试来验证 needRemoveByVersion 函数的各种情况
  • 可以考虑将版本比较逻辑封装成一个独立的类,便于维护和扩展

总体来说,这段代码的改进提高了版本检查的准确性和健壮性,但在性能优化和错误处理方面还有提升空间。

@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 and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/deb-installer/utils/deb_package.cpp:29` </location>
<code_context>
+    const int result = QApt::Package::compareVersion(installed_version, conflict_version);
+
+    // 根据关系类型判断是否需要移除
+    switch (type) {
+    case QApt::LessOrEqual:
+        return result <= 0;
+    case QApt::GreaterOrEqual:
+        return result >= 0;
+    case QApt::LessThan:
+        return result < 0;
+    case QApt::GreaterThan:
+        return result > 0;
+    case QApt::Equals:
+        return result == 0;
+    case QApt::NotEqual:
+        return result != 0;
+    default:
+        return true;
+    }
</code_context>

<issue_to_address>
Default case in switch returns true, which may mask unexpected relation types.

Returning true for unknown relation types may cause unintended package removals. Please handle unexpected types explicitly or add logging to prevent silent errors.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    switch (type) {
    case QApt::LessOrEqual:
        return result <= 0;
    case QApt::GreaterOrEqual:
        return result >= 0;
    case QApt::LessThan:
        return result < 0;
    case QApt::GreaterThan:
        return result > 0;
    case QApt::Equals:
        return result == 0;
    case QApt::NotEqual:
        return result != 0;
    default:
        return true;
    }
=======
    switch (type) {
    case QApt::LessOrEqual:
        return result <= 0;
    case QApt::GreaterOrEqual:
        return result >= 0;
    case QApt::LessThan:
        return result < 0;
    case QApt::GreaterThan:
        return result > 0;
    case QApt::Equals:
        return result == 0;
    case QApt::NotEqual:
        return result != 0;
    default:
        qWarning() << "Unknown relation type in deb_package.cpp:" << type << ". No removal performed.";
        return false;
    }
>>>>>>> REPLACE

</suggested_fix>

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.

Comment on lines +29 to +44
switch (type) {
case QApt::LessOrEqual:
return result <= 0;
case QApt::GreaterOrEqual:
return result >= 0;
case QApt::LessThan:
return result < 0;
case QApt::GreaterThan:
return result > 0;
case QApt::Equals:
return result == 0;
case QApt::NotEqual:
return result != 0;
default:
return true;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (bug_risk): Default case in switch returns true, which may mask unexpected relation types.

Returning true for unknown relation types may cause unintended package removals. Please handle unexpected types explicitly or add logging to prevent silent errors.

Suggested change
switch (type) {
case QApt::LessOrEqual:
return result <= 0;
case QApt::GreaterOrEqual:
return result >= 0;
case QApt::LessThan:
return result < 0;
case QApt::GreaterThan:
return result > 0;
case QApt::Equals:
return result == 0;
case QApt::NotEqual:
return result != 0;
default:
return true;
}
switch (type) {
case QApt::LessOrEqual:
return result <= 0;
case QApt::GreaterOrEqual:
return result >= 0;
case QApt::LessThan:
return result < 0;
case QApt::GreaterThan:
return result > 0;
case QApt::Equals:
return result == 0;
case QApt::NotEqual:
return result != 0;
default:
qWarning() << "Unknown relation type in deb_package.cpp:" << type << ". No removal performed.";
return false;
}

@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 Sep 12, 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 commented Sep 18, 2025

Copy link
Copy Markdown
Contributor

This pr cannot be merged! (status: unstable)

@LiHua000 LiHua000 closed this Sep 18, 2025
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