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 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
@CarterLi
Copy link
Member

What about RootDir and Bedrock?

@It-is-Sean
Copy link
Author

It-is-Sean commented Jan 17, 2026

Hi! First, I've checked up arch wiki and found that wiki states for DBPath:

"NOTE: if specified, this is an absolute path and the root path is not automatically prepended."

Thus, I suppose if DBPath exists, RootDir is irrelevant according to the docs.

And for the cases when DBPath doesn't exist and RootDir is specified, we can just use [RootDir]/var/lib/pacman/local as the pacmanDir.

Meanwhile, for bedrock, I think getNumElements() will prepend baseDir and would fix the problem, so the final path would be [baseDir][pacmanDir]. I'll try and make another commit.

@fastfetch-cli fastfetch-cli deleted a comment from Copilot AI Jan 17, 2026
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

2 participants