summaryrefslogtreecommitdiff
path: root/src/app_index.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2020-05-19 11:39:21 +0300
committerTimo Teräs <timo.teras@iki.fi>2020-05-19 12:02:56 +0300
commitd0edeec8fb8fa5abee8b3065cea5e4882d0c51c4 (patch)
tree10dbc6d72c9cef13a26cb539df43e92e4bf78d74 /src/app_index.c
parent12fdf6fc219321d22825042ae08efd322acc0310 (diff)
downloadapk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.tar.gz
apk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.tar.bz2
apk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.tar.xz
apk-tools-d0edeec8fb8fa5abee8b3065cea5e4882d0c51c4.zip
make the atom functions not use global state
This greatly helps with memory management on applications that may want to daemonize and open/close database several times. Also the lifetime and "owner" of memory for all data is now explicitly bound to owning struct apk_database, which might be helpful when writing language bindings. As side effect, the interned "atoms" are unique only within what apk_database, so comparing packages from different apk_database may not work as expected. Fixes #10697
Diffstat (limited to 'src/app_index.c')
-rw-r--r--src/app_index.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/app_index.c b/src/app_index.c
index 4c0b0d1..53e53b0 100644
--- a/src/app_index.c
+++ b/src/app_index.c
@@ -27,7 +27,7 @@ struct index_ctx {
const char *index;
const char *output;
const char *description;
- apk_blob_t *rewrite_arch;
+ const char *rewrite_arch;
time_t index_mtime;
int method;
unsigned short index_flags;
@@ -64,7 +64,7 @@ static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt
ictx->output = optarg;
break;
case OPT_INDEX_rewrite_arch:
- ictx->rewrite_arch = apk_blob_atomize(APK_BLOB_STR(optarg));
+ ictx->rewrite_arch = optarg;
break;
case OPT_INDEX_no_warnings:
ictx->index_flags |= APK_INDEXF_NO_WARNINGS;
@@ -86,7 +86,7 @@ static int index_read_file(struct apk_database *db, struct index_ctx *ictx)
if (ictx->index == NULL)
return 0;
- if (apk_fileinfo_get(AT_FDCWD, ictx->index, APK_CHECKSUM_NONE, &fi) < 0)
+ if (apk_fileinfo_get(AT_FDCWD, ictx->index, APK_CHECKSUM_NONE, &fi, &db->atoms) < 0)
return 0;
ictx->index_mtime = fi.mtime;
@@ -121,6 +121,7 @@ static int index_main(void *ctx, struct apk_database *db, struct apk_string_arra
struct index_ctx *ictx = (struct index_ctx *) ctx;
struct apk_package *pkg;
char **parg;
+ apk_blob_t *rewrite_arch = NULL;
if (isatty(STDOUT_FILENO) && ictx->output == NULL &&
!(apk_force & APK_FORCE_BINARY_STDOUT)) {
@@ -137,8 +138,11 @@ static int index_main(void *ctx, struct apk_database *db, struct apk_string_arra
return r;
}
+ if (ictx->rewrite_arch)
+ rewrite_arch = apk_atomize(&db->atoms, APK_BLOB_STR(ictx->rewrite_arch));
+
foreach_array_item(parg, args) {
- if (apk_fileinfo_get(AT_FDCWD, *parg, APK_CHECKSUM_NONE, &fi) < 0) {
+ if (apk_fileinfo_get(AT_FDCWD, *parg, APK_CHECKSUM_NONE, &fi, &db->atoms) < 0) {
apk_warning("File '%s' is unaccessible", *parg);
continue;
}
@@ -174,15 +178,11 @@ static int index_main(void *ctx, struct apk_database *db, struct apk_string_arra
foreach_array_item(p, name->providers) {
pkg = p->pkg;
- if (pkg->name != name)
- continue;
- if (apk_blob_compare(bver, *pkg->version) != 0)
- continue;
- if (pkg->size != fi.size)
- continue;
+ if (pkg->name != name) continue;
+ if (apk_blob_compare(bver, *pkg->version) != 0) continue;
+ if (pkg->size != fi.size) continue;
pkg->filename = strdup(*parg);
- if (ictx->rewrite_arch != NULL)
- pkg->arch = ictx->rewrite_arch;
+ if (rewrite_arch) pkg->arch = rewrite_arch;
found = TRUE;
break;
}
@@ -197,8 +197,7 @@ static int index_main(void *ctx, struct apk_database *db, struct apk_string_arra
errors++;
} else {
newpkgs++;
- if (ictx->rewrite_arch != NULL)
- pkg->arch = ictx->rewrite_arch;
+ if (rewrite_arch) pkg->arch = rewrite_arch;
}
apk_sign_ctx_free(&sctx);
}