From: Michael Tremer Date: Tue, 4 Feb 2025 17:53:56 +0000 (+0000) Subject: pakfire: Split initialization into smaller functions X-Git-Tag: 0.9.30~140 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c36dd4088dbbad89d162702d2fb2a91c5fe70173;p=pakfire.git pakfire: Split initialization into smaller functions Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/pakfire.c b/src/pakfire/pakfire.c index 661b9b01..747323cf 100644 --- a/src/pakfire/pakfire.c +++ b/src/pakfire/pakfire.c @@ -280,15 +280,9 @@ static int pakfire_lock_running_kernel(struct pakfire* pakfire) { return 0; } -static int pakfire_populate_pool(struct pakfire* pakfire) { - struct pakfire_db* db = NULL; - struct pakfire_repo* commandline = NULL; - struct pakfire_repo* dummy = NULL; - struct pakfire_repo* system = NULL; +static int pakfire_setup_pool(struct pakfire* pakfire) { int r; - const char* arch = pakfire_get_effective_arch(pakfire); - // Initialize the pool Pool* pool = pakfire->pool = pool_create(); pool_setdisttype(pool, DISTTYPE_RPM); @@ -302,7 +296,7 @@ static int pakfire_populate_pool(struct pakfire* pakfire) { #endif // Set architecture of the pool - pool_setarchpolicy(pool, arch); + pool_setarchpolicy(pool, pakfire_get_effective_arch(pakfire)); // Set path pool_set_rootdir(pool, pakfire->path); @@ -328,47 +322,71 @@ static int pakfire_populate_pool(struct pakfire* pakfire) { queue_push2(&pool->pooljobs, SOLVER_SOLVABLE_PROVIDES|SOLVER_MULTIVERSION, id); } - // Open database in read-only mode and try to load all installed packages - r = pakfire_db_open(&db, pakfire, PAKFIRE_DB_READWRITE); - if (r) + // Lock the running kernel + if (pakfire_on_root(pakfire)) { + r = pakfire_lock_running_kernel(pakfire); + if (r < 0) + return r; + } + + return 0; +} + +static int pakfire_load_installed_packages(struct pakfire* self) { + struct pakfire_repo* repo = NULL; + struct pakfire_db* db = NULL; + int r; + + // Fetch the system repository + repo = pakfire_get_repo(self, PAKFIRE_REPO_SYSTEM); + + // Open the database (or create a new one) + r = pakfire_db_open(&db, self, PAKFIRE_DB_READWRITE); + if (r < 0) goto ERROR; + // Load database content + r = pakfire_db_load(db, repo); + if (r < 0) + goto ERROR; + +ERROR: + if (repo) + pakfire_repo_unref(repo); + if (db) + pakfire_db_unref(db); + + return r; +} + +static int pakfire_setup_default_repos(struct pakfire* self) { + struct pakfire_repo* commandline = NULL; + struct pakfire_repo* dummy = NULL; + struct pakfire_repo* system = NULL; + int r; + // Create a dummy repository - r = pakfire_repo_create(&dummy, pakfire, PAKFIRE_REPO_DUMMY); - if (r) + r = pakfire_repo_create(&dummy, self, PAKFIRE_REPO_DUMMY); + if (r < 0) goto ERROR; // Disable the repository pakfire_repo_set_enabled(dummy, 0); // Create the system repository - r = pakfire_repo_create(&system, pakfire, PAKFIRE_REPO_SYSTEM); - if (r) + r = pakfire_repo_create(&system, self, PAKFIRE_REPO_SYSTEM); + if (r < 0) goto ERROR; // Set this repository as the installed one - pool_set_installed(pool, pakfire_repo_get_repo(system)); + pool_set_installed(self->pool, pakfire_repo_get_repo(system)); // Create the command line repo - r = pakfire_repo_create(&commandline, pakfire, PAKFIRE_REPO_COMMANDLINE); - if (r) - goto ERROR; - - // Load database content - r = pakfire_db_load(db, system); - if (r) + r = pakfire_repo_create(&commandline, self, PAKFIRE_REPO_COMMANDLINE); + if (r < 0) goto ERROR; - // Lock the running kernel - if (pakfire_on_root(pakfire)) { - r = pakfire_lock_running_kernel(pakfire); - if (r) - goto ERROR; - } - ERROR: - if (db) - pakfire_db_unref(db); if (commandline) pakfire_repo_unref(commandline); if (dummy) @@ -1052,8 +1070,13 @@ int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* ctx, goto ERROR; } - // Populate pool - r = pakfire_populate_pool(p); + // Setup the pool + r = pakfire_setup_pool(p); + if (r < 0) + goto ERROR; + + // Create the default repositories + r = pakfire_setup_default_repos(p); if (r < 0) goto ERROR; @@ -1076,6 +1099,13 @@ int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* ctx, goto ERROR; } + // Load installed packages + if (!pakfire_has_flag(p, PAKFIRE_FLAGS_STUB)) { + r = pakfire_load_installed_packages(p); + if (r < 0) + goto ERROR; + } + // Refresh repositories r = pakfire_repo_walk(p, pakfire_refresh_repo, NULL); if (r < 0)