Skip to content

fix: Avoid hardcode binary path#197

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wangrong1069:pr0317
Mar 17, 2026
Merged

fix: Avoid hardcode binary path#197
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wangrong1069:pr0317

Conversation

@wangrong1069
Copy link
Contributor

@wangrong1069 wangrong1069 commented Mar 17, 2026

Avoid hardcoding executable file paths to improve portability.

Bug: linuxdeepin/developer-center#3374

Summary by Sourcery

Make disk manager processes rely on executable names rather than hardcoded absolute paths to improve portability.

Bug Fixes:

  • Allow dbus-send and deepin-diskmanager-authenticateProxy to be launched using PATH resolution instead of fixed /usr/bin locations.
  • Detect the front-end process exit by checking the executable basename instead of matching a hardcoded absolute path.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 17, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Replaces hardcoded absolute paths to binaries with portable lookups based on program name and relaxes a front-end process check to no longer depend on a fixed installation path.

Flow diagram for updated front-end quit check in checkFrontEndQuit

flowchart TD
    A[Start checkFrontEndQuit frontEndPid] --> B[Build frontEndExe as /proc/frontEndPid/exe]
    B --> C[Create QFileInfo info using frontEndExe]
    C --> D[Resolve targetPath = info.symLinkTarget]
    D --> E[Create QFileInfo targetInfo using targetPath]
    E --> F[Extract exeName = targetInfo.fileName]
    F --> G{exeName == deepin-diskmanager?}
    G -- Yes --> H[Do nothing, keep service running]
    G -- No --> I[Log warning Front-end process has quit]
    I --> J[Exit QCoreApplication with code 0]
    H --> K[End]
    J --> K[End]
Loading

File-Level Changes

Change Details Files
Use program names instead of hardcoded absolute paths when spawning helper processes.
  • Change QProcess::startDetached invocations for dbus-send to use the bare executable name
  • Change QProcess::startDetached invocation for deepin-diskmanager-authenticateProxy to use the bare executable name
application/main.cpp
application/widgets/mainwindow.cpp
Make front-end liveness check independent of fixed installation directory.
  • Replace comparison against a fixed /usr/bin/deepin-diskmanager path with a comparison of the resolved executable file name only
service/main.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 - I've left some high level feedback:

  • Relying on bare executable names for dbus-send and deepin-diskmanager-authenticateProxy shifts behavior to whatever is at the front of $PATH; if the intent is portability rather than configurability, consider resolving the full path once (e.g., via a config or helper) to avoid unexpected PATH hijacking or environment-dependent behavior in system contexts.
  • The dbus-send call sequence is duplicated in multiple places; consider extracting a small helper to construct and invoke this quit call so that arguments and behavior stay consistent if they need adjustment later.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Relying on bare executable names for `dbus-send` and `deepin-diskmanager-authenticateProxy` shifts behavior to whatever is at the front of `$PATH`; if the intent is portability rather than configurability, consider resolving the full path once (e.g., via a config or helper) to avoid unexpected PATH hijacking or environment-dependent behavior in system contexts.
- The `dbus-send` call sequence is duplicated in multiple places; consider extracting a small helper to construct and invoke this quit call so that arguments and behavior stay consistent if they need adjustment later.

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

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "application/main.cpp": [
        {
            "line": "    const QString acknowledgementLink = \"https://www.deepin.org/acknowledgments/deepin_reader\";",
            "line_number": 124,
            "rule": "S35",
            "reason": "Url link | c08ef69076"
        }
    ]
}

lzwind
lzwind previously approved these changes Mar 17, 2026
Avoid hardcoding executable file paths to improve portability.

Bug: linuxdeepin/developer-center#3374
@deepin-ci-robot
Copy link

deepin pr auto review

代码审查报告

我已对提供的 git diff 进行了仔细审查,以下是关于语法逻辑、代码质量、代码性能和代码安全的改进建议:

1. 版权年份更新

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

