db, io: load repositories also from etc/apk/repositories.d/*.list
Load additional repositories from $ROOT/etc/apk/repositories.d/*.list unless --repositories-file is given as parameter.cute-signatures
parent
d633746892
commit
77e203bf32
|
@ -210,7 +210,7 @@ int apk_cache_download(struct apk_database *db, const char *url, apk_blob_t *arc
|
||||||
const char *item, const char *cache_item, int verify);
|
const char *item, const char *cache_item, int verify);
|
||||||
|
|
||||||
typedef void (*apk_cache_item_cb)(struct apk_database *db,
|
typedef void (*apk_cache_item_cb)(struct apk_database *db,
|
||||||
const char *filename,
|
int dirfd, const char *name,
|
||||||
struct apk_package *pkg);
|
struct apk_package *pkg);
|
||||||
int apk_db_cache_foreach_item(struct apk_database *db, apk_cache_item_cb cb);
|
int apk_db_cache_foreach_item(struct apk_database *db, apk_cache_item_cb cb);
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ size_t apk_ostream_write_string(struct apk_ostream *ostream, const char *string)
|
||||||
apk_blob_t apk_blob_from_istream(struct apk_istream *istream, size_t size);
|
apk_blob_t apk_blob_from_istream(struct apk_istream *istream, size_t size);
|
||||||
apk_blob_t apk_blob_from_file(int atfd, const char *file);
|
apk_blob_t apk_blob_from_file(int atfd, const char *file);
|
||||||
|
|
||||||
typedef int apk_dir_file_cb(void *ctx, const char *entry);
|
typedef int apk_dir_file_cb(void *ctx, int dirfd, const char *entry);
|
||||||
|
|
||||||
#define APK_FI_NOFOLLOW 0x80000000
|
#define APK_FI_NOFOLLOW 0x80000000
|
||||||
|
|
||||||
|
|
10
src/cache.c
10
src/cache.c
|
@ -64,16 +64,16 @@ static int cache_download(struct apk_database *db)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cache_clean_item(struct apk_database *db, const char *filename, struct apk_package *pkg)
|
static void cache_clean_item(struct apk_database *db, int dirfd, const char *name, struct apk_package *pkg)
|
||||||
{
|
{
|
||||||
char tmp[PATH_MAX];
|
char tmp[PATH_MAX];
|
||||||
apk_blob_t b;
|
apk_blob_t b;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (pkg != NULL || strcmp(filename, "installed") == 0)
|
if (pkg != NULL || strcmp(name, "installed") == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
b = APK_BLOB_STR(filename);
|
b = APK_BLOB_STR(name);
|
||||||
for (i = 0; i < db->num_repos; i++) {
|
for (i = 0; i < db->num_repos; i++) {
|
||||||
/* Check if this is a valid index */
|
/* Check if this is a valid index */
|
||||||
apk_cache_format_index(APK_BLOB_BUF(tmp), &db->repos[i]);
|
apk_cache_format_index(APK_BLOB_BUF(tmp), &db->repos[i]);
|
||||||
|
@ -82,9 +82,9 @@ static void cache_clean_item(struct apk_database *db, const char *filename, stru
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apk_verbosity >= 2)
|
if (apk_verbosity >= 2)
|
||||||
apk_message("deleting %s", filename);
|
apk_message("deleting %s", name);
|
||||||
if (!(apk_flags & APK_SIMULATE))
|
if (!(apk_flags & APK_SIMULATE))
|
||||||
unlinkat(db->cache_fd, filename, 0);
|
unlinkat(dirfd, name, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cache_clean(struct apk_database *db)
|
static int cache_clean(struct apk_database *db)
|
||||||
|
|
|
@ -1224,7 +1224,7 @@ static void relocate_database(struct apk_database *db)
|
||||||
apk_move_file(db->root_fd, apk_installed_file_old, apk_installed_file);
|
apk_move_file(db->root_fd, apk_installed_file_old, apk_installed_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mark_in_cache(struct apk_database *db, const char *name, struct apk_package *pkg)
|
static void mark_in_cache(struct apk_database *db, int dirfd, const char *name, struct apk_package *pkg)
|
||||||
{
|
{
|
||||||
if (pkg == NULL)
|
if (pkg == NULL)
|
||||||
return;
|
return;
|
||||||
|
@ -1232,6 +1232,29 @@ static void mark_in_cache(struct apk_database *db, const char *name, struct apk_
|
||||||
pkg->in_cache = 1;
|
pkg->in_cache = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int add_repos_from_file(void *ctx, int dirfd, const char *file)
|
||||||
|
{
|
||||||
|
struct apk_database *db = (struct apk_database *) ctx;
|
||||||
|
apk_blob_t blob;
|
||||||
|
|
||||||
|
if (dirfd != db->root_fd) {
|
||||||
|
/* if loading from repositories.d,
|
||||||
|
* the name must end in .list */
|
||||||
|
const char *ext = strrchr(file, '.');
|
||||||
|
if (ext == NULL || strcmp(ext, ".list") != 0)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
blob = apk_blob_from_file(dirfd, file);
|
||||||
|
if (APK_BLOB_IS_NULL(blob))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
apk_blob_for_each_segment(blob, "\n", apk_db_add_repository, db);
|
||||||
|
free(blob.ptr);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
@ -1396,15 +1419,11 @@ 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)
|
list_for_each_entry(repo, &dbopts->repository_list, list)
|
||||||
apk_db_add_repository(db, APK_BLOB_STR(repo->url));
|
apk_db_add_repository(db, APK_BLOB_STR(repo->url));
|
||||||
blob = apk_blob_from_file(
|
|
||||||
db->root_fd,
|
add_repos_from_file(db, db->root_fd, dbopts->repositories_file ?: "etc/apk/repositories");
|
||||||
dbopts->repositories_file ?: "etc/apk/repositories");
|
apk_dir_foreach_file(openat(db->root_fd, "etc/apk/repositories.d", O_RDONLY | O_CLOEXEC),
|
||||||
if (!APK_BLOB_IS_NULL(blob)) {
|
add_repos_from_file, db);
|
||||||
apk_blob_for_each_segment(
|
|
||||||
blob, "\n",
|
|
||||||
apk_db_add_repository, db);
|
|
||||||
free(blob.ptr);
|
|
||||||
}
|
|
||||||
if (apk_flags & APK_UPDATE_CACHE)
|
if (apk_flags & APK_UPDATE_CACHE)
|
||||||
apk_db_index_write_nr_cache(db);
|
apk_db_index_write_nr_cache(db);
|
||||||
}
|
}
|
||||||
|
@ -1630,7 +1649,7 @@ struct foreach_cache_item_ctx {
|
||||||
apk_cache_item_cb cb;
|
apk_cache_item_cb cb;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int foreach_cache_file(void *pctx, const char *name)
|
static int foreach_cache_file(void *pctx, int dirfd, const char *name)
|
||||||
{
|
{
|
||||||
struct foreach_cache_item_ctx *ctx = (struct foreach_cache_item_ctx *) pctx;
|
struct foreach_cache_item_ctx *ctx = (struct foreach_cache_item_ctx *) pctx;
|
||||||
struct apk_database *db = ctx->db;
|
struct apk_database *db = ctx->db;
|
||||||
|
@ -1655,7 +1674,7 @@ static int foreach_cache_file(void *pctx, const char *name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
no_pkg:
|
no_pkg:
|
||||||
ctx->cb(db, name, pkg);
|
ctx->cb(db, dirfd, name, pkg);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
2
src/io.c
2
src/io.c
|
@ -562,7 +562,7 @@ int apk_dir_foreach_file(int dirfd, apk_dir_file_cb cb, void *ctx)
|
||||||
while ((de = readdir(dir)) != NULL) {
|
while ((de = readdir(dir)) != NULL) {
|
||||||
if (de->d_name[0] == '.')
|
if (de->d_name[0] == '.')
|
||||||
continue;
|
continue;
|
||||||
cb(ctx, de->d_name);
|
cb(ctx, dirfd, de->d_name);
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue