Skip to content

Commit

Permalink
db, index: fix 'index' loading of old index
Browse files Browse the repository at this point in the history
Now that the cache repository is gone, the index applet cannot
use repository '0' anymore. Introduce and use a new mode to
load the non-database/commandline index.

fixes 460d62e db: extend repositories file format with commands
fixes 35a5754 db: remove APK_REPOSITORY_CACHED and use cache_repository
fixes #11085
  • Loading branch information
fabled committed Feb 21, 2025
1 parent 5fbb854 commit 1458737
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/apk_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ struct apk_repository {
#define APK_DB_LAYER_UVOL 1
#define APK_DB_LAYER_NUM 2

#define APK_REPO_DB_INSTALLED -1
#define APK_REPO_CACHE_INSTALLED -2
#define APK_REPO_NONE -3

#define APK_DEFAULT_REPOSITORY_TAG 0
#define APK_DEFAULT_PINNING_MASK BIT(APK_DEFAULT_REPOSITORY_TAG)

Expand Down
2 changes: 1 addition & 1 deletion src/app_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static int index_read_file(struct apk_database *db, struct index_ctx *ictx)
return 0;

ictx->index_mtime = fi.mtime;
return apk_db_index_read_file(db, ictx->index, 0);
return apk_db_index_read_file(db, ictx->index, APK_REPO_NONE);
}

static int warn_if_no_providers(struct apk_database *db, const char *match, struct apk_name *name, void *ctx)
Expand Down
23 changes: 12 additions & 11 deletions src/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,9 +834,9 @@ static int apk_db_fdb_read(struct apk_database *db, struct apk_istream *is, int

if (repo >= 0) {
tmpl.pkg.repos |= BIT(repo);
} else if (repo == -2) {
} else if (repo == APK_REPO_CACHE_INSTALLED) {
tmpl.pkg.cached_non_repository = 1;
} else if (repo == -1 && ipkg == NULL) {
} else if (repo == APK_REPO_DB_INSTALLED && ipkg == NULL) {
/* Installed package without files */
ipkg = apk_pkg_install(db, &tmpl.pkg);
}
Expand All @@ -860,14 +860,14 @@ static int apk_db_fdb_read(struct apk_database *db, struct apk_istream *is, int
/* Standard index line? */
r = apk_pkgtmpl_add_info(db, &tmpl, field, l);
if (r == 0) continue;
if (r == 1 && repo == -1 && ipkg == NULL) {
if (r == 1 && repo == APK_REPO_DB_INSTALLED && ipkg == NULL) {
/* Instert to installed database; this needs to
* happen after package name has been read, but
* before first FDB entry. */
ipkg = apk_pkg_install(db, &tmpl.pkg);
diri_node = hlist_tail_ptr(&ipkg->owned_dirs);
}
if (repo != -1 || ipkg == NULL) continue;
if (repo != APK_REPO_DB_INSTALLED || ipkg == NULL) continue;

/* Check FDB special entries */
switch (field) {
Expand Down Expand Up @@ -956,7 +956,7 @@ static int apk_db_fdb_read(struct apk_database *db, struct apk_istream *is, int

int apk_db_index_read(struct apk_database *db, struct apk_istream *is, int repo)
{
return apk_db_fdb_read(db, is, repo, 0);
return apk_db_fdb_read(db, is, repo, APK_DB_LAYER_ROOT);
}

static void apk_blob_push_db_acl(apk_blob_t *b, char field, struct apk_db_acl *acl)
Expand Down Expand Up @@ -1222,7 +1222,7 @@ static int apk_db_read_layer(struct apk_database *db, unsigned layer)
}

if (!(flags & APK_OPENF_NO_INSTALLED)) {
r = apk_db_fdb_read(db, apk_istream_from_file(fd, "installed"), -1, layer);
r = apk_db_fdb_read(db, apk_istream_from_file(fd, "installed"), APK_REPO_DB_INSTALLED, layer);
if (!ret && r != -ENOENT) ret = r;
r = apk_db_parse_istream(db, apk_istream_from_file(fd, "triggers"), apk_db_add_trigger);
if (!ret && r != -ENOENT) ret = r;
Expand Down Expand Up @@ -1338,10 +1338,11 @@ struct apkindex_ctx {
static int load_v2index(struct apk_extract_ctx *ectx, apk_blob_t *desc, struct apk_istream *is)
{
struct apkindex_ctx *ctx = container_of(ectx, struct apkindex_ctx, ectx);
struct apk_repository *repo = &ctx->db->repos[ctx->repo];

if (!repo->v2_allowed) return -APKE_FORMAT_INVALID;
repo->description = *apk_atomize_dup(&ctx->db->atoms, *desc);
if (ctx->repo >= 0) {
struct apk_repository *repo = &ctx->db->repos[ctx->repo];
if (!repo->v2_allowed) return -APKE_FORMAT_INVALID;
repo->description = *apk_atomize_dup(&ctx->db->atoms, *desc);
}
return apk_db_index_read(ctx->db, is, ctx->repo);
}

Expand Down Expand Up @@ -2016,7 +2017,7 @@ int apk_db_open(struct apk_database *db)

if (!(ac->open_flags & APK_OPENF_NO_INSTALLED_REPO)) {
if (apk_db_cache_active(db)) {
apk_db_index_read(db, apk_istream_from_file(db->cache_fd, "installed"), -2);
apk_db_index_read(db, apk_istream_from_file(db->cache_fd, "installed"), APK_REPO_CACHE_INSTALLED);
}
}

Expand Down

0 comments on commit 1458737

Please # to comment.