Skip to content

Fix: Remove useless code.#619

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
GongHeng2017:202603171103-master-fix
Mar 17, 2026
Merged

Fix: Remove useless code.#619
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
GongHeng2017:202603171103-master-fix

Conversation

@GongHeng2017
Copy link
Copy Markdown
Contributor

@GongHeng2017 GongHeng2017 commented Mar 17, 2026

-- Remove useless code.

Log: fix issue
Bug: https://pms.uniontech.com/bug-view-352671.html

Summary by Sourcery

Enhancements:

  • Clean up CommonTools by deleting the unused getGpuInfoCommandFromDConfig API and its declaration.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Mar 17, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR removes an unused helper method for retrieving a GPU info command from DConfig, simplifying the CommonTools interface to only expose the GPU info pre-generation API that is actually used.

Class diagram for CommonTools before removal of getGpuInfoCommandFromDConfig

classDiagram
    class CommonTools {
        +static QString getBackupPath()
        +static void parseEDID(const QStringList allEDIDS, const QString input, bool isHW)
        +static QString getGpuInfoCommandFromDConfig()
        +static QString preGenerateGpuInfo()
    }
Loading

Updated class diagram for CommonTools after removal of getGpuInfoCommandFromDConfig

classDiagram
    class CommonTools {
        +static QString getBackupPath()
        +static void parseEDID(const QStringList allEDIDS, const QString input, bool isHW)
        +static QString preGenerateGpuInfo()
    }
Loading

File-Level Changes

Change Details Files
Remove unused GPU info command lookup helper and its declaration from CommonTools.
  • Delete the static CommonTools::getGpuInfoCommandFromDConfig implementation that created a DConfig instance and read the CommandToGetGPUInfo key.
  • Remove the corresponding static method declaration from the CommonTools class interface, leaving preGenerateGpuInfo as the primary GPU-related helper.
deepin-devicemanager/src/Tool/commontools.cpp
deepin-devicemanager/src/Tool/commontools.h

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
Copy Markdown

@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 - I've reviewed your changes and they look great!


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.

@github-actions
Copy link
Copy Markdown

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "deepin-devicemanager/src/Tool/commontools.cpp": [
        {
            "line": "        return \"https://driver.uniontech.com/api/v1/drive/search\";",
            "line_number": 177,
            "rule": "S35",
            "reason": "Url link | 162cef9d4a"
        },
        {
            "line": "        return \"https://driver.uniontech.com/api/v1/drive/search\";",
            "line_number": 182,
            "rule": "S35",
            "reason": "Url link | 162cef9d4a"
        },
        {
            "line": "        return \"https://drive-pre.uniontech.com/api/v1/drive/search\";",
            "line_number": 185,
            "rule": "S35",
            "reason": "Url link | 0e010283c1"
        }
    ]
}

Copy link
Copy Markdown
Contributor

@lzwind lzwind left a comment

Choose a reason for hiding this comment

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

改下年份

@GongHeng2017 GongHeng2017 force-pushed the 202603171103-master-fix branch from 6115ac8 to f3ed0e6 Compare March 17, 2026 03:16
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码diff主要涉及两个文件的修改:

  1. commontools.cpp:删除了 getGpuInfoCommandFromDConfig() 函数的实现,并更新了版权年份。
  2. commontools.h:删除了 getGpuInfoCommandFromDConfig() 函数的声明。

下面是对这些修改的详细审查意见:

1. 版权信息更新

-// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
+// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.

审查意见

  • ✅ 合理:更新版权年份是常规维护操作,表示代码将持续维护到2026年。
  • ⚠️ 建议:如果这是自动生成的代码,可以考虑使用动态年份(如2022 - [CurrentYear]),避免每年手动更新。

2. 删除 getGpuInfoCommandFromDConfig() 函数

-QString CommonTools::getGpuInfoCommandFromDConfig()
-{
-    QString cmd;
-    DConfig *dconfig = DConfig::create("org.deepin.devicemanager","org.deepin.devicemanager");
-    if (dconfig && dconfig->isValid() && dconfig->keyList().contains("CommandToGetGPUInfo"))
-        cmd = dconfig->value("CommandToGetGPUInfo").toString();
-    return cmd;
-}

审查意见

  • ✅ 合理:如果该函数不再被使用,删除它是正确的做法,避免死代码。
  • ⚠️ 潜在问题:删除该函数前,需要确认:
    1. 该函数是否在其他地方被调用?(建议全局搜索)
    2. 是否有替代方案来获取GPU信息命令?
    3. 如果该功能被移除,是否会影响GPU信息的获取逻辑?

3. 代码质量与性能分析

原函数存在以下问题:

  1. 内存泄漏风险

    • DConfig::create() 返回的指针未被释放,可能导致内存泄漏。
    • 建议使用智能指针(如QScopedPointer)或手动delete
  2. 重复创建DConfig对象

    • 如果该函数被频繁调用,每次都会创建新的DConfig对象,影响性能。
    • 建议将DConfig对象缓存为静态成员或单例。
  3. 字符串比较效率

    • dconfig->keyList().contains("CommandToGetGPUInfo") 会遍历整个键列表,效率较低。
    • 建议直接调用dconfig->value("CommandToGetGPUInfo"),并检查返回值是否有效。

4. 改进建议(如果需要保留类似功能)

如果未来需要类似功能,建议重构为:

QString CommonTools::getGpuInfoCommandFromDConfig()
{
    static DConfig *dconfig = DConfig::create("org.deepin.devicemanager", "org.deepin.devicemanager");
    static bool initialized = false;
    
    if (!initialized && dconfig && dconfig->isValid()) {
        initialized = true;
    }
    
    if (initialized) {
        return dconfig->value("CommandToGetGPUInfo").toString();
    }
    return QString();
}

改进点:

  1. 使用静态变量避免重复创建DConfig对象。
  2. 简化键检查逻辑,直接读取值。
  3. 避免内存泄漏(静态变量在程序结束时自动释放)。

5. 安全性审查

  1. 命令注入风险

    • 如果CommandToGetGPUInfo的值来自用户输入或配置文件,直接执行可能导致命令注入。
    • 建议对返回的命令进行白名单验证或转义。
  2. 配置文件安全性

    • 确保DConfig的配置文件权限正确,避免被恶意修改。

总结

  • 删除操作合理:如果该函数确实不再被使用,删除是正确的。
  • 潜在风险:需确认GPU信息获取逻辑是否受影响。
  • 未来改进:如需类似功能,建议重构以提高性能和安全性。

如果需要进一步分析或补充代码,请提供更多上下文(如preGenerateGpuInfo()的实现)。

@github-actions
Copy link
Copy Markdown

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "deepin-devicemanager/src/Tool/commontools.cpp": [
        {
            "line": "        return \"https://driver.uniontech.com/api/v1/drive/search\";",
            "line_number": 177,
            "rule": "S35",
            "reason": "Url link | 162cef9d4a"
        },
        {
            "line": "        return \"https://driver.uniontech.com/api/v1/drive/search\";",
            "line_number": 182,
            "rule": "S35",
            "reason": "Url link | 162cef9d4a"
        },
        {
            "line": "        return \"https://drive-pre.uniontech.com/api/v1/drive/search\";",
            "line_number": 185,
            "rule": "S35",
            "reason": "Url link | 0e010283c1"
        }
    ]
}

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017, 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

@GongHeng2017
Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot Bot commented Mar 17, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot Bot merged commit 8509a18 into linuxdeepin:master Mar 17, 2026
21 of 22 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