Skip to content

Conversation

@18202781743
Copy link
Contributor

@18202781743 18202781743 commented Sep 4, 2025

  1. Added check to avoid prepending DDE_SHELL_QML_INSTALL_DIR if it
    already exists in import path list
  2. This prevents duplicate paths and maintains correct search order for
    QML imports
  3. The change ensures consistent behavior when environment variables add
    the same path
  4. Fixes issue where duplicate paths could cause import resolution
    problems

fix: 防止 QML 导入路径重复

  1. 添加检查避免在导入路径列表中已存在 DDE_SHELL_QML_INSTALL_DIR 时重复
    添加
  2. 防止路径重复并保持 QML 导入的正确搜索顺序
  3. 确保当环境变量添加相同路径时行为一致
  4. 修复重复路径可能导致导入解析问题的情况

Summary by Sourcery

Bug Fixes:

  • Avoid duplicate DDE_SHELL_QML_INSTALL_DIR and plugin directory paths in the QML import path list by verifying their presence before prepending.

1. Added check to avoid prepending DDE_SHELL_QML_INSTALL_DIR if it
already exists in import path list
2. This prevents duplicate paths and maintains correct search order for
QML imports
3. The change ensures consistent behavior when environment variables add
the same path
4. Fixes issue where duplicate paths could cause import resolution
problems

fix: 防止 QML 导入路径重复

1. 添加检查避免在导入路径列表中已存在 DDE_SHELL_QML_INSTALL_DIR 时重复
添加
2. 防止路径重复并保持 QML 导入的正确搜索顺序
3. 确保当环境变量添加相同路径时行为一致
4. 修复重复路径可能导致导入解析问题的情况
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码是对QML引擎导入路径设置的改进,我来分析一下:

  1. 语法逻辑:
  • 原代码直接将路径添加到列表开头,没有检查是否已存在
  • 改进后添加了contains()检查,避免重复添加相同路径
  • 逻辑更严谨,防止了可能的冗余路径
  1. 代码质量:
  • 改进后的代码更加健壮,避免了重复路径
  • 使用了条件判断,使代码意图更清晰
  • 保持了代码的可读性和维护性
  1. 代码性能:
  • 添加了contains()检查会带来轻微的性能开销,但影响很小
  • 避免了重复路径可能带来的潜在性能问题
  • 总体来说性能影响可以忽略不计
  1. 代码安全:
  • 防止了重复路径可能导致的问题
  • 避免了可能的路径冲突
  • 代码更加安全可靠

建议:

  1. 可以考虑将路径检查逻辑提取为一个单独的函数,提高代码复用性
  2. 可以添加日志记录,记录路径的添加情况,便于调试
  3. 考虑对路径进行有效性验证,确保路径存在且可访问

改进后的代码质量有明显提升,主要改进点在于增加了重复路径检查,使代码更加健壮和安全。这是一个很好的改进,避免了潜在的问题。

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 4, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This patch enhances the QML engine setup by adding guard checks before inserting key import paths into the engine’s path list. It ensures DDE_SHELL_QML_INSTALL_DIR and the local plugins directory are only prepended if they’re not already present, preventing duplicate entries and preserving the intended search order.

Sequence diagram for QML import path setup with duplicate prevention

sequenceDiagram
    participant DQmlEnginePrivate
    participant QQmlEngine
    participant QCoreApplication
    participant QDir
    DQmlEnginePrivate->>QQmlEngine: importPathList()
    QQmlEngine-->>DQmlEnginePrivate: returns paths
    DQmlEnginePrivate->>DQmlEnginePrivate: Check if paths contains DDE_SHELL_QML_INSTALL_DIR
    alt DDE_SHELL_QML_INSTALL_DIR not in paths
        DQmlEnginePrivate->>QQmlEnginePrivate: Prepend DDE_SHELL_QML_INSTALL_DIR
    end
    DQmlEnginePrivate->>QCoreApplication: applicationDirPath()
    QCoreApplication-->>DQmlEnginePrivate: returns rootDir
    DQmlEnginePrivate->>QDir: cd("../plugins")
    QDir-->>DQmlEnginePrivate: success/failure
    alt pluginDir.cd success
        DQmlEnginePrivate->>DQmlEnginePrivate: Check if paths contains pluginDir.absolutePath()
        alt pluginDir.absolutePath() not in paths
            DQmlEnginePrivate->>QQmlEnginePrivate: Prepend pluginDir.absolutePath()
        end
    end
    DQmlEnginePrivate->>QQmlEngine: setImportPathList(paths)
    DQmlEnginePrivate->>DQmlEnginePrivate: qCDebug(dsLog()) << importPathList()
