pkg: alternatives support
[oweals/opkg-lede.git] / libopkg / pkg.c
index 551c62917225524204d6515148b3de7ed8757c21..21f239eeab9514e2b58e3b3ff066a3c199d6cf36 100644 (file)
@@ -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;
                }
@@ -636,7 +650,22 @@ 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, "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",
@@ -938,6 +967,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);
 }