aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/apk_database.h10
-rw-r--r--src/cache.c2
-rw-r--r--src/database.c62
-rw-r--r--src/fetch.c2
-rw-r--r--src/info.c2
-rw-r--r--src/search.c2
6 files changed, 45 insertions, 35 deletions
diff --git a/src/apk_database.h b/src/apk_database.h
index 4fb6ac80eb..1b23d51eb1 100644
--- a/src/apk_database.h
+++ b/src/apk_database.h
@@ -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);
diff --git a/src/cache.c b/src/cache.c
index 152008bc96..e368cb38e5 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -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;
diff --git a/src/database.c b/src/database.c
index fda50db8db..55e97faf18 100644
--- a/src/database.c
+++ b/src/database.c
@@ -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;
+ 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);
+ 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);
+ }
}
- 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_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));
}
diff --git a/src/fetch.c b/src/fetch.c
index 501dff1768..8e53b2c709 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -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;
diff --git a/src/info.c b/src/info.c
index 60dd9105b2..4be29dcef9 100644
--- a/src/info.c
+++ b/src/info.c
@@ -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)
diff --git a/src/search.c b/src/search.c
index 9acf4f3281..52429eb5a4 100644
--- a/src/search.c
+++ b/src/search.c
@@ -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)