diff options
author | Timo Teras <timo.teras@iki.fi> | 2009-01-16 15:14:23 +0200 |
---|---|---|
committer | Timo Teras <timo.teras@iki.fi> | 2009-01-16 15:14:23 +0200 |
commit | 1b5422fb4af4bb836d15e07c86128507147315d0 (patch) | |
tree | 3157af3499f45ab0ba28177e64e33363f2518b71 | |
parent | 6b6c10cdf244d3a307df4c339cde774600d49f49 (diff) | |
download | apk-tools-1b5422fb4af4bb836d15e07c86128507147315d0.tar.gz apk-tools-1b5422fb4af4bb836d15e07c86128507147315d0.tar.bz2 apk-tools-1b5422fb4af4bb836d15e07c86128507147315d0.tar.xz apk-tools-1b5422fb4af4bb836d15e07c86128507147315d0.zip |
index: write out only packages specified in command line
Ignore /etc/apk/repositories, so additional repositories that depend
on other repositories need to have explicit --repository reference on
command line when generating the index (to avoid warnings).
-rw-r--r-- | src/apk_database.h | 2 | ||||
-rw-r--r-- | src/database.c | 41 | ||||
-rw-r--r-- | src/index.c | 10 |
3 files changed, 33 insertions, 20 deletions
diff --git a/src/apk_database.h b/src/apk_database.h index e2f16fa..9710939 100644 --- a/src/apk_database.h +++ b/src/apk_database.h @@ -108,7 +108,7 @@ struct apk_package *apk_db_pkg_add_file(struct apk_database *db, const char *fil struct apk_package *apk_db_get_pkg(struct apk_database *db, csum_t sum); struct apk_package *apk_db_get_file_owner(struct apk_database *db, apk_blob_t filename); -void apk_db_index_write(struct apk_database *db, struct apk_ostream *os); +int apk_db_index_write(struct apk_database *db, struct apk_ostream *os); int apk_db_add_repository(apk_database_t db, apk_blob_t repository); int apk_db_recalculate_and_commit(struct apk_database *db); diff --git a/src/database.c b/src/database.c index 32f224d..92b87b7 100644 --- a/src/database.c +++ b/src/database.c @@ -645,6 +645,15 @@ int apk_db_open(struct apk_database *db, const char *root) free(db->root); return -errno; } + + if (apk_repos == NULL) + apk_repos = "/etc/apk/repositories"; + blob = apk_blob_from_file(apk_repos); + if (!APK_BLOB_IS_NULL(blob)) { + apk_blob_for_each_segment(blob, "\n", + apk_db_add_repository, db); + free(blob.ptr); + } } blob = APK_BLOB_STR("etc:-etc/init.d"); @@ -654,14 +663,6 @@ int apk_db_open(struct apk_database *db, const char *root) if (r != 0) return r; - if (apk_repos == NULL) - apk_repos="/etc/apk/repositories"; - blob = apk_blob_from_file(apk_repos); - if (!APK_BLOB_IS_NULL(blob)) { - apk_blob_for_each_segment(blob, "\n", apk_db_add_repository, db); - free(blob.ptr); - } - if (apk_repository != NULL) apk_db_add_repository(db, APK_BLOB_STR(apk_repository)); @@ -775,25 +776,39 @@ struct apk_package *apk_db_pkg_add_file(struct apk_database *db, const char *fil return info; } +struct index_write_ctx { + struct apk_ostream *os; + int count; +}; + static int write_index_entry(apk_hash_item item, void *ctx) { - struct apk_ostream *os = (struct apk_ostream *) ctx; + struct index_write_ctx *iwctx = (struct index_write_ctx *) ctx; + struct apk_package *pkg = (struct apk_package *) item; char buf[1024]; apk_blob_t blob; - blob = apk_pkg_format_index_entry(item, sizeof(buf), buf); + if (pkg->repos != 0) + return 0; + + blob = apk_pkg_format_index_entry(pkg, sizeof(buf), buf); if (APK_BLOB_IS_NULL(blob)) return 0; - if (os->write(os, blob.ptr, blob.len) != blob.len) + if (iwctx->os->write(iwctx->os, blob.ptr, blob.len) != blob.len) return -1; + iwctx->count++; return 0; } -void apk_db_index_write(struct apk_database *db, struct apk_ostream *os) +int apk_db_index_write(struct apk_database *db, struct apk_ostream *os) { - apk_hash_foreach(&db->available.packages, write_index_entry, (void *) os); + struct index_write_ctx ctx = { os, 0 }; + + apk_hash_foreach(&db->available.packages, write_index_entry, &ctx); + + return ctx.count; } int apk_db_add_repository(apk_database_t _db, apk_blob_t repository) diff --git a/src/index.c b/src/index.c index 81adc51..c272b74 100644 --- a/src/index.c +++ b/src/index.c @@ -16,7 +16,6 @@ #include "apk_database.h" struct counts { - int total; int unsatisfied; }; @@ -34,7 +33,6 @@ static int warn_if_no_providers(apk_hash_item item, void *ctx) "not reporting the rest."); } } - counts->total++; return 0; } @@ -42,16 +40,16 @@ static int warn_if_no_providers(apk_hash_item item, void *ctx) static int index_main(void *ctx, int argc, char **argv) { struct apk_database db; - struct counts counts = {0,0}; + struct counts counts = {0}; struct apk_ostream *os; - int i; + int total, i; apk_db_open(&db, NULL); for (i = 0; i < argc; i++) apk_db_pkg_add_file(&db, argv[i]); os = apk_ostream_to_fd(STDOUT_FILENO); - apk_db_index_write(&db, os); + total = apk_db_index_write(&db, os); os->close(os); apk_hash_foreach(&db.available.names, warn_if_no_providers, &counts); @@ -61,7 +59,7 @@ static int index_main(void *ctx, int argc, char **argv) apk_warning("Total of %d unsatisfiable package " "names. Your repository maybe broken.", counts.unsatisfied); - apk_message("Index has %d packages", counts.total); + apk_message("Index has %d packages", total); return 0; } |