Skip to content

Conversation

@pebolle
Copy link

@pebolle pebolle commented Jun 12, 2025

This is an attempt at fixing issue #129. I've tried to keep it as simple as possible.

Note that this small series will make popt check both XDG_CONFIG_HOME/popt and ~/.popt. It is explained is some detail in the commit description, comments and in popt.3.

Speaking about popt.3: I gave up on understanding the groff, nroff, troff or whatever formatting stuff. It renders OK on my machine, but that might be just dumb luck.

@pebolle pebolle requested a review from a team as a code owner June 12, 2025 15:58
@pebolle pebolle requested review from pmatilai and removed request for a team June 12, 2025 15:58
Copy link
Member

@pmatilai pmatilai left a comment

Choose a reason for hiding this comment

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

We can't read both ~/.popt and the XDG version, it needs to be one or the other.

I'd suggest first determining the path (based on file existence), preferring XDG if it exists, and then have exactly one poptReadConfig() call to process it. Also, magic "+20" on buffer sizes doesn't cut it. Calculate the string size and then +1 for the trailing zero.

pebolle added 3 commits July 21, 2025 13:41
poptReadConfigFile reads an optional config file, ie. it returns success
even if that config file does not exist. This behavior is exported and
can not be changed.

But sometimes, eg. with ~/.config/popt and ~/.popt, we need to know
whether a config file exists in order to read just one. Add
poptReadConfigFileInternal to allow that. It basically is the guts of
the old poptReadConfigFile. And make poptReadConfigFile a very thin
wrapper around poptReadConfigFileInternal.
Look for per-user alias specification in the ${XDG_CONFIG_HOME}/popt
file. Still look in the traditional ${HOME}/.popt file but only if the
file in the new XDG base directory doesn't exists.

As per the XDG spec, if ${XDG_CONFIG_HOME} is not set, default to
~/.config/popt.

Fixes: rpm-software-management#129
@pebolle
Copy link
Author

pebolle commented Jul 21, 2025

Let's see whether this addresses your review.

Please note that poptReadConfigFile being exported (being API) complicated things quite a bit. This series should not alter that API. Fingers crossed!

Also, magic "+20" on buffer sizes doesn't cut it. Calculate the string size and then +1 for the trailing zero.

Being lazy, I only copied the approach used in master. Anyhow, manipulating strings in C is fun (for specific values of fun). Fingers crossed again!

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.

2 participants