db: convert repository list to a string array

cute-signatures
Timo Teräs 2020-10-05 14:24:08 +03:00
parent 010497cb5a
commit b2af872fff
4 changed files with 8 additions and 25 deletions

View File

@ -63,16 +63,6 @@ static void version(void)
); );
} }
static struct apk_repository_list *apk_repository_new(const char *url)
{
struct apk_repository_list *r = calloc(1, sizeof(struct apk_repository_list));
if (r) {
r->url = url;
list_init(&r->list);
}
return r;
}
#define GLOBAL_OPTIONS(OPT) \ #define GLOBAL_OPTIONS(OPT) \
OPT(OPT_GLOBAL_allow_untrusted, "allow-untrusted") \ OPT(OPT_GLOBAL_allow_untrusted, "allow-untrusted") \
OPT(OPT_GLOBAL_arch, APK_OPT_ARG "arch") \ OPT(OPT_GLOBAL_arch, APK_OPT_ARG "arch") \
@ -118,8 +108,6 @@ APK_OPT_GROUP(optiondesc_global, "Global", GLOBAL_OPTIONS);
static int option_parse_global(void *ctx, struct apk_db_options *dbopts, int opt, const char *optarg) static int option_parse_global(void *ctx, struct apk_db_options *dbopts, int opt, const char *optarg)
{ {
struct apk_repository_list *repo;
switch (opt) { switch (opt) {
case OPT_GLOBAL_help: case OPT_GLOBAL_help:
return -EINVAL; return -EINVAL;
@ -133,8 +121,7 @@ static int option_parse_global(void *ctx, struct apk_db_options *dbopts, int opt
dbopts->repositories_file = optarg; dbopts->repositories_file = optarg;
break; break;
case OPT_GLOBAL_repository: case OPT_GLOBAL_repository:
repo = apk_repository_new(optarg); *apk_string_array_add(&dbopts->repository_list) = (char*) optarg;
if (repo) list_add(&repo->list, &dbopts->repository_list);
break; break;
case OPT_GLOBAL_quiet: case OPT_GLOBAL_quiet:
apk_verbosity--; apk_verbosity--;
@ -471,7 +458,7 @@ int main(int argc, char **argv)
apk_argv[argc+1] = NULL; apk_argv[argc+1] = NULL;
memset(&dbopts, 0, sizeof(dbopts)); memset(&dbopts, 0, sizeof(dbopts));
list_init(&dbopts.repository_list); apk_string_array_init(&dbopts.repository_list);
apk_string_array_init(&dbopts.private_keys); apk_string_array_init(&dbopts.private_keys);
umask(0); umask(0);
setup_terminal(); setup_terminal();

View File

@ -117,11 +117,6 @@ struct apk_repository {
apk_blob_t description; apk_blob_t description;
}; };
struct apk_repository_list {
struct list_head list;
const char *url;
};
struct apk_db_options { struct apk_db_options {
int lock_wait; int lock_wait;
unsigned int cache_max_age; unsigned int cache_max_age;
@ -131,7 +126,7 @@ struct apk_db_options {
const char *keys_dir; const char *keys_dir;
const char *cache_dir; const char *cache_dir;
const char *repositories_file; const char *repositories_file;
struct list_head repository_list; struct apk_string_array *repository_list;
struct apk_string_array *private_keys; struct apk_string_array *private_keys;
}; };

View File

@ -1511,7 +1511,6 @@ void apk_db_init(struct apk_database *db)
int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts) int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
{ {
const char *msg = NULL; const char *msg = NULL;
struct apk_repository_list *repo = NULL;
struct statfs stfs; struct statfs stfs;
apk_blob_t blob; apk_blob_t blob;
int r, fd, write_arch = FALSE; int r, fd, write_arch = FALSE;
@ -1695,8 +1694,10 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
} }
if (!(dbopts->open_flags & APK_OPENF_NO_SYS_REPOS)) { if (!(dbopts->open_flags & APK_OPENF_NO_SYS_REPOS)) {
list_for_each_entry(repo, &dbopts->repository_list, list) char **repo;
apk_db_add_repository(db, APK_BLOB_STR(repo->url));
foreach_array_item(repo, dbopts->repository_list)
apk_db_add_repository(db, APK_BLOB_STR(*repo));
if (dbopts->repositories_file == NULL) { if (dbopts->repositories_file == NULL) {
add_repos_from_file(db, db->root_fd, "etc/apk/repositories"); add_repos_from_file(db, db->root_fd, "etc/apk/repositories");

View File

@ -170,7 +170,7 @@ static int Papk_db_open(lua_State *L)
int r; int r;
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
list_init(&opts.repository_list); apk_string_array_init(&opts.repository_list);
if (lua_istable(L, 1)) if (lua_istable(L, 1))
get_dbopts(L, 1, &opts); get_dbopts(L, 1, &opts);
else else