pkg: pass-through ABIVersion to status file
[project/opkg-lede.git] / libopkg / pkg.c
index 551c62917225524204d6515148b3de7ed8757c21..51110687cc8c50368f099b1e82457666104f8655 100644 (file)
@@ -106,7 +106,7 @@ void *pkg_set_raw(pkg_t *pkg, int id, const void *val, size_t len)
        blob_for_each_attr(cur, pkg->blob.head, rem) {
                if (blob_id(cur) == id) {
                        if (blob_len(cur) < len) {
-                               fprintf(stderr, "ERROR: truncating field %d <%p> to %d byte",
+                               fprintf(stderr, "ERROR: truncating field %d <%p> to %zu byte",
                                        id, val, blob_len(cur));
                        }
                        memcpy(blob_data(cur), val, blob_len(cur));
@@ -319,6 +319,20 @@ void pkg_deinit(pkg_t * pkg)
                                free(ptr);
                        }
 
+                       pkg_set_ptr(pkg, blob_id(cur), NULL);
+                       break;
+               case PKG_ALTERNATIVES:
+                       ptr = pkg_get_ptr(pkg, blob_id(cur));
+
+                       if (ptr) {
+                               struct pkg_alternatives *pkg_alts = ptr;
+
+                               while (pkg_alts->nalts)
+                                       free(pkg_alts->alts[--pkg_alts->nalts]);
+                               free(pkg_alts->alts);
+                               free(pkg_alts);
+                       }
+
                        pkg_set_ptr(pkg, blob_id(cur), NULL);
                        break;
                }
@@ -465,6 +479,8 @@ int pkg_merge(pkg_t * oldpkg, pkg_t * newpkg)
                pkg_set_string(oldpkg, PKG_PRIORITY, pkg_get_string(newpkg, PKG_PRIORITY));
        if (!pkg_get_string(oldpkg, PKG_SOURCE))
                pkg_set_string(oldpkg, PKG_SOURCE, pkg_get_string(newpkg, PKG_SOURCE));
+       if (!pkg_get_string(oldpkg, PKG_ABIVERSION))
+               pkg_set_string(oldpkg, PKG_ABIVERSION, pkg_get_string(newpkg, PKG_ABIVERSION));
 
        if (!pkg_get_ptr(oldpkg, PKG_CONFFILES)) {
                pkg_set_ptr(oldpkg, PKG_CONFFILES, pkg_get_ptr(newpkg, PKG_CONFFILES));
@@ -636,7 +652,27 @@ void pkg_formatted_field(FILE * fp, pkg_t * pkg, const char *field)
        switch (field[0]) {
        case 'a':
        case 'A':
-               if (strcasecmp(field, "Architecture") == 0) {
+               if (strcasecmp(field, "ABIVersion") == 0) {
+                       p = pkg_get_string(pkg, PKG_ABIVERSION);
+                       if (p) {
+                               fprintf(fp, "ABIVersion: %s\n", p);
+                       }
+               } else if (strcasecmp(field, "Alternatives") == 0) {
+                       struct pkg_alternatives *pkg_alts = pkg_get_ptr(pkg, PKG_ALTERNATIVES);
+
+                       if (pkg_alts && pkg_alts->nalts > 0) {
+                               int i;
+                               struct pkg_alternative *alt;
+
+                               alt = pkg_alts->alts[0];
+                               fprintf(fp, "Alternatives: %d:%s:%s", alt->prio, alt->path, alt->altpath);
+                               for (i = 1; i < pkg_alts->nalts; i++) {
+                                       alt = pkg_alts->alts[i];
+                                       fprintf(fp, ", %d:%s:%s", alt->prio, alt->path, alt->altpath);
+                               }
+                               fputs("\n", fp);
+                       }
+               } else if (strcasecmp(field, "Architecture") == 0) {
                        p = pkg_get_architecture(pkg);
                        if (p) {
                                fprintf(fp, "Architecture: %s\n",
@@ -788,11 +824,11 @@ void pkg_formatted_field(FILE * fp, pkg_t * pkg, const char *field)
        case 'R':
                if (strcasecmp(field, "Replaces") == 0) {
                        ab_pkg = pkg_get_ptr(pkg, PKG_REPLACES);
-                       if (ab_pkg && *ab_pkg) {
+                       if (ab_pkg && ab_pkg[0]) {
                                fprintf(fp, "Replaces:");
-                               for (i = 0; *ab_pkg; i++, ab_pkg++) {
+                               for (i = 0; ab_pkg[i]; i++) {
                                        fprintf(fp, "%s %s", i == 0 ? "" : ",",
-                                               (*ab_pkg)->name);
+                                               ab_pkg[i]->name);
                                }
                                fprintf(fp, "\n");
                        }
@@ -925,6 +961,7 @@ void pkg_print_status(pkg_t * pkg, FILE * file)
        }
 
        pkg_formatted_field(file, pkg, "Package");
+       pkg_formatted_field(file, pkg, "ABIVersion");
        pkg_formatted_field(file, pkg, "Version");
        pkg_formatted_field(file, pkg, "Depends");
        pkg_formatted_field(file, pkg, "Recommends");
@@ -938,6 +975,7 @@ void pkg_print_status(pkg_t * pkg, FILE * file)
        pkg_formatted_field(file, pkg, "Conffiles");
        pkg_formatted_field(file, pkg, "Installed-Time");
        pkg_formatted_field(file, pkg, "Auto-Installed");
+       pkg_formatted_field(file, pkg, "Alternatives");
        fputs("\n", file);
 }