pkg: pass-through ABIVersion to status file
[project/opkg-lede.git] / libopkg / pkg.c
index 114cf05705666ab43c57903faafe6ba29e257eeb..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));
@@ -481,6 +497,9 @@ int pkg_merge(pkg_t * oldpkg, pkg_t * newpkg)
        if (!oldpkg->essential)
                oldpkg->essential = newpkg->essential;
 
+       if (!oldpkg->provided_by_hand)
+               oldpkg->provided_by_hand = newpkg->provided_by_hand;
+
        return 0;
 }
 
@@ -501,34 +520,6 @@ abstract_pkg_t *abstract_pkg_new(void)
        return ab_pkg;
 }
 
-void set_flags_from_control(pkg_t * pkg)
-{
-       char *file_name;
-       FILE *fp;
-
-       sprintf_alloc(&file_name, "%s/%s.control", pkg->dest->info_dir,
-                     pkg->name);
-
-       fp = fopen(file_name, "r");
-       if (fp == NULL) {
-               opkg_perror(ERROR, "Failed to open %s", file_name);
-               free(file_name);
-               return;
-       }
-
-       free(file_name);
-
-       if (pkg_parse_from_stream(pkg, fp, PFM_ALL ^ PFM_ESSENTIAL)) {
-               opkg_msg(DEBUG,
-                        "Unable to read control file for %s. May be empty.\n",
-                        pkg->name);
-       }
-
-       fclose(fp);
-
-       return;
-}
-
 static const char *pkg_state_want_to_str(pkg_state_want_t sw)
 {
        int i;
@@ -661,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",
@@ -813,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");
                        }
@@ -950,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");
@@ -963,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);
 }
 
@@ -1360,7 +1373,8 @@ int pkg_run_script(pkg_t * pkg, const char *script, const char *args)
        /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages
           have scripts in tmp_unpack_dir. */
        if (pkg->state_status == SS_INSTALLED
-           || pkg->state_status == SS_UNPACKED) {
+           || pkg->state_status == SS_UNPACKED
+           || pkg->state_status == SS_HALF_INSTALLED) {
                if (pkg->dest == NULL) {
                        opkg_msg(ERROR, "Internal error: %s has a NULL dest.\n",
                                 pkg->name);
@@ -1398,7 +1412,7 @@ int pkg_run_script(pkg_t * pkg, const char *script, const char *args)
        sprintf_alloc(&cmd, "%s %s", path, args);
        free(path);
        {
-               const char *argv[] = { "sh", "-c", cmd, NULL };
+               const char *argv[] = { "/bin/sh", "-c", cmd, NULL };
                err = xsystem(argv);
        }
        free(cmd);