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.

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

ffStrbufAppendS(baseDir, "/etc/pacman.conf");

// Get DBPath for packages
// If DBpath is specified
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

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

Comment has a typo: "DBpath" should be "DBPath" to match the actual configuration option name used in pacman.conf and elsewhere in the code (see line 425 where "DBPath =" is used).

Suggested change
// If DBpath is specified
// If DBPath is specified

Copilot uses AI. Check for mistakes.
Comment on lines 424 to 426
// If DBpath is specified
if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)){
// If DBpath is not specified and RootDir is specified
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

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

Comment has a typo: "DBpath" should be "DBPath" to match the actual configuration option name used in pacman.conf and elsewhere in the code (see line 425 where "DBPath =" is used).

Suggested change
// If DBpath is specified
if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)){
// If DBpath is not specified and RootDir is specified
// If DBPath is specified
if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)){
// If DBPath is not specified and RootDir is specified

Copilot uses AI. Check for mistakes.
Comment on lines 424 to 426
// If DBpath is specified
if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)){
// If DBpath is not specified and RootDir is specified
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

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

Comment has a typo: "DBpath" should be "DBPath" to match the actual configuration option name used in pacman.conf and elsewhere in the code (see line 425 where "DBPath =" is used).

Suggested change
// If DBpath is specified
if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)){
// If DBpath is not specified and RootDir is specified
// If DBPath is specified
if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)){
// If DBPath is not specified and RootDir is specified

Copilot uses AI. Check for mistakes.
Comment on lines 425 to 433
if (!ffParsePropFile(baseDir->chars, "DBPath =", &pacmanDir)){
// If DBpath is not specified and RootDir is specified
if (!ffParsePropFile(baseDir->chars, "RootDir =", &pacmanDir))
// If both are not specified
ffStrbufClear(&pacmanDir);

ffStrbufTrimRight(&pacmanDir, '/');
ffStrbufAppendS(&pacmanDir, "/var/lib/pacman");
}
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

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

The logic for handling the pacman.conf parsing is incorrect. The function ffParsePropFile returns true if the file exists (regardless of whether the property was found), and false only if the file doesn't exist.

The current implementation has the following issues:

  1. When the file doesn't exist, line 425 enters the if block, then line 427 tries to parse the same non-existent file again for "RootDir", which will always fail.
  2. When the file exists but DBPath is not specified, line 425 won't enter the if block, skipping the RootDir fallback logic entirely.

The correct logic should be:

  • First check if the file exists
  • If it exists, try to parse DBPath
  • If DBPath is not found (buffer is empty), try RootDir and append "/var/lib/pacman"
  • If RootDir is also not found (buffer is empty), use the default "/var/lib/pacman"
  • If the file doesn't exist, use the default "/var/lib/pacman"

Copilot uses AI. Check for mistakes.
@CarterLi
Copy link
Member

Needs testing on Bedrock

@It-is-Sean
Copy link
Author

I'm setting up a VM to test this out and will share you the results later. Any help from Bedrock Linux users are welcome.

@It-is-Sean
Copy link
Author

I did a test with a bedrock linux in a VM with Archlinux Strat and Ubuntu Strat. It seems that everything works when using bedrock linux and run fast fetch under the both stratas

image image

@CarterLi
Copy link
Member

What if you set DBPath or RootDir in Archlinux Strat?

@CarterLi
Copy link
Member

Can you help to test #2155?

@It-is-Sean
Copy link
Author

ok, working on it

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