db: open flags revisited
more fine grained control what to load, and rename some of the flags to be shorter.cute-signatures
parent
4d940c7932
commit
1a54de02b5
|
@ -116,8 +116,14 @@ struct apk_db_file *apk_db_file_query(struct apk_database *db,
|
|||
#define APK_OPENF_READ 0x0000
|
||||
#define APK_OPENF_WRITE 0x0001
|
||||
#define APK_OPENF_CREATE 0x0002
|
||||
#define APK_OPENF_EMPTY_STATE 0x0004
|
||||
#define APK_OPENF_EMPTY_REPOS 0x0008
|
||||
#define APK_OPENF_NO_INSTALLED 0x0010
|
||||
#define APK_OPENF_NO_SCRIPTS 0x0020
|
||||
#define APK_OPENF_NO_WORLD 0x0040
|
||||
#define APK_OPENF_NO_REPOS 0x0080
|
||||
|
||||
#define APK_OPENF_NO_STATE (APK_OPENF_NO_INSTALLED | \
|
||||
APK_OPENF_NO_SCRIPTS | \
|
||||
APK_OPENF_NO_WORLD)
|
||||
|
||||
int apk_db_open(struct apk_database *db, const char *root, unsigned int flags);
|
||||
int apk_db_write_config(struct apk_database *db);
|
||||
|
|
|
@ -117,7 +117,7 @@ static int cache_main(void *ctx, int argc, char **argv)
|
|||
return -100;
|
||||
|
||||
r = apk_db_open(&db, apk_root,
|
||||
(actions & CACHE_DOWNLOAD) ? 0 : APK_OPENF_EMPTY_STATE);
|
||||
(actions & CACHE_DOWNLOAD) ? 0 : APK_OPENF_NO_STATE);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
|
|
|
@ -576,7 +576,7 @@ static int apk_db_scriptdb_read(struct apk_database *db, struct apk_istream *is)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int apk_db_read_state(struct apk_database *db)
|
||||
static int apk_db_read_state(struct apk_database *db, int flags)
|
||||
{
|
||||
struct apk_istream *is;
|
||||
apk_blob_t blob;
|
||||
|
@ -592,25 +592,31 @@ static int apk_db_read_state(struct apk_database *db)
|
|||
*/
|
||||
fchdir(db->root_fd);
|
||||
|
||||
blob = apk_blob_from_file("var/lib/apk/world");
|
||||
if (APK_BLOB_IS_NULL(blob))
|
||||
return -ENOENT;
|
||||
apk_deps_parse(db, &db->world, blob);
|
||||
free(blob.ptr);
|
||||
if (!(flags & APK_OPENF_NO_WORLD)) {
|
||||
blob = apk_blob_from_file("var/lib/apk/world");
|
||||
if (APK_BLOB_IS_NULL(blob))
|
||||
return -ENOENT;
|
||||
apk_deps_parse(db, &db->world, blob);
|
||||
free(blob.ptr);
|
||||
|
||||
for (i = 0; i < db->world->num; i++)
|
||||
db->world->item[i].name->flags |= APK_NAME_TOPLEVEL;
|
||||
|
||||
is = apk_istream_from_file("var/lib/apk/installed");
|
||||
if (is != NULL) {
|
||||
apk_db_index_read(db, is, -1);
|
||||
is->close(is);
|
||||
for (i = 0; i < db->world->num; i++)
|
||||
db->world->item[i].name->flags |= APK_NAME_TOPLEVEL;
|
||||
}
|
||||
|
||||
is = apk_istream_from_file("var/lib/apk/scripts");
|
||||
if (is != NULL) {
|
||||
apk_db_scriptdb_read(db, is);
|
||||
is->close(is);
|
||||
if (!(flags & APK_OPENF_NO_INSTALLED)) {
|
||||
is = apk_istream_from_file("var/lib/apk/installed");
|
||||
if (is != NULL) {
|
||||
apk_db_index_read(db, is, -1);
|
||||
is->close(is);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(flags & APK_OPENF_NO_SCRIPTS)) {
|
||||
is = apk_istream_from_file("var/lib/apk/scripts");
|
||||
if (is != NULL) {
|
||||
apk_db_scriptdb_read(db, is);
|
||||
is->close(is);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -702,23 +708,21 @@ int apk_db_open(struct apk_database *db, const char *root, unsigned int flags)
|
|||
apk_blob_for_each_segment(blob, ":", add_protected_path, db);
|
||||
|
||||
if (root != NULL) {
|
||||
if (!(flags & APK_OPENF_EMPTY_STATE)) {
|
||||
r = apk_db_read_state(db);
|
||||
if (r == -ENOENT && (flags & APK_OPENF_CREATE)) {
|
||||
r = apk_db_create(db);
|
||||
if (r != 0) {
|
||||
msg = "Unable to create database";
|
||||
goto ret_r;
|
||||
}
|
||||
r = apk_db_read_state(db);
|
||||
}
|
||||
r = apk_db_read_state(db, flags);
|
||||
if (r == -ENOENT && (flags & APK_OPENF_CREATE)) {
|
||||
r = apk_db_create(db);
|
||||
if (r != 0) {
|
||||
msg = "Unable to read database state";
|
||||
msg = "Unable to create database";
|
||||
goto ret_r;
|
||||
}
|
||||
r = apk_db_read_state(db, flags);
|
||||
}
|
||||
if (r != 0) {
|
||||
msg = "Unable to read database state";
|
||||
goto ret_r;
|
||||
}
|
||||
|
||||
if (!(flags & APK_OPENF_EMPTY_REPOS)) {
|
||||
if (!(flags & APK_OPENF_NO_REPOS)) {
|
||||
if (apk_repos == NULL)
|
||||
apk_repos = "/etc/apk/repositories";
|
||||
blob = apk_blob_from_file(apk_repos);
|
||||
|
@ -733,7 +737,7 @@ int apk_db_open(struct apk_database *db, const char *root, unsigned int flags)
|
|||
db->cache_dir = apk_linked_cache_dir;
|
||||
}
|
||||
|
||||
if (!(flags & APK_OPENF_EMPTY_REPOS)) {
|
||||
if (!(flags & APK_OPENF_NO_REPOS)) {
|
||||
list_for_each_entry(repo, &apk_repository_list.list, list)
|
||||
apk_db_add_repository(db, APK_BLOB_STR(repo->url));
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ static int fetch_main(void *ctx, int argc, char **argv)
|
|||
struct apk_database db;
|
||||
int i, j, r;
|
||||
|
||||
r = apk_db_open(&db, apk_root, APK_OPENF_EMPTY_STATE);
|
||||
r = apk_db_open(&db, apk_root, APK_OPENF_NO_STATE);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
|
|
|
@ -313,7 +313,7 @@ static int info_main(void *ctx, int argc, char **argv)
|
|||
struct apk_database db;
|
||||
int r;
|
||||
|
||||
if (apk_db_open(&db, apk_root, APK_OPENF_READ + APK_OPENF_EMPTY_REPOS) < 0)
|
||||
if (apk_db_open(&db, apk_root, APK_OPENF_READ | APK_OPENF_NO_REPOS) < 0)
|
||||
return -1;
|
||||
|
||||
if (ictx->action != NULL)
|
||||
|
|
|
@ -118,7 +118,7 @@ static int search_main(void *ctx, int argc, char **argv)
|
|||
struct apk_database db;
|
||||
int r;
|
||||
|
||||
if (apk_db_open(&db, apk_root, APK_OPENF_READ + APK_OPENF_EMPTY_STATE) < 0)
|
||||
if (apk_db_open(&db, apk_root, APK_OPENF_READ | APK_OPENF_NO_STATE) < 0)
|
||||
return -1;
|
||||
|
||||
if (ictx->action != NULL)
|
||||
|
|
Loading…
Reference in New Issue