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).cute-signatures
parent
6b6c10cdf2
commit
1b5422fb4a
|
@ -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_pkg(struct apk_database *db, csum_t sum);
|
||||||
struct apk_package *apk_db_get_file_owner(struct apk_database *db, apk_blob_t filename);
|
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_add_repository(apk_database_t db, apk_blob_t repository);
|
||||||
int apk_db_recalculate_and_commit(struct apk_database *db);
|
int apk_db_recalculate_and_commit(struct apk_database *db);
|
||||||
|
|
|
@ -645,6 +645,15 @@ int apk_db_open(struct apk_database *db, const char *root)
|
||||||
free(db->root);
|
free(db->root);
|
||||||
return -errno;
|
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");
|
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)
|
if (r != 0)
|
||||||
return r;
|
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)
|
if (apk_repository != NULL)
|
||||||
apk_db_add_repository(db, APK_BLOB_STR(apk_repository));
|
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;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct index_write_ctx {
|
||||||
|
struct apk_ostream *os;
|
||||||
|
int count;
|
||||||
|
};
|
||||||
|
|
||||||
static int write_index_entry(apk_hash_item item, void *ctx)
|
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];
|
char buf[1024];
|
||||||
apk_blob_t blob;
|
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))
|
if (APK_BLOB_IS_NULL(blob))
|
||||||
return 0;
|
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;
|
return -1;
|
||||||
|
|
||||||
|
iwctx->count++;
|
||||||
return 0;
|
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)
|
int apk_db_add_repository(apk_database_t _db, apk_blob_t repository)
|
||||||
|
|
10
src/index.c
10
src/index.c
|
@ -16,7 +16,6 @@
|
||||||
#include "apk_database.h"
|
#include "apk_database.h"
|
||||||
|
|
||||||
struct counts {
|
struct counts {
|
||||||
int total;
|
|
||||||
int unsatisfied;
|
int unsatisfied;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -34,7 +33,6 @@ static int warn_if_no_providers(apk_hash_item item, void *ctx)
|
||||||
"not reporting the rest.");
|
"not reporting the rest.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
counts->total++;
|
|
||||||
|
|
||||||
return 0;
|
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)
|
static int index_main(void *ctx, int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct apk_database db;
|
struct apk_database db;
|
||||||
struct counts counts = {0,0};
|
struct counts counts = {0};
|
||||||
struct apk_ostream *os;
|
struct apk_ostream *os;
|
||||||
int i;
|
int total, i;
|
||||||
|
|
||||||
apk_db_open(&db, NULL);
|
apk_db_open(&db, NULL);
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
apk_db_pkg_add_file(&db, argv[i]);
|
apk_db_pkg_add_file(&db, argv[i]);
|
||||||
|
|
||||||
os = apk_ostream_to_fd(STDOUT_FILENO);
|
os = apk_ostream_to_fd(STDOUT_FILENO);
|
||||||
apk_db_index_write(&db, os);
|
total = apk_db_index_write(&db, os);
|
||||||
os->close(os);
|
os->close(os);
|
||||||
|
|
||||||
apk_hash_foreach(&db.available.names, warn_if_no_providers, &counts);
|
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 "
|
apk_warning("Total of %d unsatisfiable package "
|
||||||
"names. Your repository maybe broken.",
|
"names. Your repository maybe broken.",
|
||||||
counts.unsatisfied);
|
counts.unsatisfied);
|
||||||
apk_message("Index has %d packages", counts.total);
|
apk_message("Index has %d packages", total);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue