Unify the user+group caching between librpm and librpmbuild
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 15 Dec 2010 07:30:56 +0000 (09:30 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 21 Dec 2010 09:49:04 +0000 (11:49 +0200)
- 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
build/files.c
build/parsePrep.c

index 443cf94..aaca9b8 100644 (file)
@@ -12,6 +12,7 @@
 #include <rpm/rpmfileutil.h>
 #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;
 }
index fa47c77..2762578 100644 (file)
@@ -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("");
        
index ac671cc..1a9ee6a 100644 (file)
@@ -12,6 +12,7 @@
 #include <rpm/rpmfileutil.h>
 #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;
     }