Skip to content

Conversation

@ComixHe
Copy link
Contributor

@ComixHe ComixHe commented Oct 22, 2025

Summary by Sourcery

Consolidate XDG directory path retrieval across the codebase by merging home and standard dirs into unified functions and updating all consumers to use these new helpers

Enhancements:

  • Unify XDG directory handling by introducing getXDGDataMergedDirs, getXDGConfigMergedDirs, and getMimeDirs to consolidate home and system paths
  • Remove outdated getXDGSystemDirs function and redundant home-path insertion logic from data and config directory getters
  • Refactor getDesktopFileDirs, getAutoStartDirs, applicationmimeinfo, and ApplicationManager1Service to use the new merged directory functions for scanning and file lookup

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 22, 2025

Reviewer's Guide

This PR refactors XDG directory path handling by introducing unified merged directory functions (getXDGDataMergedDirs, getXDGConfigMergedDirs, getMimeDirs), removing redundant helpers, and updating all consumers to use these shared utilities for consistent path management.

Sequence diagram for getListFiles() using unified mimeDirs

sequenceDiagram
    participant "getListFiles()"
    participant "getMimeDirs()"
    participant "appendListFile()"
    "getListFiles()"->>"getMimeDirs()": Retrieve mimeDirs
    "getListFiles()"->>"appendListFile()": For each dir in mimeDirs
    "appendListFile()"->>"QFileInfo": Check if dir exists and is a directory
    "appendListFile()"->>"QDir": Build desktopList path
    "appendListFile()"->>"QFileInfo": Check if desktopList exists
    "appendListFile()"-->>"getListFiles()": Append desktopList if exists
    "getListFiles()"-->>"getListFiles()": Reverse files and return
Loading

Sequence diagram for scanMimeInfos() using getMimeDirs()

sequenceDiagram
    participant scanMimeInfos
    participant getMimeDirs
    participant MimeInfo_createMimeInfo
    scanMimeInfos->>getMimeDirs: Retrieve mimeDirs
    loop for each dir in mimeDirs
        scanMimeInfos->>MimeInfo_createMimeInfo: Create MimeInfo for dir
        alt info exists
            scanMimeInfos-->>scanMimeInfos: Add info to mimeInfos
        end
    end
Loading

Sequence diagram for loadHooks() using getXDGDataMergedDirs()

sequenceDiagram
    participant "loadHooks()"
    participant "getXDGDataMergedDirs()"
    "loadHooks()"->>"getXDGDataMergedDirs()": Retrieve hookDirs
    loop for each dir in hookDirs
        "loadHooks()"-->>"loadHooks()": Append ApplicationManagerHookDir
    end
Loading

Sequence diagram for doReloadApplications() using updated desktopFileDirs

sequenceDiagram
    participant "doReloadApplications()"
    participant "getDesktopFileDirs()"
    participant "getXDGConfigDirs()"
    "doReloadApplications()"->>"getDesktopFileDirs()": Retrieve desktopFileDirs
    "doReloadApplications()"->>"getXDGConfigDirs()": Append config dirs to desktopFileDirs
    "doReloadApplications()"-->>"doReloadApplications()": Continue reload logic
Loading

Class diagram for unified XDG directory path handling functions

classDiagram
    class global_h {
        +QString getXDGDataHome()
        +QStringList getXDGDataDirs()
        +QStringList getXDGDataMergedDirs()
        +QStringList getDesktopFileDirs()
        +QString getXDGConfigHome()
        +QStringList getXDGConfigDirs()
        +QStringList getXDGConfigMergedDirs()
        +QStringList getAutoStartDirs()
        +QStringList getMimeDirs()
    }
    global_h : -getXDGSystemDirs()  // removed
    global_h : getXDGDataMergedDirs() uses getXDGDataHome(), getXDGDataDirs()
    global_h : getXDGConfigMergedDirs() uses getXDGConfigHome(), getXDGConfigDirs()
    global_h : getDesktopFileDirs() uses getXDGDataMergedDirs()
    global_h : getAutoStartDirs() uses getXDGConfigMergedDirs()
    global_h : getMimeDirs() uses getXDGConfigMergedDirs(), getDesktopFileDirs()
Loading

File-Level Changes

Change Details Files
Introduce unified merged XDG directory functions and remove redundant helpers
  • Remove getXDGSystemDirs and inline manual merging in data/config dir getters
  • Add getXDGDataMergedDirs and getXDGConfigMergedDirs to prepend home dirs
  • Add getMimeDirs combining config merged dirs with desktop file dirs
  • Update getDesktopFileDirs and getAutoStartDirs to use merged helpers
src/global.h
Refactor MIME file enumeration to use unified merged directories
  • Replace separate config/data dir lists with getMimeDirs in getListFiles
  • Enforce const correctness on QFileInfo/QDir instances
  • Simplify directory iteration to use single merged list
src/applicationmimeinfo.cpp
Update ApplicationManager1Service to consume merged directory lists
  • Use getMimeDirs in scanMimeInfos instead of separate XDGConfig and desktop dirs
  • Switch loadHooks to getXDGDataMergedDirs for hook directory paths
  • Replace getXDGSystemDirs usage in doReloadApplications with getXDGConfigDirs
src/dbus/applicationmanager1service.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!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/global.h:411-417` </location>
<code_context>
     return XDGDataDirs;
 }

+inline QStringList getXDGDataMergedDirs()
+{
+    QStringList merged;
</code_context>

<issue_to_address>
**suggestion:** Consider deduplicating entries in getXDGDataMergedDirs.

Deduplicating the merged list will prevent redundant paths if getXDGDataHome() appears in getXDGDataDirs().

```suggestion
inline QStringList getXDGDataMergedDirs()
{
    QStringList merged;
    merged.append(getXDGDataHome());
    merged.append(getXDGDataDirs());
    merged.removeDuplicates();
    return merged;
}
```
</issue_to_address>

### Comment 2
<location> `src/global.h:452` </location>
<code_context>
     return XDGConfigDirs;
 }

+inline QStringList getXDGConfigMergedDirs()
+{
+    QStringList merged;
</code_context>

<issue_to_address>
**suggestion:** Consider deduplicating entries in getXDGConfigMergedDirs.

Merging getXDGConfigHome() and getXDGConfigDirs() can result in duplicate directories. Ensure the merged list contains only unique entries to avoid redundant processing.

Suggested implementation:

```c
inline QStringList getXDGConfigMergedDirs()
{
    QStringList merged;

```

```c
    merged.append(getXDGConfigHome());
    merged.append(getXDGConfigDirs());
    // Deduplicate entries
    QSet<QString> uniqueDirs = QSet<QString>(merged.begin(), merged.end());
    return QStringList(uniqueDirs.begin(), uniqueDirs.end());
}

```
</issue_to_address>

### Comment 3
<location> `src/dbus/applicationmanager1service.cpp:475-477` </location>
<code_context>
 void ApplicationManager1Service::loadHooks() noexcept
 {
-    auto hookDirs = getXDGDataDirs();
+    auto hookDirs = getXDGDataMergedDirs();
     std::for_each(hookDirs.begin(), hookDirs.end(), [](QString &str) { str.append(ApplicationManagerHookDir); });
     QHash<QString, ApplicationHook> hooks;
</code_context>

<issue_to_address>
**suggestion:** Switch to getXDGDataMergedDirs may introduce duplicate hook directories.

Deduplicate the merged list to prevent redundant processing of hook directories.

```suggestion
    auto hookDirs = getXDGDataMergedDirs();
    std::for_each(hookDirs.begin(), hookDirs.end(), [](QString &str) { str.append(ApplicationManagerHookDir); });
    // Deduplicate hookDirs to prevent redundant processing
    hookDirs = QList<QString>(QSet<QString>(hookDirs.begin(), hookDirs.end()).values());
    QHash<QString, ApplicationHook> hooks;
```
</issue_to_address>

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.

Comment on lines +475 to 477
auto hookDirs = getXDGDataMergedDirs();
std::for_each(hookDirs.begin(), hookDirs.end(), [](QString &str) { str.append(ApplicationManagerHookDir); });
QHash<QString, ApplicationHook> hooks;
Copy link

Choose a reason for hiding this comment

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

suggestion: Switch to getXDGDataMergedDirs may introduce duplicate hook directories.

Deduplicate the merged list to prevent redundant processing of hook directories.

Suggested change
auto hookDirs = getXDGDataMergedDirs();
std::for_each(hookDirs.begin(), hookDirs.end(), [](QString &str) { str.append(ApplicationManagerHookDir); });
QHash<QString, ApplicationHook> hooks;
auto hookDirs = getXDGDataMergedDirs();
std::for_each(hookDirs.begin(), hookDirs.end(), [](QString &str) { str.append(ApplicationManagerHookDir); });
// Deduplicate hookDirs to prevent redundant processing
hookDirs = QList<QString>(QSet<QString>(hookDirs.begin(), hookDirs.end()).values());
QHash<QString, ApplicationHook> hooks;

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, ComixHe

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 requested a review from Copilot October 23, 2025 02:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors XDG directory path handling by introducing unified "merged" directory functions that combine home and system paths, eliminating redundant logic scattered across the codebase. The change simplifies directory path retrieval by providing consistent helper functions (getXDGDataMergedDirs, getXDGConfigMergedDirs, getMimeDirs) that return complete directory lists in priority order.

Key changes:

  • Introduced three new merged directory functions that combine home and system XDG paths
  • Removed getXDGSystemDirs() function and refactored consumers to use appropriate XDG config directories
  • Updated all directory scanning code to use the new unified functions

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/global.h Adds merged directory helper functions and removes duplicate home-path insertion logic from getters
src/dbus/applicationmanager1service.cpp Updates scanMimeInfos, loadHooks, and doReloadApplications to use new merged directory functions
src/applicationmimeinfo.cpp Refactors getListFiles to use getMimeDirs instead of manually combining config and data directories

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@ComixHe ComixHe merged commit 6a3a48c into linuxdeepin:master Oct 23, 2025
16 of 17 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