Closed Jguer closed 6 years ago
Pacman's parsing solution is very simple. Something like this:
for each line
trim whitespace
if line starts with [ and ends with ]
handle header
else
left, right = split on '='
trim white space for left and right
handle value
endif
endfor
If we use `pacconf` then that simplifies it further for us. It will remove all the comments and solve the includes.
pacutils/*.h
/usr/include/pacutils/config.h
typedef struct pu_config_t {
char *rootdir;
char *dbpath;
char *gpgdir;
char *logfile;
char *architecture;
char *xfercommand;
pu_config_bool_t checkspace;
pu_config_bool_t color;
pu_config_bool_t ilovecandy;
pu_config_bool_t totaldownload;
pu_config_bool_t usesyslog;
pu_config_bool_t verbosepkglists;
float usedelta;
int siglevel;
int localfilesiglevel;
int remotefilesiglevel;
int siglevel_mask;
int localfilesiglevel_mask;
int remotefilesiglevel_mask;
alpm_list_t *cachedirs;
alpm_list_t *holdpkgs;
alpm_list_t *hookdirs;
alpm_list_t *ignoregroups;
alpm_list_t *ignorepkgs;
alpm_list_t *noextract;
alpm_list_t *noupgrade;
int cleanmethod;
alpm_list_t *repos;
} pu_config_t;
pu_config_t *config = pu_config_new_from_file("/etc/pacman.conf");
Easily portable using cgo
Separable from go_alpm -> go_pacutils?
-3, severe impact 0, no impact, 3, very beneficial
Total Estimated benefit: 2
Ah whoops instead of pacconf
I meant pacman-conf
which is part of pacman.
Haha, writing a go_pacutils
wrapper (https://github.com/andrewgregory/pacutils) would still be fun if not for use in yay.
I guess pacman-conf uses the same structure and parsing but does not export it.
I like the pacman parsing solution, it's KISS, is there any other alternative?
Not really, either way we need to read the config and set up the correct databases and all that. pacman-conf
is built into Pacman so it wins by default for me.
I'm okay with that as well, I'm a bit short on implementation time until July though
I've made this for my own experiments https://github.com/Morganamilo/go-pacmanconf could be used here too if you don't mind deping on it.
There would be some subtle changes though, currently the config does some magic. Converts siglevels to its own type and arch=auto will set the correct arch. I have not bothered with that because the config file is plain text and should stay as plain text even when parsed.
Once we start setting alpm values then the magic can happen. For example if config.Arch=auto
then we can alpm.SetArch(uname)
but keep the conf value as auto.
Although I'm still unsure whether that fits here as I have mentioned before, alpm does not have a config, that't totally a pacman thing and this project aims to be a alpm wrapper. So instead the config stuff could be in Yay with then uses that to alpm.SetFoo
.
But at the same time anybody who is using this project probably wants the ability to read the pacman.conf stuff too, so you can argue for it being here.
By the way as this was more of me just experimenting with stuff I didn't bother to comment and test it to the extent of go-srcfo (yet). The structs in pacmanconf.go should be enough to get an idea of how it works.
And as discussed before this is a wrapper for pacman-conf
so includes and stuff are handled for us.
Closing this issue as it's been outsourced. Refer to release https://github.com/Jguer/go-alpm/releases/tag/v8.1110 for the last version with an included parser
Interesting choice on the version number. Although v8.1115 also still uses go-alpm for parsing. Currently only git has it removed.
It was tagged during the 8.1110 release, and to 8.1115 there wasn't much if any change that warranted a tag
Discussion on the reimplementation of
pacman.conf
parsing to fix some of the current problems presentAlternatives