summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/add.c2
-rw-r--r--src/apk.c1
-rw-r--r--src/apk_blob.h7
-rw-r--r--src/apk_database.h3
-rw-r--r--src/apk_package.h15
-rw-r--r--src/blob.c67
-rw-r--r--src/database.c53
-rw-r--r--src/index.c2
-rw-r--r--src/info.c36
-rw-r--r--src/package.c39
-rw-r--r--src/print.c2
-rw-r--r--src/search.c12
-rw-r--r--src/state.c31
-rw-r--r--src/update.c5
-rw-r--r--src/ver.c18
15 files changed, 184 insertions, 109 deletions
diff --git a/src/add.c b/src/add.c
index f13215a..5f5f6c7 100644
--- a/src/add.c
+++ b/src/add.c
@@ -78,7 +78,7 @@ static int add_main(void *ctx, struct apk_database *db, int argc, char **argv)
virtpkg->name = apk_db_get_name(db, APK_BLOB_STR(actx->virtpkg));
apk_blob_checksum(APK_BLOB_STR(virtpkg->name->name),
apk_checksum_default(), &virtpkg->csum);
- virtpkg->version = strdup("0");
+ virtpkg->version = apk_blob_atomize(APK_BLOB_STR("0"));
virtpkg->description = strdup("virtual meta package");
apk_dep_from_pkg(&virtdep, db, virtpkg);
virtdep.name->flags |= APK_NAME_TOPLEVEL;
diff --git a/src/apk.c b/src/apk.c
index 55628c1..7663d4c 100644
--- a/src/apk.c
+++ b/src/apk.c
@@ -247,6 +247,7 @@ int main(int argc, char **argv)
memset(&dbopts, 0, sizeof(dbopts));
list_init(&dbopts.repository_list);
+ apk_atom_init();
umask(0);
applet = deduce_applet(argc, argv);
diff --git a/src/apk_blob.h b/src/apk_blob.h
index 877635c..f1c3a35 100644
--- a/src/apk_blob.h
+++ b/src/apk_blob.h
@@ -24,6 +24,9 @@ struct apk_blob {
typedef struct apk_blob apk_blob_t;
typedef int (*apk_blob_cb)(void *ctx, apk_blob_t blob);
+#define BLOB_FMT "%.*s"
+#define BLOB_PRINTF(b) (int)(b).len, (b).ptr
+
#define APK_CHECKSUM_NONE 0
#define APK_CHECKSUM_MD5 16
#define APK_CHECKSUM_SHA1 20
@@ -114,4 +117,8 @@ struct apk_indent {
void apk_print_indented_words(struct apk_indent *i, const char *text);
int apk_print_indented(struct apk_indent *i, apk_blob_t blob);
+void apk_atom_init(void);
+apk_blob_t *apk_blob_atomize(apk_blob_t blob);
+apk_blob_t *apk_blob_atomize_dup(apk_blob_t blob);
+
#endif
diff --git a/src/apk_database.h b/src/apk_database.h
index cfac023..349ea7d 100644
--- a/src/apk_database.h
+++ b/src/apk_database.h
@@ -103,7 +103,8 @@ struct apk_database {
char *root;
int root_fd, lock_fd, cache_fd, cachetmp_fd, keys_fd;
unsigned name_id, num_repos;
- const char *cache_dir, *arch;
+ const char *cache_dir;
+ apk_blob_t *arch;
int permanent;
unsigned int local_repos;
diff --git a/src/apk_package.h b/src/apk_package.h
index 8ba1ffe..0b0d317 100644
--- a/src/apk_package.h
+++ b/src/apk_package.h
@@ -63,8 +63,8 @@ struct apk_sign_ctx {
struct apk_dependency {
struct apk_name *name;
+ apk_blob_t *version;
int result_mask;
- char *version;
};
APK_ARRAY(apk_dependency_array, struct apk_dependency);
@@ -83,18 +83,21 @@ struct apk_installed_package {
struct apk_package {
apk_hash_node hash_node;
- unsigned repos;
struct apk_name *name;
- char *version, *arch;
- char *url, *description, *license;
+ struct apk_installed_package *ipkg;
+ apk_blob_t *version, *arch, *license;
+ char *url, *description;
+ char *filename;
struct apk_dependency_array *depends;
size_t installed_size, size;
- char *filename;
+ unsigned repos;
struct apk_checksum csum;
- struct apk_installed_package *ipkg;
};
APK_ARRAY(apk_package_array, struct apk_package *);
+#define PKG_VER_FMT "%s-" BLOB_FMT
+#define PKG_VER_PRINTF(pkg) pkg->name->name, BLOB_PRINTF(*pkg->version)
+
extern const char *apk_script_types[];
void apk_sign_ctx_init(struct apk_sign_ctx *ctx, int action,
diff --git a/src/blob.c b/src/blob.c
index 70004e6..0167c51 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -11,8 +11,15 @@
#include <malloc.h>
#include <string.h>
+#include <printf.h>
#include "apk_blob.h"
+#include "apk_hash.h"
+
+struct apk_blob_atom {
+ struct hlist_node hash_node;
+ apk_blob_t blob;
+};
char *apk_blob_cstr(apk_blob_t blob)
{
@@ -432,3 +439,63 @@ void apk_blob_pull_base64(apk_blob_t *b, apk_blob_t to)
b->ptr += needed;
b->len -= needed;
}
+
+static apk_blob_t atom_hash_get_key(apk_hash_item item)
+{
+ return ((struct apk_blob_atom *) item)->blob;
+}
+
+static struct apk_hash atom_hash;
+static struct apk_hash_ops atom_ops = {
+ .node_offset = offsetof(struct apk_blob_atom, hash_node),
+ .get_key = atom_hash_get_key,
+ .hash_key = apk_blob_hash,
+ .compare = apk_blob_compare,
+ .delete_item = (apk_hash_delete_f) free,
+};
+static apk_blob_t null_blob = {0,0};
+
+void apk_atom_init(void)
+{
+ apk_hash_init(&atom_hash, &atom_ops, 2048);
+}
+
+apk_blob_t *apk_blob_atomize(apk_blob_t blob)
+{
+ struct apk_blob_atom *atom;
+ unsigned long hash = apk_hash_from_key(&atom_hash, blob);
+
+ if (blob.len < 0 || blob.ptr == NULL)
+ return &null_blob;
+
+ atom = (struct apk_blob_atom *) apk_hash_get_hashed(&atom_hash, blob, hash);
+ if (atom != NULL)
+ return &atom->blob;
+
+ atom = malloc(sizeof(*atom));
+ atom->blob = blob;
+ apk_hash_insert_hashed(&atom_hash, atom, hash);
+
+ return &atom->blob;
+}
+
+apk_blob_t *apk_blob_atomize_dup(apk_blob_t blob)
+{
+ struct apk_blob_atom *atom;
+ unsigned long hash = apk_hash_from_key(&atom_hash, blob);
+ char *ptr;
+
+ if (blob.len < 0 || blob.ptr == NULL)
+ return &null_blob;
+ atom = (struct apk_blob_atom *) apk_hash_get_hashed(&atom_hash, blob, hash);
+ if (atom != NULL)
+ return &atom->blob;
+
+ atom = malloc(sizeof(*atom) + blob.len);
+ ptr = (char*) (atom + 1);
+ memcpy(ptr, blob.ptr, blob.len);
+ atom->blob = APK_BLOB_PTR_LEN(ptr, blob.len);
+ apk_hash_insert_hashed(&atom_hash, atom, hash);
+
+ return &atom->blob;
+}
diff --git a/src/database.c b/src/database.c
index 8ad3bdd..f87123b 100644
--- a/src/database.c
+++ b/src/database.c
@@ -453,9 +453,9 @@ int apk_cache_download(struct apk_database *db, const char *url,
char fullurl[PATH_MAX];
int r;
- snprintf(fullurl, sizeof(fullurl), "%s%s%s/%s",
+ snprintf(fullurl, sizeof(fullurl), "%s%s" BLOB_FMT "/%s",
url, url[strlen(url)-1] == '/' ? "" : "/",
- db->arch, item);
+ BLOB_PRINTF(*db->arch), item);
apk_message("fetch %s", fullurl);
if (apk_flags & APK_SIMULATE)
@@ -738,7 +738,7 @@ static int apk_db_scriptdb_write(struct apk_database *db, struct apk_ostream *os
bfn = APK_BLOB_BUF(filename);
apk_blob_push_blob(&bfn, APK_BLOB_STR(pkg->name->name));
apk_blob_push_blob(&bfn, APK_BLOB_STR("-"));
- apk_blob_push_blob(&bfn, APK_BLOB_STR(pkg->version));
+ apk_blob_push_blob(&bfn, *pkg->version);
apk_blob_push_blob(&bfn, APK_BLOB_STR("."));
apk_blob_push_csum(&bfn, &pkg->csum);
apk_blob_push_blob(&bfn, APK_BLOB_STR("."));
@@ -1122,8 +1122,7 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
blob = APK_BLOB_STR("etc:*etc/init.d");
apk_blob_for_each_segment(blob, ":", add_protected_path, db);
- db->arch = apk_arch;
-
+ db->arch = apk_blob_atomize(APK_BLOB_STR(apk_arch));
db->cache_fd = openat(db->root_fd, db->cache_dir, O_RDONLY | O_CLOEXEC);
mkdirat(db->cache_fd, "tmp", 0644);
db->cachetmp_fd = openat(db->cache_fd, "tmp", O_RDONLY | O_CLOEXEC);
@@ -1401,15 +1400,15 @@ static int apk_repo_is_remote(struct apk_repository *repo)
}
static struct apk_bstream *apk_repo_file_open(struct apk_repository *repo,
- const char *arch,
+ apk_blob_t arch,
const char *file,
char *buf, int buflen)
{
const char *url = repo->url;
- snprintf(buf, buflen, "%s%s%s/%s",
+ snprintf(buf, buflen, "%s%s" BLOB_FMT "/%s",
url, url[strlen(url)-1] == '/' ? "" : "/",
- arch, file);
+ BLOB_PRINTF(arch), file);
if ((apk_flags & APK_NO_NETWORK) && apk_repo_is_remote(repo))
return NULL;
@@ -1577,7 +1576,7 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t repository)
bs = apk_bstream_from_file(db->cache_fd, buf);
} else {
db->local_repos |= BIT(r);
- bs = apk_repo_file_open(repo, db->arch, apkindex_tar_gz, buf, sizeof(buf));
+ bs = apk_repo_file_open(repo, *db->arch, apkindex_tar_gz, buf, sizeof(buf));
}
if (bs == NULL) {
apk_warning("Failed to open index for %s", repo->url);
@@ -1675,7 +1674,6 @@ static int apk_db_install_archive_entry(void *_ctx,
apk_blob_t name = APK_BLOB_STR(ae->name), bdir, bfile;
struct apk_db_dir_instance *diri = ctx->diri;
struct apk_db_file *file;
- const char *p;
int r = 0, type = APK_SCRIPT_INVALID;
if (apk_sign_ctx_process_file(&ctx->sctx, ae, is) == 0)
@@ -1693,19 +1691,6 @@ static int apk_db_install_archive_entry(void *_ctx,
type = apk_script_type(&ae->name[1]);
if (type == APK_SCRIPT_INVALID)
return 0;
- } else if (strncmp(ae->name, "var/db/apk/", 11) == 0) {
- /* APK 1.0 format */
- p = &ae->name[11];
- if (strncmp(p, pkg->name->name, strlen(pkg->name->name)) != 0)
- return 0;
- p += strlen(pkg->name->name) + 1;
- if (strncmp(p, pkg->version, strlen(pkg->version)) != 0)
- return 0;
- p += strlen(pkg->version) + 1;
-
- type = apk_script_type(p);
- if (type == APK_SCRIPT_INVALID)
- return 0;
}
/* Handle script */
@@ -2001,7 +1986,7 @@ static int apk_db_unpack_pkg(struct apk_database *db,
if (bs == NULL) {
apk_pkg_format_plain(pkg, APK_BLOB_BUF(item));
- bs = apk_repo_file_open(repo, pkg->arch ?: db->arch, item, file, sizeof(file));
+ bs = apk_repo_file_open(repo, *(pkg->arch ?: db->arch), item, file, sizeof(file));
if (apk_repo_is_remote(repo))
need_copy = TRUE;
}
@@ -2076,14 +2061,14 @@ int apk_db_install_pkg(struct apk_database *db,
{
char *script_args[] = { NULL, NULL, NULL, NULL };
struct apk_installed_package *ipkg;
- int r;
+ int r = 0;
/* Upgrade script gets two args: <new-pkg> <old-pkg> */
if (oldpkg != NULL && newpkg != NULL) {
- script_args[1] = newpkg->version;
- script_args[2] = oldpkg->version;
+ script_args[1] = apk_blob_cstr(*newpkg->version);
+ script_args[2] = apk_blob_cstr(*oldpkg->version);
} else {
- script_args[1] = oldpkg ? oldpkg->version : newpkg->version;
+ script_args[1] = apk_blob_cstr(*(oldpkg ? oldpkg->version : newpkg->version));
}
/* Just purging? */
@@ -2091,19 +2076,18 @@ int apk_db_install_pkg(struct apk_database *db,
ipkg = oldpkg->ipkg;
if (ipkg == NULL)
- return 0;
+ goto ret_r;
r = apk_ipkg_run_script(ipkg, db,
APK_SCRIPT_PRE_DEINSTALL, script_args);
if (r != 0)
- return r;
+ goto ret_r;
apk_db_purge_pkg(db, ipkg, NULL);
r = apk_ipkg_run_script(ipkg, db,
APK_SCRIPT_POST_DEINSTALL, script_args);
apk_pkg_uninstall(db, oldpkg);
-
- return r;
+ goto ret_r;
}
/* Install the new stuff */
@@ -2121,7 +2105,7 @@ int apk_db_install_pkg(struct apk_database *db,
script_args);
if (r != 0) {
apk_pkg_uninstall(db, newpkg);
- return r;
+ goto ret_r;
}
}
@@ -2138,5 +2122,8 @@ int apk_db_install_pkg(struct apk_database *db,
apk_error("%s-%s: Failed to execute post-install/upgrade script",
newpkg->name->name, newpkg->version);
}
+ret_r:
+ free(script_args[1]);
+ free(script_args[2]);
return r;
}
diff --git a/src/index.c b/src/index.c
index e7ed0c3..a6f9cc4 100644
--- a/src/index.c
+++ b/src/index.c
@@ -145,7 +145,7 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv)
for (j = 0; j < name->pkgs->num; j++) {
struct apk_package *pkg = name->pkgs->item[j];
- if (apk_blob_compare(bver, APK_BLOB_STR(pkg->version)) != 0)
+ if (apk_blob_compare(bver, *pkg->version) != 0)
continue;
if (pkg->size != fi.size)
continue;
diff --git a/src/info.c b/src/info.c
index 19a3f48..f345b53 100644
--- a/src/info.c
+++ b/src/info.c
@@ -45,7 +45,7 @@ static void verbose_print_pkg(struct apk_package *pkg, int minimal_verbosity)
printf("%s", pkg->name->name);
if (apk_verbosity > 1)
- printf("-%s", pkg->version);
+ printf("-" BLOB_FMT, BLOB_PRINTF(*pkg->version));
if (apk_verbosity > 2)
printf(" - %s", pkg->description);
printf("\n");
@@ -84,7 +84,7 @@ static int info_exists(struct info_ctx *ctx, struct apk_database *db,
if (j >= name->pkgs->num)
continue;
- if (!(apk_version_compare(pkg->version, dep.version)
+ if (!(apk_version_compare_blob(*pkg->version, *dep.version)
& dep.result_mask))
continue;
@@ -116,8 +116,8 @@ static int info_who_owns(struct info_ctx *ctx, struct apk_database *db,
};
apk_deps_add(&deps, &dep);
} else {
- printf("%s is owned by %s-%s\n", argv[i],
- pkg->name->name, pkg->version);
+ printf("%s is owned by " PKG_VER_FMT "\n",
+ argv[i], PKG_VER_PRINTF(pkg));
}
}
if (apk_verbosity < 1 && deps->num != 0) {
@@ -138,8 +138,9 @@ static void info_print_description(struct apk_package *pkg)
if (apk_verbosity > 1)
printf("%s: %s", pkg->name->name, pkg->description);
else
- printf("%s-%s description:\n%s\n", pkg->name->name,
- pkg->version, pkg->description);
+ printf(PKG_VER_FMT " description:\n%s\n",
+ PKG_VER_PRINTF(pkg),
+ pkg->description);
}
static void info_print_url(struct apk_package *pkg)
@@ -147,7 +148,8 @@ static void info_print_url(struct apk_package *pkg)
if (apk_verbosity > 1)
printf("%s: %s", pkg->name->name, pkg->url);
else
- printf("%s-%s webpage:\n%s\n", pkg->name->name, pkg->version,
+ printf(PKG_VER_FMT " webpage:\n%s\n",
+ PKG_VER_PRINTF(pkg),
pkg->url);
}
@@ -156,7 +158,8 @@ static void info_print_size(struct apk_package *pkg)
if (apk_verbosity > 1)
printf("%s: %zu", pkg->name->name, pkg->installed_size);
else
- printf("%s-%s installed size:\n%zu\n", pkg->name->name, pkg->version,
+ printf(PKG_VER_FMT " installed size:\n%zu\n",
+ PKG_VER_PRINTF(pkg),
pkg->installed_size);
}
@@ -165,7 +168,8 @@ static void info_print_depends(struct apk_package *pkg)
int i;
char *separator = apk_verbosity > 1 ? " " : "\n";
if (apk_verbosity == 1)
- printf("%s-%s depends on:\n", pkg->name->name, pkg->version);
+ printf(PKG_VER_FMT " depends on:\n",
+ PKG_VER_PRINTF(pkg));
if (apk_verbosity > 1)
printf("%s: ", pkg->name->name);
for (i = 0; i < pkg->depends->num; i++)
@@ -178,7 +182,8 @@ static void info_print_required_by(struct apk_package *pkg)
char *separator = apk_verbosity > 1 ? " " : "\n";
if (apk_verbosity == 1)
- printf("%s-%s is required by:\n", pkg->name->name, pkg->version);
+ printf(PKG_VER_FMT " is required by:\n",
+ PKG_VER_PRINTF(pkg));
if (apk_verbosity > 1)
printf("%s: ", pkg->name->name);
for (i = 0; i < pkg->name->rdepends->num; i++) {
@@ -194,8 +199,9 @@ static void info_print_required_by(struct apk_package *pkg)
for (k = 0; k < pkg0->depends->num; k++) {
if (pkg0->depends->item[k].name != pkg->name)
continue;
- printf("%s-%s%s", pkg0->name->name,
- pkg0->version, separator);
+ printf(PKG_VER_FMT "%s",
+ PKG_VER_PRINTF(pkg0),
+ separator);
break;
}
}
@@ -210,7 +216,8 @@ static void info_print_contents(struct apk_package *pkg)
struct hlist_node *dc, *dn, *fc, *fn;
if (apk_verbosity == 1)
- printf("%s-%s contains:\n", pkg->name->name, pkg->version);
+ printf(PKG_VER_FMT " contains:\n",
+ PKG_VER_PRINTF(pkg));
hlist_for_each_entry_safe(diri, dc, dn, &ipkg->owned_dirs,
pkg_dirs_list) {
@@ -229,7 +236,8 @@ static void info_print_triggers(struct apk_package *pkg)
int i;
if (apk_verbosity == 1)
- printf("%s-%s triggers:\n", pkg->name->name, pkg->version);
+ printf(PKG_VER_FMT " triggers:\n",
+ PKG_VER_PRINTF(pkg));
for (i = 0; i < ipkg->triggers->num; i++) {
if (apk_verbosity > 1)
diff --git a/src/package.c b/src/package.c
index e327ce5..db10802 100644
--- a/src/package.c
+++ b/src/package.c
@@ -35,7 +35,7 @@ void apk_pkg_format_plain(struct apk_package *pkg, apk_blob_t to)
/* pkgname-1.0.apk */
apk_blob_push_blob(&to, APK_BLOB_STR(pkg->name->name));
apk_blob_push_blob(&to, APK_BLOB_STR("-"));
- apk_blob_push_blob(&to, APK_BLOB_STR(pkg->version));
+ apk_blob_push_blob(&to, *pkg->version);
apk_blob_push_blob(&to, APK_BLOB_STR(".apk"));
apk_blob_push_blob(&to, APK_BLOB_PTR_LEN("", 1));
}
@@ -45,7 +45,7 @@ void apk_pkg_format_cache(struct apk_package *pkg, apk_blob_t to)
/* pkgname-1.0_alpha1.12345678.apk */
apk_blob_push_blob(&to, APK_BLOB_STR(pkg->name->name));
apk_blob_push_blob(&to, APK_BLOB_STR("-"));
- apk_blob_push_blob(&to, APK_BLOB_STR(pkg->version));
+ apk_blob_push_blob(&to, *pkg->version);
apk_blob_push_blob(&to, APK_BLOB_STR("."));
apk_blob_push_hexdump(&to, APK_BLOB_PTR_LEN((char *) pkg->csum.data,
APK_CACHE_CSUM_BYTES));
@@ -238,7 +238,7 @@ int apk_dep_from_blob(struct apk_dependency *dep, struct apk_database *db,
*dep = (struct apk_dependency){
.name = name,
- .version = APK_BLOB_IS_NULL(bver) ? NULL : apk_blob_cstr(bver),
+ .version = apk_blob_atomize_dup(bver),
.result_mask = mask,
};
return 0;
@@ -295,7 +295,7 @@ void apk_blob_push_dep(apk_blob_t *to, struct apk_dependency *dep)
if (dep->result_mask != APK_DEPMASK_CONFLICT &&
dep->result_mask != APK_DEPMASK_REQUIRE) {
apk_blob_push_blob(to, APK_BLOB_STR(apk_version_op_string(dep->result_mask)));
- apk_blob_push_blob(to, APK_BLOB_STR(dep->version));
+ apk_blob_push_blob(to, *dep->version);
}
}
@@ -612,7 +612,7 @@ int apk_pkg_add_info(struct apk_database *db, struct apk_package *pkg,
pkg->name = apk_db_get_name(db, value);
break;
case 'V':
- pkg->version = apk_blob_cstr(value);
+ pkg->version = apk_blob_atomize_dup(value);
break;
case 'T':
pkg->description = apk_blob_cstr(value);
@@ -621,10 +621,10 @@ int apk_pkg_add_info(struct apk_database *db, struct apk_package *pkg,
pkg->url = apk_blob_cstr(value);
break;
case 'L':
- pkg->license = apk_blob_cstr(value);
+ pkg->license = apk_blob_atomize_dup(value);
break;
case 'A':
- pkg->arch = apk_blob_cstr(value);
+ pkg->arch = apk_blob_atomize_dup(value);
break;
case 'D':
apk_deps_parse(db, &pkg->depends, value);
@@ -763,16 +763,10 @@ void apk_pkg_free(struct apk_package *pkg)
apk_pkg_uninstall(NULL, pkg);
apk_dependency_array_free(&pkg->depends);
- if (pkg->version)
- free(pkg->version);
if (pkg->url)
free(pkg->url);
if (pkg->description)
free(pkg->description);
- if (pkg->license)
- free(pkg->license);
- if (pkg->arch)
- free(pkg->arch);
free(pkg);
}
@@ -822,8 +816,8 @@ int apk_ipkg_run_script(struct apk_installed_package *ipkg,
argv[0] = (char *) apk_script_types[type];
/* Avoid /tmp as it can be mounted noexec */
- snprintf(fn, sizeof(fn), "var/cache/misc/%s-%s.%s",
- pkg->name->name, pkg->version,
+ snprintf(fn, sizeof(fn), "var/cache/misc/" PKG_VER_FMT ".%s",
+ PKG_VER_PRINTF(pkg),
apk_script_types[type]);
apk_message("Executing %s", &fn[15]);
@@ -888,8 +882,8 @@ struct apk_package *apk_pkg_parse_index_entry(struct apk_database *db, apk_blob_
if (ctx.pkg->name == NULL) {
apk_pkg_free(ctx.pkg);
- apk_error("Failed to parse index entry: %.*s",
- blob.len, blob.ptr);
+ apk_error("Failed to parse index entry: " BLOB_FMT,
+ BLOB_PRINTF(blob));
ctx.pkg = NULL;
}
@@ -908,10 +902,10 @@ int apk_pkg_write_index_entry(struct apk_package *info,
apk_blob_push_blob(&bbuf, APK_BLOB_STR("\nP:"));
apk_blob_push_blob(&bbuf, APK_BLOB_STR(info->name->name));
apk_blob_push_blob(&bbuf, APK_BLOB_STR("\nV:"));
- apk_blob_push_blob(&bbuf, APK_BLOB_STR(info->version));
+ apk_blob_push_blob(&bbuf, *info->version);
if (info->arch != NULL) {
apk_blob_push_blob(&bbuf, APK_BLOB_STR("\nA:"));
- apk_blob_push_blob(&bbuf, APK_BLOB_STR(info->arch));
+ apk_blob_push_blob(&bbuf, *info->arch);
}
apk_blob_push_blob(&bbuf, APK_BLOB_STR("\nS:"));
apk_blob_push_uint(&bbuf, info->size, 10);
@@ -922,7 +916,7 @@ int apk_pkg_write_index_entry(struct apk_package *info,
apk_blob_push_blob(&bbuf, APK_BLOB_STR("\nU:"));
apk_blob_push_blob(&bbuf, APK_BLOB_STR(info->url));
apk_blob_push_blob(&bbuf, APK_BLOB_STR("\nL:"));
- apk_blob_push_blob(&bbuf, APK_BLOB_STR(info->license));
+ apk_blob_push_blob(&bbuf, *info->license);
apk_blob_push_blob(&bbuf, APK_BLOB_STR("\n"));
if (APK_BLOB_IS_NULL(bbuf))
@@ -947,5 +941,8 @@ int apk_pkg_write_index_entry(struct apk_package *info,
int apk_pkg_version_compare(struct apk_package *a, struct apk_package *b)
{
- return apk_version_compare(a->version, b->version);
+ if (a->version == b->version)
+ return APK_VERSION_EQUAL;
+
+ return apk_version_compare_blob(*a->version, *b->version);
}
diff --git a/src/print.c b/src/print.c
index 8ee8b25..260809e 100644
--- a/src/print.c
+++ b/src/print.c
@@ -26,7 +26,7 @@ int apk_print_indented(struct apk_indent *i, apk_blob_t blob)
i->x = i->indent;
printf("\n%*s", i->indent - 1, "");
}
- i->x += printf(" %.*s", (int) blob.len, blob.ptr);
+ i->x += printf(" " BLOB_FMT, BLOB_PRINTF(blob));
return 0;
}
diff --git a/src/search.c b/src/search.c
index 14eb0fb..cb8c44d 100644
--- a/src/search.c
+++ b/src/search.c
@@ -28,10 +28,9 @@ static int print_match(struct apk_package *pkg)
{
printf("%s", pkg->name->name);
if (apk_verbosity > 0)
- printf("-%s", pkg->version);
- if (apk_verbosity > 1) {
+ printf("-" BLOB_FMT, BLOB_PRINTF(*pkg->version));
+ if (apk_verbosity > 1)
printf(" - %s", pkg->description);
- }
printf("\n");
return 0;
@@ -46,7 +45,7 @@ static int print_rdepends(struct apk_package *pkg)
name = pkg->name;
- printf("%s-%s:", pkg->name->name, pkg->version);
+ printf(PKG_VER_FMT ":", PKG_VER_PRINTF(pkg));
for (i = 0; i < name->rdepends->num; i++) {
name0 = name->rdepends->item[i];
for (j = 0; j < name0->pkgs->num; j++) {
@@ -54,9 +53,10 @@ static int print_rdepends(struct apk_package *pkg)
for (k = 0; k < pkg0->depends->num; k++) {
dep = &pkg0->depends->item[k];
if (name == dep->name &&
- (apk_version_compare(pkg->version, dep->version)
+ (apk_version_compare_blob(*pkg->version, *dep->version)
& dep->result_mask)) {
- printf(" %s-%s", pkg0->name->name, pkg0->version);
+ printf(" " PKG_VER_FMT,
+ PKG_VER_PRINTF(pkg0));
}
}
}
diff --git a/src/state.c b/src/state.c
index 59315eb..61ff563 100644
--- a/src/state.c
+++ b/src/state.c
@@ -130,7 +130,7 @@ static struct apk_name_choices *name_choices_new(struct apk_database *db,
continue;
for (j = 0; j < nc->num; ) {
- if (apk_version_compare(nc->pkgs[j]->version, dep->version)
+ if (apk_version_compare_blob(*nc->pkgs[j]->version, *dep->version)
& dep->result_mask) {
j++;
} else {
@@ -284,7 +284,7 @@ int apk_state_prune_dependency(struct apk_state *state,
return -1;
}
} else {
- if (!(apk_version_compare(pkg->version, dep->version)
+ if (!(apk_version_compare_blob(*pkg->version, *dep->version)
& dep->result_mask))
return -1;
}
@@ -299,7 +299,7 @@ int apk_state_prune_dependency(struct apk_state *state,
c = ns_to_choices(state->name[name->id]);
i = 0;
while (i < c->num) {
- if (apk_version_compare(c->pkgs[i]->version, dep->version)
+ if (apk_version_compare_blob(*c->pkgs[i]->version, *dep->version)
& dep->result_mask) {
i++;
continue;
@@ -442,7 +442,7 @@ static int call_if_dependency_broke(struct apk_state *state,
dep->result_mask == APK_DEPMASK_CONFLICT)
continue;
if (dep_pkg != NULL &&
- (apk_version_compare(dep_pkg->version, dep->version)
+ (apk_version_compare_blob(*dep_pkg->version, *dep->version)
& dep->result_mask))
continue;
return cb(state, pkg, dep, ctx);
@@ -602,11 +602,13 @@ static void apk_print_change(struct apk_database *db,
name = newpkg->name;
if (oldpkg == NULL) {
- apk_message("%s Installing %s (%s)",
- status, name->name, newpkg->version);
+ apk_message("%s Installing %s (" BLOB_FMT ")",
+ status, name->name,
+ BLOB_PRINTF(*newpkg->version));
} else if (newpkg == NULL) {
- apk_message("%s Purging %s (%s)",
- status, name->name, oldpkg->version);
+ apk_message("%s Purging %s (" BLOB_FMT ")",
+ status, name->name,
+ BLOB_PRINTF(*oldpkg->version));
} else {
r = apk_pkg_version_compare(newpkg, oldpkg);
switch (r) {
@@ -624,9 +626,10 @@ static void apk_print_change(struct apk_database *db,
msg = "Upgrading";
break;
}
- apk_message("%s %s %s (%s -> %s)",
- status, msg, name->name, oldpkg->version,
- newpkg->version);
+ apk_message("%s %s %s (" BLOB_FMT " -> " BLOB_FMT ")",
+ status, msg, name->name,
+ BLOB_PRINTF(*oldpkg->version),
+ BLOB_PRINTF(*newpkg->version));
}
}
@@ -810,8 +813,8 @@ static int print_dep(struct apk_state *state,
if (pkg != es->prevpkg) {
printf("\n");
es->indent.x = 0;
- len = snprintf(buf, sizeof(buf), "%s-%s:",
- pkg->name->name, pkg->version);
+ len = snprintf(buf, sizeof(buf), PKG_VER_FMT ":",
+ PKG_VER_PRINTF(pkg));
apk_print_indented(&es->indent, APK_BLOB_PTR_LEN(buf, len));
es->prevpkg = pkg;
}
@@ -836,7 +839,7 @@ void apk_state_print_errors(struct apk_state *state)
es.prevpkg = pkg = state->conflicts->item[i];
es.indent.x =
- printf(" %s-%s:", pkg->name->name, pkg->version);
+ printf(" " PKG_VER_FMT ":", PKG_VER_PRINTF(pkg));
es.indent.indent = es.indent.x + 1;
for (j = 0; j < pkg->depends->num; j++) {
r = apk_state_lock_dependency(state,
diff --git a/src/update.c b/src/update.c
index 945258d..75b1513 100644
--- a/src/update.c
+++ b/src/update.c
@@ -30,9 +30,8 @@ static int update_main(void *ctx, struct apk_database *db, int argc, char **argv
if (APK_BLOB_IS_NULL(repo->description))
continue;
- apk_message("%.*s [%s]",
- repo->description.len,
- repo->description.ptr,
+ apk_message(BLOB_FMT " [%s]",
+ BLOB_PRINTF(repo->description),
db->repos[i].url);
}
diff --git a/src/ver.c b/src/ver.c
index c4c0079..4d17123 100644
--- a/src/ver.c
+++ b/src/ver.c
@@ -32,9 +32,8 @@ static int ver_indexes(struct apk_database *db, int argc, char **argv)
if (APK_BLOB_IS_NULL(repo->description))
continue;
- printf("%.*s [%s]\n",
- (int) repo->description.len,
- repo->description.ptr,
+ printf(BLOB_FMT " [%s]\n",
+ BLOB_PRINTF(repo->description),
db->repos[i].url);
}
@@ -94,7 +93,8 @@ static void ver_print_package_status(struct apk_package *pkg, const char *limit)
struct apk_name *name;
struct apk_package *tmp;
char pkgname[256];
- const char *opstr, *latest = "";
+ const char *opstr;
+ apk_blob_t *latest = apk_blob_atomize(APK_BLOB_STR(""));
int i, r = -1;
name = pkg->name;
@@ -102,16 +102,18 @@ static void ver_print_package_status(struct apk_package *pkg, const char *limit)
tmp = name->pkgs->item[i];
if (tmp->name != name || tmp->repos == 0)
continue;
- r = apk_version_compare(tmp->version, latest);
+ r = apk_version_compare_blob(*tmp->version, *latest);
if (r == APK_VERSION_GREATER)
latest = tmp->version;
}
- r = apk_version_compare(pkg->version, latest);
+ r = apk_version_compare_blob(*pkg->version, *latest);
opstr = apk_version_op_string(r);
if ((limit != NULL) && (strchr(limit, *opstr) == NULL))
return;
- snprintf(pkgname, sizeof(pkgname), "%s-%s", name->name, pkg->version);
- printf("%-40s%s %s\n", pkgname, opstr, latest);
+ snprintf(pkgname, sizeof(pkgname), PKG_VER_FMT,
+ PKG_VER_PRINTF(pkg));
+ printf("%-40s%s " BLOB_FMT "\n", pkgname, opstr,
+ BLOB_PRINTF(*latest));
}
static int ver_main(void *ctx, struct apk_database *db, int argc, char **argv)