Nuke the ugly hardwired "known arch" list from label parsing
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 5 Nov 2008 18:37:48 +0000 (20:37 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 5 Nov 2008 18:37:48 +0000 (20:37 +0200)
- we have list of known archs in rpmrc, might as well use it
- avoids having to patch & recompile rpm just to have rpmtsInitIterator()
  recognize new archs when it's runtime configurable otherwise
- checking against compatible arch would be saner except then people could
  get into even more trouble using --ignorearch...

lib/misc.h
lib/rpmrc.c
lib/rpmts.c

index 405455d..e2a5453 100644 (file)
 extern "C" {
 #endif
 
+/* known arch? */
+RPM_GNUC_INTERNAL
+int rpmIsKnownArch(const char *name);
+
 /*
  * These may be called w/ a NULL argument to flush the cache -- they return
  * -1 if the user can't be found.
index 49b3e7e..69d55d6 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "rpmio/rpmlua.h"
 #include "rpmio/rpmio_internal.h"      /* XXX for rpmioSlurp */
+#include "lib/misc.h"
 
 #include "debug.h"
 
@@ -1327,6 +1328,14 @@ int rpmMachineScore(int type, const char * name)
     return (info != NULL ? info->score : 0);
 }
 
+int rpmIsKnownArch(const char *name)
+{
+    canonEntry canon = lookupInCanonTable(name,
+                       tables[RPM_MACHTABLE_INSTARCH].canons,
+                       tables[RPM_MACHTABLE_INSTARCH].canonsLength);
+    return (canon != NULL || strcmp(name, "noarch") == 0);
+}
+
 /** \ingroup rpmrc
  * Set current arch/os names.
  * NULL as argument is set to the default value (munged uname())
index 88298e5..d431a1b 100644 (file)
@@ -24,6 +24,7 @@
 #include "rpmio/digest.h"
 #include "lib/rpmlock.h"
 #include "lib/rpmts_internal.h"
+#include "lib/misc.h"
 
 /* XXX FIXME: merge with existing (broken?) tests in system.h */
 /* portability fiddles */
@@ -153,34 +154,6 @@ int rpmtsVerifyDB(rpmts ts)
     return rpmdbVerify(ts->rootDir);
 }
 
-static int isArch(const char * arch)
-{
-    const char * const * av;
-    static const char * const arches[] = {
-       "i386", "i486", "i586", "i686", "athlon", "pentium3", "pentium4", "x86_64", "amd64", "ia32e", "geode",
-       "alpha", "alphaev5", "alphaev56", "alphapca56", "alphaev6", "alphaev67",
-       "sparc", "sun4", "sun4m", "sun4c", "sun4d", "sparcv8", "sparcv9", "sparcv9v",
-       "sparc64", "sparc64v", "sun4u",
-       "mips", "mipsel", "IP",
-       "ppc", "ppciseries", "ppcpseries",
-       "ppc64", "ppc64iseries", "ppc64pseries",
-       "m68k",
-       "rs6000",
-       "ia64",
-       "armv3l", "armv4b", "armv4l", "armv4tl", "armv5tel", "armv5tejl", "armv6l",
-       "s390", "i370", "s390x",
-       "sh", "xtensa",
-       "noarch",
-       NULL,
-    };
-
-    for (av = arches; *av != NULL; av++) {
-       if (!strcmp(arch, *av))
-           return 1;
-    }
-    return 0;
-}
-
 /* keyp might no be defined. */
 rpmdbMatchIterator rpmtsInitIterator(const rpmts ts, rpmTag rpmtag,
                        const void * keyp, size_t keylen)
@@ -247,7 +220,7 @@ rpmdbMatchIterator rpmtsInitIterator(const rpmts ts, rpmTag rpmtag,
        t = (char *) keyp;
        t = strrchr(t, '.');
        /* Is this a valid ".arch" suffix? */
-       if (t != NULL && isArch(t+1)) {
+       if (t != NULL && rpmIsKnownArch(t+1)) {
           *t++ = '\0';
           arch = t;
        }