From 0b884bda7b6e1375f061e8c36deaad1288458516 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 15 Dec 2010 09:30:56 +0200 Subject: [PATCH] Unify the user+group caching between librpm and librpmbuild - The build version has getUidS() and getGidS() for which there is no counterpart in the rpmug api but there's not much point to them: they check whether the user/groupname exists but return our own string back to us even if it doesn't. - The build version also caches more than current rpmug, but has an ugly hardwired limit causing (in theory) errors that can't be nicely handled, and is the last piece relying on RPMLOG_CRIT actually terminating the process. The librpm version doesn't fail, in the worst case its just a bit slower. And that can be fixed anytime by making it to use hash tables for caching. (cherry picked from commit a2d002a34bc567e8ce88c9ed30270d55d7c904fd) --- build/build.c | 3 ++- build/files.c | 21 +++++++++++---------- build/parsePrep.c | 3 ++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/build/build.c b/build/build.c index 443cf94..aaca9b8 100644 --- a/build/build.c +++ b/build/build.c @@ -12,6 +12,7 @@ #include #include "build/rpmbuild_internal.h" #include "build/rpmbuild_misc.h" +#include "lib/rpmug.h" #include "debug.h" @@ -290,7 +291,7 @@ exit: rpmlog(RPMLOG_NOTICE, _("\n\nRPM build errors:\n")); rpmlogPrint(NULL); } - freeNames(); + rpmugFree(); return rc; } diff --git a/build/files.c b/build/files.c index fa47c77..2762578 100644 --- a/build/files.c +++ b/build/files.c @@ -25,6 +25,7 @@ #include "misc/fts.h" #include "lib/cpio.h" #include "lib/rpmfi_internal.h" /* XXX fi->apath */ +#include "lib/rpmug.h" #include "build/rpmbuild_internal.h" #include "build/rpmbuild_misc.h" @@ -1423,21 +1424,21 @@ static rpmRC addFile(FileList fl, const char * diskPath, fileMode |= fl->cur_ar.ar_fmode; } if (fl->cur_ar.ar_user) { - fileUname = getUnameS(fl->cur_ar.ar_user); + fileUname = fl->cur_ar.ar_user; } else { - fileUname = getUname(fileUid); + fileUname = rpmugUname(fileUid); } if (fl->cur_ar.ar_group) { - fileGname = getGnameS(fl->cur_ar.ar_group); + fileGname = fl->cur_ar.ar_group; } else { - fileGname = getGname(fileGid); + fileGname = rpmugGname(fileGid); } /* Default user/group to builder's user/group */ if (fileUname == NULL) - fileUname = getUname(getuid()); + fileUname = rpmugUname(getuid()); if (fileGname == NULL) - fileGname = getGname(getgid()); + fileGname = rpmugGname(getgid()); /* S_XXX macro must be consistent with type in find call at check-files script */ if (check_fileList && (S_ISREG(fileMode) || S_ISLNK(fileMode))) { @@ -2027,14 +2028,14 @@ rpmRC processSourceFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags) flp->fl_mode |= fl.def_ar.ar_fmode; } if (fl.def_ar.ar_user) { - flp->uname = getUnameS(fl.def_ar.ar_user); + flp->uname = fl.def_ar.ar_user; } else { - flp->uname = getUname(flp->fl_uid); + flp->uname = rpmugUname(flp->fl_uid); } if (fl.def_ar.ar_group) { - flp->gname = getGnameS(fl.def_ar.ar_group); + flp->gname = fl.def_ar.ar_group; } else { - flp->gname = getGname(flp->fl_gid); + flp->gname = rpmugGname(flp->fl_gid); } flp->langs = xstrdup(""); diff --git a/build/parsePrep.c b/build/parsePrep.c index ac671cc..1a9ee6a 100644 --- a/build/parsePrep.c +++ b/build/parsePrep.c @@ -12,6 +12,7 @@ #include #include "build/rpmbuild_internal.h" #include "build/rpmbuild_misc.h" +#include "lib/rpmug.h" #include "debug.h" /** @@ -28,7 +29,7 @@ static rpmRC checkOwners(const char * urlfn) urlfn, strerror(errno)); return RPMRC_FAIL; } - if (!getUname(sb.st_uid) || !getGname(sb.st_gid)) { + if (!rpmugUname(sb.st_uid) || !rpmugGname(sb.st_gid)) { rpmlog(RPMLOG_ERR, _("Bad owner/group: %s\n"), urlfn); return RPMRC_FAIL; } -- 2.7.4