Refactor to split file attribute discovery and initialization

No functional changes, will be useful for the next commit.

Co-authored-by: Florian Festi <ffesti@redhat.com>
This commit is contained in:
Panu Matilainen 2024-02-15 09:26:38 +02:00 committed by Florian Festi
parent 5ece87a250
commit d3b7b0e328
1 changed files with 16 additions and 6 deletions

View File

@ -1186,20 +1186,30 @@ static int initAttrs(rpmfc fc)
ARGV_t files = NULL;
char * attrPath = rpmExpand("%{_fileattrsdir}/*.attr", NULL);
int nattrs = 0;
ARGV_t all_attrs = NULL;
/* Discover known attributes from pathnames + initialize them */
/* Discover known attributes from pathnames */
if (rpmGlob(attrPath, NULL, &files) == 0) {
nattrs = argvCount(files);
fc->atypes = xcalloc(nattrs + 1, sizeof(*fc->atypes));
for (int i = 0; i < nattrs; i++) {
int nfiles = argvCount(files);
for (int i = 0; i < nfiles; i++) {
char *bn = basename(files[i]);
bn[strlen(bn)-strlen(".attr")] = '\0';
fc->atypes[i] = rpmfcAttrNew(bn);
argvAdd(&all_attrs, bn);
}
fc->atypes[nattrs] = NULL;
argvFree(files);
}
/* Initialize attr objects */
nattrs = argvCount(all_attrs);
fc->atypes = xcalloc(nattrs + 1, sizeof(*fc->atypes));
for (int i = 0; i < nattrs; i++) {
fc->atypes[i] = rpmfcAttrNew(all_attrs[i]);
}
fc->atypes[nattrs] = NULL;
free(attrPath);
argvFree(all_attrs);
return nattrs;
}