Browse Source

libdpkg: Update pkgbin.arch to be a pointer to struct dpkg_arch

Sponsored-by: Linaro Limited

[guillem@debian.org:
 - Distinguish between missing and empty Architecture field. ]

Signed-off-by: Guillem Jover <guillem@debian.org>
Raphaël Hertzog 15 years ago
parent
commit
865a375dca
8 changed files with 54 additions and 11 deletions
  1. 2 2
      dpkg-deb/build.c
  2. 2 1
      lib/dpkg/dpkg-db.h
  3. 21 0
      lib/dpkg/dump.c
  4. 16 0
      lib/dpkg/fields.c
  5. 7 4
      lib/dpkg/parse.c
  6. 2 0
      lib/dpkg/parsedump.h
  7. 1 1
      src/help.c
  8. 3 3
      src/processarc.c

+ 2 - 2
dpkg-deb/build.c

@@ -374,9 +374,9 @@ pkg_get_pathname(const char *dir, struct pkginfo *pkg)
   const char *versionstring, *arch_sep;
 
   versionstring = versiondescribe(&pkg->available.version, vdew_never);
-  arch_sep = pkg->available.arch[0] == '\0' ? "" : "_";
+  arch_sep = pkg->available.arch->type == arch_none ? "" : "_";
   m_asprintf(&path, "%s/%s_%s%s%s%s", dir, pkg->name, versionstring,
-             arch_sep, pkg->available.arch, DEBEXT);
+             arch_sep, pkg->available.arch->name, DEBEXT);
 
   return path;
 }

+ 2 - 1
lib/dpkg/dpkg-db.h

@@ -31,6 +31,7 @@
 #include <dpkg/macros.h>
 #include <dpkg/varbuf.h>
 #include <dpkg/version.h>
+#include <dpkg/arch.h>
 
 DPKG_BEGIN_DECLS
 
@@ -115,10 +116,10 @@ struct pkgbin {
     multiarch_allowed,
     multiarch_foreign,
   } multiarch;
+  const struct dpkg_arch *arch;
   const char *description;
   const char *maintainer;
   const char *source;
-  const char *arch;
   const char *installedsize;
   const char *origin;
   const char *bugs;

+ 21 - 0
lib/dpkg/dump.c

@@ -5,6 +5,8 @@
  * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  * Copyright © 2001 Wichert Akkerman
  * Copyright © 2006,2008-2011 Guillem Jover <guillem@debian.org>
+ * Copyright © 2011 Linaro Limited
+ * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -186,6 +188,25 @@ w_multiarch(struct varbuf *vb,
   varbuf_add_char(vb, '\n');
 }
 