评价:这是一个简单的版权年份更新,将版权范围从2022年延长到2026年。这种做法是合理的,可以保持版权声明的有效性。

2. 移除绝对路径的改进

-proc.startDetached("/usr/bin/dbus-send", argList);
+proc.startDetached("dbus-send", argList);

评价:这是一个很好的改进,使用相对路径而非绝对路径有以下几个优点:

  • 提高可移植性:程序可以在非标准路径的系统上运行
  • 更好的灵活性:系统可以自由选择可执行文件的位置
  • 符合最佳实践:让系统环境变量(PATH)来决定可执行文件的位置

3. 进程路径比较的改进

-if (info.symLinkTarget() != "/usr/bin/deepin-diskmanager") {
+if (QFileInfo(info.symLinkTarget()).fileName() != "deepin-diskmanager") {

评价:这是一个很好的改进,原因如下:

  • 使用文件名而非完整路径进行比较,提高了代码的灵活性
  • 避免了硬编码路径,使代码更加可移植
  • 能够适应不同的安装路径

4. 潜在问题与改进建议

4.1 安全性问题

application/main.cpp 中,存在一个无限循环:

while (1) {
    // 循环查询后台服务是否已经启动
}

问题

  • 没有明确的退出条件
  • 没有超时机制
  • 可能导致程序挂起

建议

int maxAttempts = 30; // 最多尝试30次
int attemptCount = 0;
const int sleepInterval = 200; // 每次间隔200ms

while (attemptCount < maxAttempts) {
    // 检查服务是否已启动
    if (isServiceStarted()) {
        break;
    }
    QThread::msleep(sleepInterval);
    attemptCount++;
}

if (attemptCount >= maxAttempts) {
    qWarning() << "Service failed to start within expected time";
    // 处理超时情况
}

4.2 代码质量问题

在多个地方重复了相同的代码:

QString args = QString("--system --type=method_call --dest=com.deepin.diskmanager /com/deepin/diskmanager com.deepin.diskmanager.Quit");
QStringList argList = args.split(" ");
proc.startDetached("dbus-send", argList);

建议:将这段代码提取为一个函数:

void sendQuitSignal()
{
    QProcess proc;
    QStringList argList;
    argList << "--system" 
            << "--type=method_call" 
            << "--dest=com.deepin.diskmanager" 
            << "/com/deepin/diskmanager" 
            << "com.deepin.diskmanager.Quit";
    proc.startDetached("dbus-send", argList);
}

4.3 性能问题

service/main.cpp 中,每次检查前端进程是否退出时都会创建一个新的 QFileInfo 对象:

if (QFileInfo(info.symLinkTarget()).fileName() != "deepin-diskmanager") {

建议:如果这段代码在频繁调用的循环中,可以考虑缓存文件名或使用更高效的检查方法。

4.4 错误处理

在多处使用 startDetached 但没有检查返回值:

proc.startDetached("dbus-send", argList);

建议:添加错误处理:

if (!proc.startDetached("dbus-send", argList)) {
    qWarning() << "Failed to start dbus-send";
}

5. 总体评价

这次更改主要是改进了代码的可移植性和灵活性,移除了硬编码的绝对路径,这是一个好的实践。但代码中仍存在一些可以改进的地方,特别是在错误处理、代码重复和潜在的无限循环问题上。

建议在后续版本中考虑上述改进建议,以提高代码的健壮性和可维护性。

@github-actions
Copy link

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "application/main.cpp": [
        {
            "line": "    const QString acknowledgementLink = \"https://www.deepin.org/acknowledgments/deepin_reader\";",
            "line_number": 124,
            "rule": "S35",
            "reason": "Url link | c08ef69076"
        }
    ]
}

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@wangrong1069
Copy link
Contributor Author

/merge

@deepin-bot deepin-bot bot merged commit bbe9b50 into linuxdeepin:master Mar 17, 2026
22 checks passed
@wangrong1069 wangrong1069 deleted the pr0317 branch March 17, 2026 03:40
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