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
Timo Teräs 2012-02-22 13:57:05 +02:00
parent d633746892
commit 77e203bf32
5 changed files with 39 additions and 20 deletions

View File

@ -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);
typedef void (*apk_cache_item_cb)(struct apk_database *db,
const char *filename,
int dirfd, const char *name,
struct apk_package *pkg);
int apk_db_cache_foreach_item(struct apk_database *db, apk_cache_item_cb cb);

View File

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

View File

@ -64,16 +64,16 @@ static int cache_download(struct apk_database *db)
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];
apk_blob_t b;
int i;
if (pkg != NULL || strcmp(filename, "installed") == 0)
if (pkg != NULL || strcmp(name, "installed") == 0)
return;
b = APK_BLOB_STR(filename);
b = APK_BLOB_STR(name);
for (i = 0; i < db->num_repos; i++) {
/* Check if this is a valid index */
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)
apk_message("deleting %s", filename);
apk_message("deleting %s", name);
if (!(apk_flags & APK_SIMULATE))
unlinkat(db->cache_fd, filename, 0);
unlinkat(dirfd, name, 0);
}
static int cache_clean(struct apk_database *db)

View File

@ -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);
}
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)
return;
@ -1232,6 +1232,29 @@ static void mark_in_cache(struct apk_database *db, const char *name, struct apk_
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)
{
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)) {
list_for_each_entry(repo, &dbopts->repository_list, list)
apk_db_add_repository(db, APK_BLOB_STR(repo->url));
blob = apk_blob_from_file(
db->root_fd,
dbopts->repositories_file ?: "etc/apk/repositories");
if (!APK_BLOB_IS_NULL(blob)) {
apk_blob_for_each_segment(
blob, "\n",
apk_db_add_repository, db);
free(blob.ptr);
}
add_repos_from_file(db, db->root_fd, dbopts->repositories_file ?: "etc/apk/repositories");
apk_dir_foreach_file(openat(db->root_fd, "etc/apk/repositories.d", O_RDONLY | O_CLOEXEC),
add_repos_from_file, db);
if (apk_flags & APK_UPDATE_CACHE)
apk_db_index_write_nr_cache(db);
}
@ -1630,7 +1649,7 @@ struct foreach_cache_item_ctx {
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 apk_database *db = ctx->db;
@ -1655,7 +1674,7 @@ static int foreach_cache_file(void *pctx, const char *name)
}
}
no_pkg:
ctx->cb(db, name, pkg);
ctx->cb(db, dirfd, name, pkg);
return 0;
}

View File

@ -562,7 +562,7 @@ int apk_dir_foreach_file(int dirfd, apk_dir_file_cb cb, void *ctx)
while ((de = readdir(dir)) != NULL) {
if (de->d_name[0] == '.')
continue;
cb(ctx, de->d_name);
cb(ctx, dirfd, de->d_name);
}
closedir(dir);