Merge branch 'master' of ssh://dev.alpinelinux.org/gitroot/apk-tools

cute-signatures
Natanael Copa 2009-01-16 13:18:47 +00:00
commit 61341384b3
3 changed files with 33 additions and 20 deletions

View File

@ -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);

View File

@ -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)

View File

@ -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;
}