Loading

File-Level Changes

Change Details Files
Prevent duplicate QML import paths
  • Added check to skip prepending DDE_SHELL_QML_INSTALL_DIR when already present
  • Added check to skip prepending pluginDir.absolutePath() when already present
frame/qmlengine.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

Copy link

@sourcery-ai sourcery-ai bot left a comment

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:

  • Consider normalizing import paths (e.g. via QDir::cleanPath or canonicalPath) before checking contains to avoid duplicates caused by differing path formats.
  • Instead of manually checking for duplicates before each prepend, consider assembling the list first and then using QStringList::removeDuplicates or a small helper to ensure uniqueness more succinctly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider normalizing import paths (e.g. via QDir::cleanPath or canonicalPath) before checking contains to avoid duplicates caused by differing path formats.
- Instead of manually checking for duplicates before each prepend, consider assembling the list first and then using QStringList::removeDuplicates or a small helper to ensure uniqueness more succinctly.

## Individual Comments

### Comment 1
<location> `frame/qmlengine.cpp:47` </location>
<code_context>
             QDir pluginDir(rootDir);
             if (pluginDir.cd("../plugins")) {
-                paths.prepend(pluginDir.absolutePath());
+                if (!paths.contains(pluginDir.absolutePath()))
+                    paths.prepend(pluginDir.absolutePath());
             }
             s_engine->setImportPathList(paths);
</code_context>

<issue_to_address>
Absolute path comparison may not account for symbolic links or path normalization.

Consider using canonicalPath() or normalizing paths before comparison to prevent duplicate entries due to symbolic links or differing path formats.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
            QDir pluginDir(rootDir);
            if (pluginDir.cd("../plugins")) {
                if (!paths.contains(pluginDir.absolutePath()))
                    paths.prepend(pluginDir.absolutePath());
            }
=======
            QDir pluginDir(rootDir);
            if (pluginDir.cd("../plugins")) {
                QString pluginCanonicalPath = pluginDir.canonicalPath();
                QStringList canonicalPaths;
                for (const QString &path : paths) {
                    QDir dir(path);
                    canonicalPaths << dir.canonicalPath();
                }
                if (!canonicalPaths.contains(pluginCanonicalPath))
                    paths.prepend(pluginCanonicalPath);
            }
>>>>>>> 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 45 to 49
QDir pluginDir(rootDir);
if (pluginDir.cd("../plugins")) {
paths.prepend(pluginDir.absolutePath());
if (!paths.contains(pluginDir.absolutePath()))
paths.prepend(pluginDir.absolutePath());
}
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Absolute path comparison may not account for symbolic links or path normalization.

Consider using canonicalPath() or normalizing paths before comparison to prevent duplicate entries due to symbolic links or differing path formats.

Suggested change
QDir pluginDir(rootDir);
if (pluginDir.cd("../plugins")) {
paths.prepend(pluginDir.absolutePath());
if (!paths.contains(pluginDir.absolutePath()))
paths.prepend(pluginDir.absolutePath());
}
QDir pluginDir(rootDir);
if (pluginDir.cd("../plugins")) {
QString pluginCanonicalPath = pluginDir.canonicalPath();
QStringList canonicalPaths;
for (const QString &path : paths) {
QDir dir(path);
canonicalPaths << dir.canonicalPath();
}
if (!canonicalPaths.contains(pluginCanonicalPath))
paths.prepend(pluginCanonicalPath);
}

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, mhduiy

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

@18202781743
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Sep 4, 2025

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit e0e0f88 into linuxdeepin:master Sep 4, 2025
7 of 10 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