Skip to content

feat(session): add XDG_CONFIG_DIRS with /usr/share/kwin/xdg fallback - #226

Open
justforlxz wants to merge 1 commit into
linuxdeepin:masterfrom
justforlxz:xdg-config-dirs
Open

feat(session): add XDG_CONFIG_DIRS with /usr/share/kwin/xdg fallback#226
justforlxz wants to merge 1 commit into
linuxdeepin:masterfrom
justforlxz:xdg-config-dirs

Conversation

@justforlxz

@justforlxz justforlxz commented Aug 18, 2026

Copy link
Copy Markdown
Member

Add /usr/share/kwin/xdg to XDG_CONFIG_DIRS in both profile.d script and EnvironmentsManager C++ code to support KConfig file fallback.

PMS: TASK-377491

Summary by Sourcery

New Features:

  • Add /usr/share/kwin/xdg as an XDG configuration search path to enable KConfig fallback support.

Add /usr/share/kwin/xdg to XDG_CONFIG_DIRS in both profile.d script
and EnvironmentsManager C++ code to support KConfig file fallback.

在profile.d脚本和EnvironmentsManager C++代码中添加
XDG_CONFIG_DIRS,包含/usr/share/kwin/xdg回退路径。

Log: 添加XDG_CONFIG_DIRS支持KConfig配置文件回退
PMS: TASK-377491
Influence: 系统启动后XDG_CONFIG_DIRS包含/usr/share/kwin/xdg,KDE配置可级联回退。
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: justforlxz

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

@sourcery-ai

sourcery-ai Bot commented Aug 18, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds /usr/share/kwin/xdg as a fallback/config directory for XDG_CONFIG_DIRS in both the session environment manager and profile.d script, ensuring consistent KConfig fallback behavior across login paths.

Sequence diagram for XDG_CONFIG_DIRS initialization with kwin fallback

sequenceDiagram
    actor User
    participant LoginShell
    participant deepin_xdg_dir_sh
    participant SessionManager
    participant EnvironmentsManager
    participant KConfig

    User->>LoginShell: start_session
    LoginShell->>deepin_xdg_dir_sh: source deepin-xdg-dir.sh
    deepin_xdg_dir_sh-->>LoginShell: export XDG_CONFIG_DIRS

    LoginShell->>SessionManager: start_session_manager
    SessionManager->>EnvironmentsManager: createGeneralEnvironments
    EnvironmentsManager->>EnvironmentsManager: createGeneralEnvironments
    alt [XDG_CONFIG_DIRS is empty]
        EnvironmentsManager-->>EnvironmentsManager: set XDG_CONFIG_DIRS=/etc/xdg:/usr/share/kwin/xdg
    else [XDG_CONFIG_DIRS is set]
        EnvironmentsManager-->>EnvironmentsManager: append :/usr/share/kwin/xdg to XDG_CONFIG_DIRS
    end

    EnvironmentsManager->>KConfig: read config using XDG_CONFIG_DIRS
Loading

File-Level Changes

Change Details Files
Ensure XDG_CONFIG_DIRS always includes /usr/share/kwin/xdg in session-managed environments.
  • Read existing XDG_CONFIG_DIRS value from the environment map.
  • If XDG_CONFIG_DIRS is empty, initialize it to /etc/xdg:/usr/share/kwin/xdg.
  • If XDG_CONFIG_DIRS is non-empty, append :/usr/share/kwin/xdg to the existing value.
  • Reinsert the computed XDG_CONFIG_DIRS value back into the environment map.
src/dde-session/environmentsmanager.cpp
Extend login shell environment to include /usr/share/kwin/xdg in XDG_CONFIG_DIRS.
  • Export XDG_CONFIG_DIRS with default /etc/xdg when unset and always appending :/usr/share/kwin/xdg in the profile script.
misc/profile.d/deepin-xdg-dir.sh

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

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:

  • The logic to append /usr/share/kwin/xdg to XDG_CONFIG_DIRS is duplicated between the C++ code and the profile script; consider centralizing this path in a single shared definition or at least a common constant to avoid divergence in future changes.
  • In EnvironmentsManager::createGeneralEnvironments, you unconditionally append :/usr/share/kwin/xdg if XDG_CONFIG_DIRS is non-empty; it may be worth checking whether the path is already present to avoid duplicating it when the environment is preconfigured.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The logic to append `/usr/share/kwin/xdg` to `XDG_CONFIG_DIRS` is duplicated between the C++ code and the profile script; consider centralizing this path in a single shared definition or at least a common constant to avoid divergence in future changes.
- In `EnvironmentsManager::createGeneralEnvironments`, you unconditionally append `:/usr/share/kwin/xdg` if `XDG_CONFIG_DIRS` is non-empty; it may be worth checking whether the path is already present to avoid duplicating it when the environment is preconfigured.

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

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码实现了KWin XDG配置目录路径的补全,逻辑严谨无安全风险
语法正确且使用现代C++特性,因缺少路径去重检查扣5分

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

environmentsmanager.cppcreateGeneralEnvironments() 函数中,通过判断 XDG_CONFIG_DIRS 是否为空来决定是初始化还是追加路径,逻辑通顺,语法无误。
潜在问题:若系统中已有其他进程或脚本预先设置了包含 /usr/share/kwin/xdgXDG_CONFIG_DIRS,此代码会导致该路径重复追加。
建议:在追加前进行简单的字符串包含检查,避免路径重复。

  • 2.代码质量(良好)✓

C++ 代码使用独立代码块 {} 限制局部变量 xdgConfigDirs 的作用域,防止变量名污染外层上下文;使用 QStringLiteral 宏进行字符串字面量优化;Shell 脚本使用 ${XDG_CONFIG_DIRS:-/etc/xdg} 标准参数扩展,符合最佳实践。
潜在问题:无
建议:无

  • 3.代码性能(无性能问题)✓

代码仅涉及简单的字符串读取、判空与拼接操作,且操作对象为极短的环境变量字符串,耗时与内存开销均可忽略不计。

建议:无

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码中涉及的所有路径均为硬编码的绝对路径常量,未引入任何外部用户输入,不存在路径遍历、命令注入等风险。

  • 建议:保持当前的硬编码常量拼接方式,避免后续维护时引入动态拼接逻辑。

■ 【改进建议代码示例】

    {
        QString xdgConfigDirs = m_envMap.value("XDG_CONFIG_DIRS");
        const QString kwinXdgPath = QStringLiteral("/usr/share/kwin/xdg");
        if (xdgConfigDirs.isEmpty()) {
            xdgConfigDirs = QStringLiteral("/etc/xdg:") + kwinXdgPath;
        } else if (!xdgConfigDirs.contains(kwinXdgPath)) {
            xdgConfigDirs += QStringLiteral(":") + kwinXdgPath;
        }
        m_envMap.insert("XDG_CONFIG_DIRS", xdgConfigDirs);
    }

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.

2 participants