Skip to content

Conversation

@18202781743
Copy link
Contributor

@18202781743 18202781743 commented Aug 20, 2025

Added DSG_DATA_DIRS environment variable setting in both dde-dconfig-
editor and dde-dconfig main functions
The variable is set to include both standard path (/usr/share/dsg) and
linglong container path (/var/lib/linglong/entries/share/dsg)
This ensures dconfig applications can access configuration files in both
standard and linglong environments
Maintains compatibility with dde-dconfig-daemon which already uses this
environment variable

fix: 为玲珑兼容性设置 DSG_DATA_DIRS 环境变量

在 dde-dconfig-editor 和 dde-dconfig 的主函数中添加了 DSG_DATA_DIRS 环境
变量设置
该变量包含标准路径 (/usr/share/dsg) 和玲珑容器路径 (/var/lib/linglong/
entries/share/dsg)
确保配置应用程序能够在标准环境和玲珑环境中访问配置文件
与已使用此环境变量的 dde-dconfig-daemon 保持兼容性

Summary by Sourcery

Bug Fixes:

  • Ensure dconfig applications can locate configuration files in both standard and Linglong environments by setting DSG_DATA_DIRS

Added DSG_DATA_DIRS environment variable setting in both dde-dconfig-
editor and dde-dconfig main functions
The variable is set to include both standard path (/usr/share/dsg) and
linglong container path (/var/lib/linglong/entries/share/dsg)
This ensures dconfig applications can access configuration files in both
standard and linglong environments
Maintains compatibility with dde-dconfig-daemon which already uses this
environment variable

fix: 为玲珑兼容性设置 DSG_DATA_DIRS 环境变量

在 dde-dconfig-editor 和 dde-dconfig 的主函数中添加了 DSG_DATA_DIRS 环境
变量设置
该变量包含标准路径 (/usr/share/dsg) 和玲珑容器路径 (/var/lib/linglong/
entries/share/dsg)
确保配置应用程序能够在标准环境和玲珑环境中访问配置文件
与已使用此环境变量的 dde-dconfig-daemon 保持兼容性
@18202781743 18202781743 requested review from BLumia and mhduiy August 20, 2025 04:27
@sourcery-ai
Copy link

sourcery-ai bot commented Aug 20, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR sets the DSG_DATA_DIRS environment variable at application startup in both dde-dconfig-editor and dde-dconfig to include standard and linglong container paths, ensuring consistent access to configuration files across environments.

Flow diagram for DSG_DATA_DIRS environment variable initialization

flowchart TD
    Start([Application Startup]) --> SetEnv[Set DSG_DATA_DIRS to /usr/share/dsg:/var/lib/linglong/entries/share/dsg]
    SetEnv --> InitApp[Initialize Application]
    InitApp --> AccessConfig[Access configuration files from both paths]
Loading

File-Level Changes

Change Details Files
Initialize DSG_DATA_DIRS environment variable in startup routines
  • Add setenv call for DSG_DATA_DIRS before DApplication is instantiated in dde-dconfig-editor main
  • Add setenv call for DSG_DATA_DIRS before QCoreApplication is instantiated in dde-dconfig main
dconfig-center/dde-dconfig-editor/main.cpp
dconfig-center/dde-dconfig/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 there - 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.

@deepin-ci-robot
Copy link

deepin pr auto review

我将对这段代码进行审查,主要关注语法逻辑、代码质量、性能和安全性。

代码审查意见

语法逻辑

  1. 代码语法正确,没有明显的语法错误。
  2. 两处修改都在main函数开始处添加了相同的setenv调用,用于设置环境变量DSG_DATA_DIRS

代码质量

  1. 重复代码:两个不同的main.cpp文件中出现了相同的setenv调用,这违反了DRY(Don't Repeat Yourself)原则。
  2. 硬编码路径:环境变量的值被硬编码为"/usr/share/dsg:/var/lib/linglong/entries/share/dsg",降低了代码的可维护性和灵活性。
  3. 错误处理缺失setenv调用没有检查返回值,如果设置失败,程序将继续执行而不做任何处理。

性能

  1. setenv操作在程序启动时只执行一次,对性能影响微乎其微,可以忽略不计。

安全性

  1. 路径安全性:硬编码的路径可能存在安全隐患。如果这些路径不存在或没有正确的权限,可能会导致程序运行异常。
  2. 环境变量覆盖:直接使用setenv会覆盖已存在的DSG_DATA_DIRS环境变量,这可能会影响其他依赖该环境变量的程序。
  3. 权限问题:程序是否有权限修改环境变量需要进一步确认。

改进建议

  1. 提取为公共函数

    // 可以放在一个公共的工具类中
    void setDsgDataDirs() {
        const char* dsgDirs = "/usr/share/dsg:/var/lib/linglong/entries/share/dsg";
        if (setenv("DSG_DATA_DIRS", dsgDirs, 0) != 0) {
            qWarning() << "Failed to set DSG_DATA_DIRS environment variable";
            // 可以考虑更严重的错误处理,如退出程序
        }
    }
  2. 使用配置文件管理路径

    // 从配置文件中读取路径,而不是硬编码
    QString getDsgDataDirs() {
        QSettings settings("your/company", "dde-dconfig");
        return settings.value("dsg/dirs", "/usr/share/dsg:/var/lib/linglong/entries/share/dsg").toString();
    }
    
    int main(int argc, char *argv[]) {
        setenv("DSG_DATA_DIRS", getDsgDataDirs().toUtf8().constData(), 0);
        // ...
    }
  3. 增加错误处理和日志记录

    int main(int argc, char *argv[]) {
        if (setenv("DSG_DATA_DIRS", "/usr/share/dsg:/var/lib/linglong/entries/share/dsg", 0) != 0) {
            qCritical() << "Failed to set DSG_DATA_DIRS environment variable";
            return EXIT_FAILURE;
        }
        
        // 继续程序初始化...
    }
  4. 考虑使用QProcessEnvironment(如果使用Qt):

    int main(int argc, char *argv[]) {
        QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
        env.insert("DSG_DATA_DIRS", "/usr/share/dsg:/var/lib/linglong/entries/share/dsg");
        QCoreApplication::setAttribute(Qt::AA_UseEnvironment, true);
        // ...
    }
  5. 添加路径验证

    bool isValidDsgPath(const QString& path) {
        QDir dir(path);
        return dir.exists() && dir.isReadable();
    }
    
    int main(int argc, char *argv[]) {
        QString dsgPath = "/usr/share/dsg:/var/lib/linglong/entries/share/dsg";
        if (!isValidDsgPath(dsgPath)) {
            qCritical() << "Invalid DSG path:" << dsgPath;
            return EXIT_FAILURE;
        }
        setenv("DSG_DATA_DIRS", dsgPath.toUtf8().constData(), 0);
        // ...
    }

总结

当前代码的主要问题是硬编码路径和缺乏错误处理。建议通过提取公共函数、使用配置文件、增加错误处理和路径验证等方式改进代码质量。同时,应考虑环境变量设置的副作用,确保不会影响程序的正常运行或其他依赖该环境变量的程序。

@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 18202781743 merged commit c573001 into linuxdeepin:master Aug 20, 2025
20 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