Skip to content

Commit

Permalink
Refactor to split file attribute discovery and initialization
Browse files Browse the repository at this point in the history
No functional changes, will be useful for the next commit.

Co-authored-by: Florian Festi <ffesti@redhat.com>
  • Loading branch information
pmatilai and ffesti committed Feb 15, 2024
1 parent 5ece87a commit d3b7b0e
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions build/rpmfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit d3b7b0e

Please sign in to comment.