Skip to content

fix: make DConfig fully functional on Windows - #578

Open
kt286 wants to merge 1 commit into
linuxdeepin:masterfrom
kt286:fix/dconfig_on_windows
Open

fix: make DConfig fully functional on Windows#578
kt286 wants to merge 1 commit into
linuxdeepin:masterfrom
kt286:fix/dconfig_on_windows

Conversation

@kt286

@kt286 kt286 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor
  • Replace Unix-specific getuid()/getpwuid() with Windows equivalents using GetUserNameW() and MD5-based user ID generation
  • Fix path handling for cross-platform: support empty localPrefix, use ';' as path separator on Windows, fallback to QStandardPaths for DSG data directories on non-Linux
  • Move dconfigfile.cpp compilation and D_DSG_APP_DATA_FALLBACK definition out of LINUX-only block in CMake
  • Define D_DISABLE_DBUS_CONFIG instead of D_DISABLE_DCONFIG on non-Linux platforms

fix: 使 DConfig 在 Windows 上完整可用

  • 使用 GetUserNameW() 和基于 MD5 的用户 ID 生成替代 Unix 特有的 getuid()/getpwuid(),实现 Windows 平台用户标识
  • 修复跨平台路径处理:支持空 localPrefix、Windows 上使用分号作为 路径分隔符、非 Linux 平台通过 QStandardPaths 获取 DSG 数据目录
  • CMake 中将 dconfigfile.cpp 编译和 D_DSG_APP_DATA_FALLBACK 定义 移出仅限 Linux 的条件块
  • 非 Linux 平台定义 D_DISABLE_DBUS_CONFIG 而非 D_DISABLE_DCONFIG

Summary by Sourcery

Make DConfig fully operational on Windows by adding Windows-specific user identification, path handling, and build configuration support while preserving Linux behavior.

New Features:

  • Introduce Windows user ID generation based on the current username hash for DConfig caching.
  • Support Windows DSG data directories using QStandardPaths when DSG_DATA_DIRS is unset.

Bug Fixes:

  • Fix cross-platform path handling by supporting empty localPrefix and using the correct path separator per platform.
  • Ensure DConfig cache directories and warnings are computed correctly on non-Linux systems.

Enhancements:

  • Unify user home path resolution and XDG state path behavior across platforms instead of returning empty paths on non-Linux.
  • Provide a cross-platform implementation of getUserName that works on Linux, Windows, and other platforms.

Build:

  • Compile dconfigfile.cpp and apply D_DSG_APP_DATA_FALLBACK outside the Linux-only CMake block so they are available on all platforms.
  • Define D_DISABLE_DBUS_CONFIG rather than D_DISABLE_DCONFIG on non-Linux builds to only disable DBus-based configuration.

- Replace Unix-specific getuid()/getpwuid() with Windows equivalents
  using GetUserNameW() and MD5-based user ID generation
- Fix path handling for cross-platform: support empty localPrefix,
  use ';' as path separator on Windows, fallback to QStandardPaths
  for DSG data directories on non-Linux
- Move dconfigfile.cpp compilation and D_DSG_APP_DATA_FALLBACK
  definition out of LINUX-only block in CMake
- Define D_DISABLE_DBUS_CONFIG instead of D_DISABLE_DCONFIG
  on non-Linux platforms

fix: 使 DConfig 在 Windows 上完整可用

- 使用 GetUserNameW() 和基于 MD5 的用户 ID 生成替代 Unix 特有的
  getuid()/getpwuid(),实现 Windows 平台用户标识
- 修复跨平台路径处理:支持空 localPrefix、Windows 上使用分号作为
  路径分隔符、非 Linux 平台通过 QStandardPaths 获取 DSG 数据目录
- CMake 中将 dconfigfile.cpp 编译和 D_DSG_APP_DATA_FALLBACK 定义
  移出仅限 Linux 的条件块
- 非 Linux 平台定义 D_DISABLE_DBUS_CONFIG 而非 D_DISABLE_DCONFIG

@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.

Sorry @kt286, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kt286

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

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

Hi @kt286. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sourcery-ai

