summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/apk_database.h5
-rw-r--r--src/app_update.c12
-rw-r--r--src/database.c59
3 files changed, 45 insertions, 31 deletions
diff --git a/src/apk_database.h b/src/apk_database.h
index 1947df0..aa0145b 100644
--- a/src/apk_database.h
+++ b/src/apk_database.h
@@ -153,7 +153,6 @@ struct apk_database {
unsigned long cache_remount_flags;
apk_blob_t *arch;
unsigned int local_repos, available_repos, cache_max_age;
- unsigned int repo_update_errors, repo_update_counter;
unsigned int pending_triggers;
unsigned int extract_flags;
int performing_self_upgrade : 1;
@@ -172,6 +171,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 e495cbb..680b2f5 100644
--- a/src/app_update.c
+++ b/src/app_update.c
@@ -22,7 +22,7 @@ static int update_main(void *ctx, struct apk_database *db, struct apk_string_arr
char buf[32] = "OK:";
if (apk_verbosity < 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];
@@ -36,13 +36,15 @@ static int update_main(void *ctx, struct apk_database *db, struct apk_string_arr
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_message("%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 2ca5caf..7118c64 100644
--- a/src/database.c
+++ b/src/database.c
@@ -1715,7 +1715,7 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
add_repos_from_file(db, AT_FDCWD, dbopts->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);
@@ -2170,24 +2170,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_url_print urlp;
- int r, verify = (apk_flags & APK_ALLOW_UNTRUSTED) ? APK_SIGN_NONE : APK_SIGN_VERIFY;
-
- r = apk_cache_download(db, repo, NULL, verify, 1, NULL, NULL);
- if (r == -EALREADY) return 0;
- if (r != 0) {
- apk_url_parse(&urlp, repo->url);
- apk_error(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_sign_ctx sctx;
@@ -2259,8 +2241,10 @@ 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 int verify = (apk_flags & APK_ALLOW_UNTRUSTED) ? APK_SIGN_NONE : APK_SIGN_VERIFY;
+ const char *error_action = "opening";
brepo = _repository;
btag = APK_BLOB_NULL;
@@ -2296,14 +2280,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 (!(apk_flags & APK_NO_NETWORK))
db->available_repos |= BIT(repo_num);
if (apk_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_message("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, verify, 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;
}
@@ -2316,11 +2313,23 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t _repository)
r = load_index(db, apk_istream_from_fd_url(atfd, buf), 1, 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_warning("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_warning("%s " URL_FMT ": %s", error_action, URL_PRINTF(urlp),
+ apk_error_str(update_error));
+ }
+
+ if (r != 0) {
db->available_repos &= ~BIT(repo_num);
- r = 0;
+ if (is_remote) db->repositories.unavailable++;
} else {
db->repo_tags[tag_id].allowed_repos |= BIT(repo_num);
}