diff options
author | Timo Teräs <timo.teras@iki.fi> | 2022-12-28 13:47:29 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2022-12-28 14:56:29 +0200 |
commit | c24dc49a72155da2e35203cc3a3d3dba8efde220 (patch) | |
tree | 29b7d422317b69aae06bfa5c017e0bfd18a19e93 /src | |
parent | 3448f3148f37bd246643be6669434c6c7f588c90 (diff) | |
download | apk-tools-c24dc49a72155da2e35203cc3a3d3dba8efde220.tar.gz apk-tools-c24dc49a72155da2e35203cc3a3d3dba8efde220.tar.bz2 apk-tools-c24dc49a72155da2e35203cc3a3d3dba8efde220.tar.xz apk-tools-c24dc49a72155da2e35203cc3a3d3dba8efde220.zip |
db: handle repository index update/opening errors more consistently
Track separately autoupdate failure, and opening errors. And print
only one error per index at maximum.
This makes update with or without --no-cache consistent.
Ignore errors from local paths as builders often refer to a local
path that is being built, but might be non-existent when building
the first package.
ref #10726
Diffstat (limited to 'src')
-rw-r--r-- | src/apk_database.h | 5 | ||||
-rw-r--r-- | src/app_update.c | 12 | ||||
-rw-r--r-- | src/database.c | 57 |
3 files changed, 43 insertions, 31 deletions
diff --git a/src/apk_database.h b/src/apk_database.h index 5b495d8..ccc6717 100644 --- a/src/apk_database.h +++ b/src/apk_database.h @@ -141,7 +141,6 @@ struct apk_database { unsigned long cache_remount_flags; apk_blob_t *arch; unsigned int local_repos, available_repos; - unsigned int repo_update_errors, repo_update_counter; unsigned int pending_triggers; unsigned int extract_flags; unsigned int active_layers; @@ -162,6 +161,10 @@ struct apk_database { struct apk_atom_pool atoms; struct { + unsigned stale, updated, unavailable; + } repositories; + + struct { struct apk_hash names; struct apk_hash packages; } available; diff --git a/src/app_update.c b/src/app_update.c index 533cd1c..3a8e25f 100644 --- a/src/app_update.c +++ b/src/app_update.c @@ -24,7 +24,7 @@ static int update_main(void *ctx, struct apk_ctx *ac, struct apk_string_array *a char buf[32] = "OK:"; if (apk_out_verbosity(out) < 1) - return db->repo_update_errors; + return db->repositories.unavailable + db->repositories.stale; for (i = 0; i < db->num_repos; i++) { repo = &db->repos[i]; @@ -38,13 +38,15 @@ static int update_main(void *ctx, struct apk_ctx *ac, struct apk_string_array *a URL_PRINTF(urlp)); } - if (db->repo_update_errors != 0) - snprintf(buf, sizeof(buf), "%d errors;", - db->repo_update_errors); + if (db->repositories.unavailable || db->repositories.stale) + snprintf(buf, sizeof(buf), "%d unavailable, %d stale;", + db->repositories.unavailable, + db->repositories.stale); + apk_msg(out, "%s %d distinct packages available", buf, db->available.packages.num_items); - return db->repo_update_errors; + return db->repositories.unavailable + db->repositories.stale; } static struct apk_applet apk_update = { diff --git a/src/database.c b/src/database.c index 71d2d68..9cbe20e 100644 --- a/src/database.c +++ b/src/database.c @@ -1780,7 +1780,7 @@ int apk_db_open(struct apk_database *db, struct apk_ctx *ac) add_repos_from_file(db, AT_FDCWD, ac->repositories_file); } - if (db->repo_update_counter) + if (db->repositories.updated > 0) apk_db_index_write_nr_cache(db); apk_hash_foreach(&db->available.names, apk_db_name_rdepends, db); @@ -2265,25 +2265,6 @@ struct apk_repository *apk_db_select_repo(struct apk_database *db, return &db->repos[APK_REPOSITORY_CACHED]; } -static int apk_repository_update(struct apk_database *db, struct apk_repository *repo) -{ - struct apk_out *out = &db->ctx->out; - struct apk_url_print urlp; - int r; - - r = apk_cache_download(db, repo, NULL, 1, NULL, NULL); - if (r == -EALREADY) return 0; - if (r != 0) { - apk_url_parse(&urlp, repo->url); - apk_err(out, URL_FMT ": %s", URL_PRINTF(urlp), apk_error_str(r)); - db->repo_update_errors++; - } else { - db->repo_update_counter++; - } - - return r; -} - struct apkindex_ctx { struct apk_database *db; struct apk_extract_ctx ectx; @@ -2352,8 +2333,9 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t _repository) struct apk_repository *repo; struct apk_url_print urlp; apk_blob_t brepo, btag; - int repo_num, r, tag_id = 0, atfd = AT_FDCWD; + int repo_num, r, tag_id = 0, atfd = AT_FDCWD, update_error = 0; char buf[PATH_MAX], *url; + const char *error_action = "opening"; brepo = _repository; btag = APK_BLOB_NULL; @@ -2389,14 +2371,27 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t _repository) apk_blob_checksum(brepo, apk_checksum_default(), &repo->csum); - if (apk_url_local_file(repo->url) == NULL) { + int is_remote = (apk_url_local_file(repo->url) == NULL); + if (is_remote) { if (!(db->ctx->flags & APK_NO_NETWORK)) db->available_repos |= BIT(repo_num); if (db->ctx->flags & APK_NO_CACHE) { + error_action = "fetching"; r = apk_repo_format_real_url(db->arch, repo, NULL, buf, sizeof(buf), &urlp); if (r == 0) apk_msg(out, "fetch " URL_FMT, URL_PRINTF(urlp)); } else { - if (db->autoupdate) apk_repository_update(db, repo); + error_action = "opening from cache"; + if (db->autoupdate) { + update_error = apk_cache_download(db, repo, NULL, 1, NULL, NULL); + switch (update_error) { + case 0: + db->repositories.updated++; + break; + case -EALREADY: + update_error = 0; + break; + } + } r = apk_repo_format_cache_index(APK_BLOB_BUF(buf), repo); atfd = db->cache_fd; } @@ -2409,9 +2404,21 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t _repository) r = load_index(db, apk_istream_from_fd_url(atfd, buf, apk_db_url_since(db, 0)), repo_num); } - if (r != 0) { + if (r || update_error) { + if (is_remote) { + if (r) db->repositories.unavailable++; + else db->repositories.stale++; + } apk_url_parse(&urlp, repo->url); - apk_warn(out, "Ignoring " URL_FMT ": %s", URL_PRINTF(urlp), apk_error_str(r)); + if (update_error) + error_action = r ? "updating and opening" : "updating"; + else + update_error = r; + apk_warn(out, "%s " URL_FMT ": %s", error_action, URL_PRINTF(urlp), + apk_error_str(update_error)); + } + + if (r != 0) { db->available_repos &= ~BIT(repo_num); } else { db->repo_tags[tag_id].allowed_repos |= BIT(repo_num); |