+void
+w_architecture(struct varbuf *vb,
+               const struct pkginfo *pigp, const struct pkgbin *pifp,
+               enum fwriteflags flags, const struct fieldinfo *fip)
+{
+  if (!pifp->arch)
+    return;
+  if (pifp->arch->type == arch_none)
+    return;
+
+  if (flags & fw_printheader) {
+    varbuf_add_str(vb, fip->name);
+    varbuf_add_str(vb, ": ");
+  }
+  varbuf_add_str(vb, pifp->arch->name);
+  if (flags & fw_printheader)
+    varbuf_add_char(vb, '\n');
+}
+
 void
 w_priority(struct varbuf *vb,
            const struct pkginfo *pigp, const struct pkgbin *pifp,

+ 16 - 0
lib/dpkg/fields.c

@@ -5,6 +5,8 @@
  * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  * Copyright © 2001 Wichert Akkerman
  * Copyright © 2006-2011 Guillem Jover <guillem@debian.org>
+ * Copyright © 2011 Linaro Limited
+ * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -172,6 +174,20 @@ f_multiarch(struct pkginfo *pigp, struct pkgbin *pifp,
   PKGPFIELD(pifp, fip->integer, int) = multiarch;
 }
 
+void
+f_architecture(struct pkginfo *pigp, struct pkgbin *pifp,
+               struct parsedb_state *ps,
+               const char *value, const struct fieldinfo *fip)
+{
+  if (!*value)
+    return;
+
+  pifp->arch = dpkg_arch_find(value);
+  if (pifp->arch->type == arch_illegal)
+    parse_warn(ps, _("'%s' is not a valid architecture name: %s"),
+               value, dpkg_arch_name_is_illegal(value));
+}
+
 void
 f_section(struct pkginfo *pigp, struct pkgbin *pifp,
           struct parsedb_state *ps,

+ 7 - 4
lib/dpkg/parse.c

@@ -59,7 +59,7 @@ const struct fieldinfo fieldinfos[]= {
   { "Origin",           f_charfield,       w_charfield,      PKGIFPOFF(origin)        },
   { "Maintainer",       f_charfield,       w_charfield,      PKGIFPOFF(maintainer)    },
   { "Bugs",             f_charfield,       w_charfield,      PKGIFPOFF(bugs)          },
-  { "Architecture",     f_charfield,       w_charfield,      PKGIFPOFF(arch)          },
+  { "Architecture",     f_architecture,    w_architecture                             },
   { "Source",           f_charfield,       w_charfield,      PKGIFPOFF(source)        },
   { "Version",          f_version,         w_version,        PKGIFPOFF(version)       },
   { "Revision",         f_revision,        w_null                                     },
@@ -192,10 +192,13 @@ pkg_parse_verify(struct parsedb_state *ps,
     /* We always want usable architecture information (as long as the package
      * is in such a state that it make sense), so that it can be used safely
      * on string comparisons and the like. */
-    parse_ensure_have_field(ps, &pkgbin->arch, "architecture");
-  } else if (pkgbin->arch == NULL) {
-    pkgbin->arch = "";
+    if (pkgbin->arch == NULL)
+      parse_warn(ps, _("missing %s"), "architecture");
+    else if (pkgbin->arch->type == arch_none)
+      parse_warn(ps, _("empty value for %s"), "architecture");
   }
+  if (pkgbin->arch == NULL)
+    pkgbin->arch = dpkg_arch_find(NULL);
 
   /* Check the Config-Version information:
    * If there is a Config-Version it is definitely to be used, but

+ 2 - 0
lib/dpkg/parsedump.h

@@ -72,6 +72,7 @@ freadfunction f_name, f_charfield, f_priority, f_section, f_status, f_filecharf;
 freadfunction f_boolean, f_dependency, f_conffiles, f_version, f_revision;
 freadfunction f_configversion;
 freadfunction f_multiarch;
+freadfunction f_architecture;
 freadfunction f_trigpend, f_trigaw;
 
 enum fwriteflags {
@@ -85,6 +86,7 @@ typedef void fwritefunction(struct varbuf*,
 fwritefunction w_name, w_charfield, w_priority, w_section, w_status, w_configversion;
 fwritefunction w_version, w_null, w_booleandefno, w_dependency, w_conffiles;
 fwritefunction w_multiarch;
+fwritefunction w_architecture;
 fwritefunction w_filecharf;
 fwritefunction w_trigpend, w_trigaw;
 

+ 1 - 1
src/help.c

@@ -270,7 +270,7 @@ do_script(struct pkginfo *pkg, struct pkgbin *pif,
   pid = subproc_fork();
   if (pid == 0) {
     if (setenv("DPKG_MAINTSCRIPT_PACKAGE", pkg->name, 1) ||
-        setenv("DPKG_MAINTSCRIPT_ARCH", pif->arch, 1) ||
+        setenv("DPKG_MAINTSCRIPT_ARCH", pif->arch->name, 1) ||
         setenv("DPKG_MAINTSCRIPT_NAME", cmd->argv[0], 1) ||
         setenv("DPKG_RUNNING_VERSION", PACKAGE_VERSION, 1))
       ohshite(_("unable to setenv for maintainer script"));

+ 3 - 3
src/processarc.c

@@ -496,11 +496,11 @@ void process_archive(const char *filename) {
     return;
   }
 
-  if (strcmp(pkg->available.arch, "all") &&
-      strcmp(pkg->available.arch, native_arch))
+  if (pkg->available.arch->type != arch_all &&
+      pkg->available.arch->type != arch_native)
     forcibleerr(fc_architecture,
                 _("package architecture (%s) does not match system (%s)"),
-                pkg->available.arch, native_arch);
+                pkg->available.arch->name, native_arch);
 
   for (deconpil= deconfigure;
        deconpil;