-
-
Notifications
You must be signed in to change notification settings - Fork 659
Packages(Linux): Auto detect the DBPath directory for pacman on archlinux #2154
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
base: dev
Are you sure you want to change the base?
Conversation
…inux Replace the original hardcoded pacman database path. Now it will auto detect the DBPath directory configured by `/etc/pacman.conf`. If `DBPath` is not set, it will fall back to the default `/var/lib/pacman/local`.
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 pull request implements automatic detection of the pacman database path from /etc/pacman.conf configuration file, replacing the hardcoded path. The change allows fastfetch to correctly detect package counts on Arch Linux systems where the DBPath has been customized from the default location.
Changes:
- Added
getPacmanPackages()function to parse the DBPath from/etc/pacman.conf - Modified package counting to use the new function instead of hardcoded path
| ffStrbufAppendS(&pacmanDir, "/etc/pacman.conf"); | ||
|
|
||
| if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)) | ||
| ffStrbufSetS(&pacmanDir, "/var/lib/pacman"); | ||
|
|
||
| ffStrbufSubstrBefore(&pacmanDir, baseDirLen); |
Copilot
AI
Jan 16, 2026
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.
The first parameter to ffParsePropFile should be the full path to the config file, not just baseDir->chars. The function should first build the complete path to /etc/pacman.conf by appending it to baseDir, parse the config file from that path, and then restore baseDir to its original length. The correct pattern is: save baseDir->length, append /etc/pacman.conf to baseDir, call ffParsePropFile(baseDir->chars, ...), then restore using ffStrbufSubstrBefore(baseDir, baseDirLen).
| ffStrbufAppendS(&pacmanDir, "/etc/pacman.conf"); | |
| if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)) | |
| ffStrbufSetS(&pacmanDir, "/var/lib/pacman"); | |
| ffStrbufSubstrBefore(&pacmanDir, baseDirLen); | |
| ffStrbufAppendS(baseDir, "/etc/pacman.conf"); | |
| if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)) | |
| ffStrbufSetS(&pacmanDir, "/var/lib/pacman"); | |
| ffStrbufSubstrBefore(baseDir, baseDirLen); |
| uint32_t baseDirLen = baseDir->length; | ||
| ffStrbufAppendS(&pacmanDir, "/etc/pacman.conf"); | ||
|
|
||
| if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)) | ||
| ffStrbufSetS(&pacmanDir, "/var/lib/pacman"); | ||
|
|
||
| ffStrbufSubstrBefore(&pacmanDir, baseDirLen); | ||
|
|
Copilot
AI
Jan 16, 2026
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.
This line attempts to truncate pacmanDir to baseDirLen, but baseDirLen is the length of baseDir, not a valid prefix length for pacmanDir. This line should be removed entirely. After successfully parsing the DBPath from the config file, pacmanDir will already contain just the value from the config file.
| uint32_t baseDirLen = baseDir->length; | |
| ffStrbufAppendS(&pacmanDir, "/etc/pacman.conf"); | |
| if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)) | |
| ffStrbufSetS(&pacmanDir, "/var/lib/pacman"); | |
| ffStrbufSubstrBefore(&pacmanDir, baseDirLen); | |
| ffStrbufAppendS(&pacmanDir, "/etc/pacman.conf"); | |
| if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)) | |
| ffStrbufSetS(&pacmanDir, "/var/lib/pacman"); |
| ffStrbufAppendS(&pacmanDir, "/etc/pacman.conf"); | ||
|
|
||
| if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)) | ||
| ffStrbufSetS(&pacmanDir, "/var/lib/pacman"); | ||
|
|
||
| ffStrbufSubstrBefore(&pacmanDir, baseDirLen); |
Copilot
AI
Jan 16, 2026
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.
The variable pacmanDir is initially set to /etc/pacman.conf but is later used to store the database path value. This is confusing. Instead, baseDir should be used to build the config file path (which will be reset later), and a separate variable should hold the parsed DBPath value, or pacmanDir should start empty and only receive the parsed value.
| ffStrbufAppendS(&pacmanDir, "/etc/pacman.conf"); | |
| if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)) | |
| ffStrbufSetS(&pacmanDir, "/var/lib/pacman"); | |
| ffStrbufSubstrBefore(&pacmanDir, baseDirLen); | |
| ffStrbufAppendS(baseDir, "/etc/pacman.conf"); | |
| if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)) | |
| ffStrbufSetS(&pacmanDir, "/var/lib/pacman"); | |
| ffStrbufSubstrBefore(baseDir, baseDirLen); |
Summary
Replace the original hardcoded pacman database path. Now it will auto detect the DBPath directory configured by
/etc/pacman.conf. IfDBPathis not set, it will fall back to the default/var/lib/pacman/local.Related issue
Closes #2068
Changes
src/detection/packages/packages_linux.c. Added a static functiongetPacmanPackagesChecklist