-
Notifications
You must be signed in to change notification settings - Fork 41
refactor: unify XDG directory path handling with merged directory functions #297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ctions Signed-off-by: ComixHe <[email protected]>
Reviewer's GuideThis 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 mimeDirssequenceDiagram
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
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
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
Sequence diagram for doReloadApplications() using updated desktopFileDirssequenceDiagram
participant "doReloadApplications()"
participant "getDesktopFileDirs()"
participant "getXDGConfigDirs()"
"doReloadApplications()"->>"getDesktopFileDirs()": Retrieve desktopFileDirs
"doReloadApplications()"->>"getXDGConfigDirs()": Append config dirs to desktopFileDirs
"doReloadApplications()"-->>"doReloadApplications()": Continue reload logic
Class diagram for unified XDG directory path handling functionsclassDiagram
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()
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| auto hookDirs = getXDGDataMergedDirs(); | ||
| std::for_each(hookDirs.begin(), hookDirs.end(), [](QString &str) { str.append(ApplicationManagerHookDir); }); | ||
| QHash<QString, ApplicationHook> hooks; |
There was a problem hiding this comment.
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.
| 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; |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this 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.
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: