pkg: store size, installed size and installed time info in blob buffer
authorJo-Philipp Wich <jo@mein.io>
Fri, 10 Feb 2017 21:56:13 +0000 (22:56 +0100)
committerJo-Philipp Wich <jo@mein.io>
Mon, 13 Feb 2017 15:53:07 +0000 (16:53 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
libopkg/opkg_cmd.c
libopkg/opkg_install.c
libopkg/pkg.c
libopkg/pkg.h
libopkg/pkg_parse.c
tests/libopkg_test.c

index 2e286ab..7f51ea9 100644 (file)
@@ -49,7 +49,7 @@ static void print_pkg(pkg_t * pkg)
        char *description = pkg_get_string(pkg, PKG_DESCRIPTION);
        printf("%s - %s", pkg->name, version);
        if (conf->size)
-               printf(" - %lu", pkg->size);
+               printf(" - %lu", (unsigned long) pkg_get_int(pkg, PKG_SIZE));
        if (description)
                printf(" - %s", description);
        printf("\n");
index 08b40fb..2d31905 100644 (file)
@@ -193,10 +193,13 @@ static int update_file_ownership(pkg_t * new_pkg, pkg_t * old_pkg)
 static int verify_pkg_installable(pkg_t * pkg)
 {
        unsigned long kbs_available, pkg_size_kbs;
+       unsigned long installed_size;
        char *root_dir = NULL;
        struct stat s;
 
-       if (conf->force_space || pkg->installed_size == 0)
+       installed_size = (unsigned long) pkg_get_int(pkg, PKG_INSTALLED_SIZE);
+
+       if (conf->force_space || installed_size == 0)
                return 0;
 
        if (pkg->dest) {
@@ -212,7 +215,7 @@ static int verify_pkg_installable(pkg_t * pkg)
 
        kbs_available = get_available_kbytes(root_dir);
 
-       pkg_size_kbs = (pkg->installed_size + 1023) / 1024;
+       pkg_size_kbs = (installed_size + 1023) / 1024;
 
        if (pkg_size_kbs >= kbs_available) {
                opkg_msg(ERROR, "Only have %ldkb available on filesystem %s, "
@@ -1256,6 +1259,7 @@ int opkg_install_pkg(pkg_t * pkg, int from_upgrade)
 #endif
        sigset_t newset, oldset;
        const char *local_filename;
+       time_t now;
 
        if (from_upgrade)
                message = 1;    /* Coming from an upgrade, and should change the output message */
@@ -1551,7 +1555,8 @@ int opkg_install_pkg(pkg_t * pkg, int from_upgrade)
        if (old_pkg)
                old_pkg->state_status = SS_NOT_INSTALLED;
 
-       time(&pkg->installed_time);
+       now = time(NULL);
+       pkg_set_int(pkg, PKG_INSTALLED_TIME, now);
 
        ab_pkg = pkg->parent;
        if (ab_pkg)
index 30602bf..7b10c1a 100644 (file)
@@ -101,8 +101,6 @@ static void pkg_init(pkg_t * pkg)
        pkg->provides_count = 0;
        pkg->provides = NULL;
        pkg->tmp_unpack_dir = NULL;
-       pkg->size = 0;
-       pkg->installed_size = 0;
        conffile_list_init(&pkg->conffiles);
        pkg->installed_files = NULL;
        pkg->installed_files_ref_cnt = 0;
@@ -393,10 +391,10 @@ int pkg_merge(pkg_t * oldpkg, pkg_t * newpkg)
                pkg_set_string(oldpkg, PKG_MD5SUM, pkg_get_string(newpkg, PKG_MD5SUM));
        if (!pkg_get_string(oldpkg, PKG_SHA256SUM))
                pkg_set_string(oldpkg, PKG_SHA256SUM, pkg_get_string(newpkg, PKG_SHA256SUM));
-       if (!oldpkg->size)
-               oldpkg->size = newpkg->size;
-       if (!oldpkg->installed_size)
-               oldpkg->installed_size = newpkg->installed_size;
+       if (!pkg_get_int(oldpkg, PKG_SIZE))
+               pkg_set_int(oldpkg, PKG_SIZE, pkg_get_int(newpkg, PKG_SIZE));
+       if (!pkg_get_int(oldpkg, PKG_INSTALLED_SIZE))
+               pkg_set_int(oldpkg, PKG_INSTALLED_SIZE, pkg_get_int(newpkg, PKG_INSTALLED_SIZE));
        if (!pkg_get_string(oldpkg, PKG_PRIORITY))
                pkg_set_string(oldpkg, PKG_PRIORITY, pkg_get_string(newpkg, PKG_PRIORITY));
        if (!pkg_get_string(oldpkg, PKG_SOURCE))
@@ -694,12 +692,14 @@ void pkg_formatted_field(FILE * fp, pkg_t * pkg, const char *field)
        case 'i':
        case 'I':
                if (strcasecmp(field, "Installed-Size") == 0) {
-                       fprintf(fp, "Installed-Size: %ld\n",
-                               pkg->installed_size);
-               } else if (strcasecmp(field, "Installed-Time") == 0
-                          && pkg->installed_time) {
-                       fprintf(fp, "Installed-Time: %lu\n",
-                               pkg->installed_time);
+                       fprintf(fp, "Installed-Size: %lu\n",
+                               (unsigned long) pkg_get_int(pkg, PKG_INSTALLED_SIZE));
+               } else if (strcasecmp(field, "Installed-Time") == 0) {
+                       i = pkg_get_int(pkg, PKG_INSTALLED_TIME);
+                       if (i) {
+                               fprintf(fp, "Installed-Time: %lu\n",
+                                       (unsigned long) i);
+                       }
                }
                break;
        case 'm':
@@ -781,8 +781,9 @@ void pkg_formatted_field(FILE * fp, pkg_t * pkg, const char *field)
                        }
 #endif
                } else if (strcasecmp(field, "Size") == 0) {
-                       if (pkg->size) {
-                               fprintf(fp, "Size: %ld\n", pkg->size);
+                       i = pkg_get_int(pkg, PKG_SIZE);
+                       if (i) {
+                               fprintf(fp, "Size: %lu\n", (unsigned long) i);
                        }
                } else if (strcasecmp(field, "Source") == 0) {
                        p = pkg_get_string(pkg, PKG_SOURCE);
index 6e09f0a..0931e6e 100644 (file)
@@ -93,6 +93,9 @@ enum pkg_fields {
        PKG_DESCRIPTION,
        PKG_MD5SUM,
        PKG_SHA256SUM,
+       PKG_SIZE,
+       PKG_INSTALLED_SIZE,
+       PKG_INSTALLED_TIME,
 };
 
 struct abstract_pkg {
@@ -164,10 +167,7 @@ struct pkg {
        abstract_pkg_t *parent;
 
        char *tmp_unpack_dir;
-       unsigned long size;     /* in bytes */
-       unsigned long installed_size;   /* in bytes */
        conffile_list_t conffiles;
-       time_t installed_time;
        /* As pointer for lazy evaluation */
        str_list_t *installed_files;
        /* XXX: CLEANUP: I'd like to perhaps come up with a better
index b7b2fe3..4b2e902 100644 (file)
@@ -168,14 +168,10 @@ int pkg_parse_line(void *ptr, const char *line, uint mask)
        case 'I':
                if ((mask & PFM_INSTALLED_SIZE)
                    && is_field("Installed-Size", line)) {
-                       char *tmp = parse_simple("Installed-Size", line);
-                       pkg->installed_size = strtoul(tmp, NULL, 0);
-                       free(tmp);
+                       pkg_set_int(pkg, PKG_INSTALLED_SIZE, strtoul(line + strlen("Installed-Size") + 1, NULL, 0));
                } else if ((mask & PFM_INSTALLED_TIME)
                           && is_field("Installed-Time", line)) {
-                       char *tmp = parse_simple("Installed-Time", line);
-                       pkg->installed_time = strtoul(tmp, NULL, 0);
-                       free(tmp);
+                       pkg_set_int(pkg, PKG_INSTALLED_TIME, strtoul(line + strlen("Installed-Time") + 1, NULL, 0));
                }
                break;
 
@@ -223,9 +219,7 @@ int pkg_parse_line(void *ptr, const char *line, uint mask)
                        pkg_set_string(pkg, PKG_SHA256SUM, line + strlen("SHA256sum") + 1);
 #endif
                else if ((mask & PFM_SIZE) && is_field("Size", line)) {
-                       char *tmp = parse_simple("Size", line);
-                       pkg->size = strtoul(tmp, NULL, 0);
-                       free(tmp);
+                       pkg_set_int(pkg, PKG_SIZE, strtoul(line + strlen("Size") + 1, NULL, 0));
                } else if ((mask & PFM_SOURCE) && is_field("Source", line))
                        pkg_set_string(pkg, PKG_SOURCE, line + strlen("Source") + 1);
                else if ((mask & PFM_STATUS) && is_field("Status", line))
index 78f68a6..ab15eb7 100644 (file)
@@ -65,14 +65,15 @@ void print_package(pkg_t * pkg)
               "Architecture: %s\n"
               "Description:  %s\n"
               "Tags:         %s\n"
-              "Size:         %ld\n"
+              "Size:         %lu\n"
               "Status:       %d\n",
               pkg->name,
               v,
               pkg->src->name,
               pkg_get_string(pkg, PKG_ARCHITECTURE),
               pkg_get_string(pkg, PKG_DESCRIPTION),
-              tags ? tags : "", pkg->size, pkg->state_status);
+              tags ? tags : "",
+              (unsigned long) pkg_get_int(pkg, PKG_SIZE), pkg->state_status);
        free(v);
 }