Skip to content

Conversation

@add-uos
Copy link
Contributor

@add-uos add-uos commented Dec 31, 2025

…enable

create udev rules directory when missing during keyboard enable or disable

log: create udev rules directory
bug: https://pms.uniontech.com/bug-view-346127.html

Summary by Sourcery

Bug Fixes:

  • Create the udev rules directory on demand during keyboard enable/disable to avoid failures when it does not already exist.

…enable

create udev rules directory when missing during keyboard enable or disable

log: create udev rules directory
bug: https://pms.uniontech.com/bug-view-346127.html
@sourcery-ai
Copy link

sourcery-ai bot commented Dec 31, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates keyboard enable logic to automatically create the udev rules directory if it is missing, adding info/warning logs and only failing when directory creation itself fails.

Sequence diagram for updated keyboard enable udev rules directory handling

sequenceDiagram
    participant ControlInterface
    participant QFileInfo
    participant QDir
    participant Logger

    ControlInterface->>QFileInfo: QFileInfo(rulesFile)
    QFileInfo-->>ControlInterface: fileInfo

    ControlInterface->>QDir: QDir rulesDir = fileInfo.absoluteDir()
    ControlInterface->>QDir: rulesDir.exists()
    QDir-->>ControlInterface: exists

    alt rulesDir does not exist
        ControlInterface->>Logger: qCInfo appLog "Udev rules directory does not exist, creating" rulesDir.absolutePath
        ControlInterface->>QDir: rulesDir.mkpath(".")
        QDir-->>ControlInterface: success
        alt mkpath failed
            ControlInterface->>Logger: qCWarning appLog "Failed to create udev rules directory" rulesDir.absolutePath
            ControlInterface-->>ControlInterface: return false
        else mkpath succeeded
            ControlInterface->>Logger: qCInfo appLog "Successfully created udev rules directory" rulesDir.absolutePath
            ControlInterface-->>ControlInterface: continue to open rulesFile
        end
    else rulesDir exists
        ControlInterface-->>ControlInterface: continue to open rulesFile
    end
Loading

File-Level Changes

Change Details Files
Automatically create the udev rules directory during keyboard enable instead of failing when it is missing, with additional logging around directory creation.
  • Replace early failure on missing udev rules directory with logic that attempts to create the directory using QDir::mkpath
  • Add informational logging before and after directory creation attempts
  • Add warning log and return false only when directory creation fails
deepin-devicemanager-server/deepin-devicecontrol/src/controlinterface.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

deepin pr auto review

我来对这段代码的修改进行审查:

  1. 语法逻辑:
  • 修改后的代码逻辑是正确的。当目录不存在时,会先尝试创建目录,而不是直接返回失败。
  • 使用了mkpath(".")来创建目录,这是Qt中创建目录的标准方法。
  1. 代码质量:
  • 优点:
    • 添加了适当的日志记录,便于问题追踪
    • 代码结构清晰,错误处理完整
  • 建议:
    • 可以考虑将目录创建的代码抽取为一个单独的函数,提高代码复用性
    • 日志信息可以考虑使用更详细的格式,比如包含时间戳
  1. 代码性能:
  • mkpath()函数会递归创建所有必要的父目录,这可能会带来一定的性能开销
  • 建议:如果确定父目录一定存在,可以使用mkdir()替代mkpath()以提高性能
  1. 代码安全:
  • 需要确保有足够的权限创建目录
  • 建议:在创建目录前检查权限,避免因权限不足导致的失败
  • 建议添加对目录创建后权限的验证

改进建议代码示例:

bool ControlInterface::ensureDirectoryExists(const QString& dirPath) {
    QDir dir(dirPath);
    if (dir.exists()) {
        return true;
    }

    // 检查权限
    QFileInfo parentDir(dir.absolutePath());
    if (!parentDir.isWritable()) {
        qCWarning(appLog) << "No permission to create directory:" << dir.absolutePath();
        return false;
    }

    qCInfo(appLog) << "Creating directory:" << dir.absolutePath();
    if (!dir.mkpath(".")) {
        qCWarning(appLog) << "Failed to create directory:" << dir.absolutePath();
        return false;
    }

    // 验证目录创建成功且可写
    if (!dir.exists() || !dir.isReadable()) {
        qCWarning(appLog) << "Directory created but not accessible:" << dir.absolutePath();
        return false;
    }

    qCInfo(appLog) << "Successfully created directory:" << dir.absolutePath();
    return true;
}

bool ControlInterface::enableKeyboard(const QString& vid, const QString& pid, const QString& serial) {
    // ... 其他代码 ...
    
    QFileInfo fileInfo(rulesFile);
    if (!ensureDirectoryExists(fileInfo.absolutePath())) {
        return false;
    }

    QFile file(rulesFile);
    // ... 继续处理 ...
}

这样的改进:

  1. 提高了代码的模块化程度
  2. 增强了错误处理和安全性
  3. 添加了更详细的权限检查
  4. 提供了更好的日志信息
  5. 使代码更容易维护和测试

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:

  • When creating the udev rules directory, consider calling rulesDir.mkpath(rulesDir.absolutePath()) instead of mkpath(".") to make the intent explicit and avoid relying on relative path semantics for QDir.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When creating the udev rules directory, consider calling `rulesDir.mkpath(rulesDir.absolutePath())` instead of `mkpath(".")` to make the intent explicit and avoid relying on relative path semantics for `QDir`.

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

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@add-uos
Copy link
Contributor Author

add-uos commented Dec 31, 2025

/merge

@deepin-bot deepin-bot bot merged commit 3b01762 into linuxdeepin:master Dec 31, 2025
18 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