summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2017-04-28 13:28:32 +0300
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2017-04-28 13:28:32 +0300
commit5c349335c76d8b6f1f1e721096d71e3b16f13dbc (patch)
tree4380c3160edbe2349e09ce84237779b6ae45fc5c /src
parentba7b50c0f8ac7c8a88b03856037d9ca6618cccd5 (diff)
downloadapk-tools-5c349335c76d8b6f1f1e721096d71e3b16f13dbc.tar.bz2
apk-tools-5c349335c76d8b6f1f1e721096d71e3b16f13dbc.tar.xz
db: separate init from open
Diffstat (limited to 'src')
-rw-r--r--src/apk.c2
-rw-r--r--src/apk_database.h1
-rw-r--r--src/database.c26
-rw-r--r--src/lua-apk.c1
4 files changed, 19 insertions, 11 deletions
diff --git a/src/apk.c b/src/apk.c
index 37cc4e9..0cf018e 100644
--- a/src/apk.c
+++ b/src/apk.c
@@ -516,6 +516,8 @@ int main(int argc, char **argv)
argv++;
}
+ apk_db_init(&db);
+
#ifdef TEST_MODE
dbopts.open_flags &= ~(APK_OPENF_WRITE | APK_OPENF_CACHE_WRITE | APK_OPENF_CREATE);
dbopts.open_flags |= APK_OPENF_READ | APK_OPENF_NO_STATE | APK_OPENF_NO_REPOS;
diff --git a/src/apk_database.h b/src/apk_database.h
index 610595f..20454d9 100644
--- a/src/apk_database.h
+++ b/src/apk_database.h
@@ -216,6 +216,7 @@ struct apk_db_file *apk_db_file_query(struct apk_database *db,
APK_OPENF_NO_SCRIPTS | \
APK_OPENF_NO_WORLD)
+void apk_db_init(struct apk_database *db);
int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts);
void apk_db_close(struct apk_database *db);
int apk_db_write_config(struct apk_database *db);
diff --git a/src/database.c b/src/database.c
index 80b80e9..8230764 100644
--- a/src/database.c
+++ b/src/database.c
@@ -1471,6 +1471,21 @@ static unsigned long map_statfs_flags(unsigned long f_flag)
return mnt_flags;
}
+void apk_db_init(struct apk_database *db)
+{
+ memset(db, 0, sizeof(*db));
+ apk_hash_init(&db->available.names, &pkg_name_hash_ops, 20000);
+ apk_hash_init(&db->available.packages, &pkg_info_hash_ops, 10000);
+ apk_hash_init(&db->installed.dirs, &dir_hash_ops, 20000);
+ apk_hash_init(&db->installed.files, &file_hash_ops, 200000);
+ list_init(&db->installed.packages);
+ list_init(&db->installed.triggers);
+ apk_dependency_array_init(&db->world);
+ apk_protected_path_array_init(&db->protected_paths);
+ db->permanent = 1;
+ db->root_fd = -1;
+}
+
int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
{
const char *msg = NULL;
@@ -1483,7 +1498,6 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
apk_default_acl_dir = apk_db_acl_atomize(0755, 0, 0, NULL);
apk_default_acl_file = apk_db_acl_atomize(0644, 0, 0, NULL);
- memset(db, 0, sizeof(*db));
if (apk_flags & APK_SIMULATE) {
dbopts->open_flags &= ~(APK_OPENF_CREATE | APK_OPENF_WRITE);
dbopts->open_flags |= APK_OPENF_READ;
@@ -1495,16 +1509,6 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
}
if (!dbopts->cache_dir) dbopts->cache_dir = "etc/apk/cache";
- apk_hash_init(&db->available.names, &pkg_name_hash_ops, 20000);
- apk_hash_init(&db->available.packages, &pkg_info_hash_ops, 10000);
- apk_hash_init(&db->installed.dirs, &dir_hash_ops, 20000);
- apk_hash_init(&db->installed.files, &file_hash_ops, 200000);
- list_init(&db->installed.packages);
- list_init(&db->installed.triggers);
- apk_dependency_array_init(&db->world);
- apk_protected_path_array_init(&db->protected_paths);
- db->permanent = 1;
-
apk_db_setup_repositories(db, dbopts->cache_dir);
db->root = strdup(dbopts->root ?: "/");
diff --git a/src/lua-apk.c b/src/lua-apk.c
index e79e311..532577a 100644
--- a/src/lua-apk.c
+++ b/src/lua-apk.c
@@ -172,6 +172,7 @@ static int Papk_db_open(lua_State *L)
luaL_getmetatable(L, APK_DB_META);
lua_setmetatable(L, -2);
+ apk_db_init(db);
r = apk_db_open(db, &opts);
if (r != 0)
luaL_error(L, "apk_db_open() failed");