sourcery-ai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Reviewer's Guide

Make DConfig fully functional and buildable on Windows by replacing Linux-specific user identification and path handling logic with cross-platform/Windows equivalents, and adjusting CMake flags so DConfig is enabled and DBus config is disabled on non-Linux platforms.

Sequence diagram for FileBackend user cache creation on Linux vs Windows

sequenceDiagram
    participant FileBackend
    participant DConfigFile
    participant DConfigCache

    FileBackend->>DConfigFile: DConfigFile(owner->appId, owner->name, owner->subpath)
    alt Q_OS_LINUX
        FileBackend->>DConfigFile: createUserCache(getuid)
    else Q_OS_WIN
        FileBackend->>FileBackend: getWindowsUserId
        FileBackend->>DConfigFile: createUserCache(getWindowsUserId)
    end
    DConfigFile-->>FileBackend: DConfigCache pointer
    FileBackend->>DConfigCache: load(localPrefix)
    FileBackend->>DConfigFile: load(localPrefix)
Loading

File-Level Changes

Change Details Files
Introduce Windows-specific user identification and cache handling in DConfig and DConfigFile instead of relying on Unix getuid()/getpwuid().
  • Add Windows includes and guards in dconfigfile.cpp and dconfig.cpp
  • Implement getUserName() on Windows using GetUserNameW() and ignore uid parameter
  • Add getWindowsUserId() helper that hashes the Windows username with MD5 to produce a uint-like UID
  • Use getWindowsUserId() when creating user caches in FileBackend instead of getuid() on non-Linux platforms
  • Adjust home path resolution in DConfigCacheImpl to avoid getuid() on non-Linux platforms and rely on DStandardPaths::homePath()
src/dconfigfile.cpp
src/dconfig.cpp
Fix cross-platform path handling for DConfig meta and cache directories, including empty localPrefix and Windows path separator semantics.
  • Update DConfigMeta::genericMetaDirs() to treat empty localPrefix by omitting the prefix component when building paths
  • Update DConfigCacheImpl::getCacheDir() to handle empty localPrefix when constructing cache directory paths
  • Adjust warning logging in save() to avoid getuid() on non-Linux platforms and simplify message
  • Change DSG data dir resolution in DStandardPaths::paths() to use QStandardPaths::GenericDataLocation on non-Linux when DSG_DATA_DIRS is unset
  • Parse DSG_DATA_DIRS using ';' as separator on Windows and ':' elsewhere
  • Simplify XDG_STATE_HOME fallback in DStandardPaths::path() to always use ~/.local/state rather than returning empty on non-Linux
src/dconfigfile.cpp
src/filesystem/dstandardpaths.cpp
Make dconfigfile and DSG app data fallback compile on all platforms and ensure DBus config is disabled (rather than DConfig) on non-Linux.
  • Move dconfigfile.cpp and its header into the global OUTER_SOURCE/OUTER_HEADER lists outside the LINUX-only CMake block
  • Apply D_DSG_APP_DATA_FALLBACK definition unconditionally when provided instead of only on Linux
  • Change non-Linux build flag from D_DISABLE_DCONFIG to D_DISABLE_DBUS_CONFIG to keep DConfig enabled while disabling DBus integration
src/glob.cmake

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

Comment thread src/dconfigfile.cpp
// lower priority is higher.
for (auto item: DStandardPaths::paths(DStandardPaths::DSG::DataDir)) {
paths.prepend(QDir::cleanPath(QString("%1/%2/configs").arg(localPrefix, item)));
if (localPrefix.isEmpty()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

localPrefix 啥场景下会为空?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

正常场景下都会为空,这个是给玲珑环境准备的吧

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

举个例子

Linux环境中 item 是 /usr/share,localPrefix 是玲珑那个/perxxxx 的,如果不是玲珑环境就是 /usr/share/config 玲珑环境就是 /perxxxx/usr/share/config 这样都没问题

但是 Windows 下没有玲珑环境 localPrefix 默认为空 item 是一个 C:/xxx 这样的格式,拼接起来就变成了 /C:/xxx/config,这样的目录是解析不出来的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants