diff options
Diffstat (limited to 'src/database.c')
-rw-r--r-- | src/database.c | 57 |
1 files changed, 32 insertions, 25 deletions
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); |