Skip to content

Conversation

@It-is-Sean
Copy link

Summary

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.

Related issue

Closes #2068

Changes

  • Modified src/detection/packages/packages_linux.c. Added a static function getPacmanPackages

Checklist

  • I have tested my changes locally.

…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`.
Copy link
Contributor

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

Comment on lines 421 to 426
ffStrbufAppendS(&pacmanDir, "/etc/pacman.conf");

if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir))
ffStrbufSetS(&pacmanDir, "/var/lib/pacman");

ffStrbufSubstrBefore(&pacmanDir, baseDirLen);
Copy link

Copilot AI Jan 16, 2026

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

Suggested change
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);

Copilot uses AI. Check for mistakes.
Comment on lines 420 to 427
uint32_t baseDirLen = baseDir->length;
ffStrbufAppendS(&pacmanDir, "/etc/pacman.conf");

if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir))
ffStrbufSetS(&pacmanDir, "/var/lib/pacman");

ffStrbufSubstrBefore(&pacmanDir, baseDirLen);

Copy link

Copilot AI Jan 16, 2026

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.

Suggested change
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");

Copilot uses AI. Check for mistakes.
Comment on lines 421 to 426
ffStrbufAppendS(&pacmanDir, "/etc/pacman.conf");

if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir))
ffStrbufSetS(&pacmanDir, "/var/lib/pacman");

ffStrbufSubstrBefore(&pacmanDir, baseDirLen);
Copy link

Copilot AI Jan 16, 2026

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
@It-is-Sean It-is-Sean marked this pull request as draft January 16, 2026 16:03
@It-is-Sean It-is-Sean marked this pull request as ready for review January 16, 2026 16:15
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.

[BUG] Pacman packages do not show on systems with a different DBPath directory

1 participant