From d3b7b0e3280dbc66bd39cd851af32f16fd863f1b Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Thu, 15 Feb 2024 09:26:38 +0200 Subject: [PATCH] Refactor to split file attribute discovery and initialization No functional changes, will be useful for the next commit. Co-authored-by: Florian Festi --- build/rpmfc.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/build/rpmfc.c b/build/rpmfc.c index d51a262c09..08f48c19bf 100644 --- a/build/rpmfc.c +++ b/build/rpmfc.c @@ -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; }