Commit 5c349335 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

db: separate init from open

parent ba7b50c0
......@@ -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;
......
......@@ -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);
......
......@@ -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 ?: "/");
......
......@@ -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");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment