]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Instead of passing around flags, automatically free the repo
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 Jan 2025 10:09:52 +0000 (10:09 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 Jan 2025 10:09:52 +0000 (10:09 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/repo.c

index ac0219629566b6acc0ad3afc3703905e4ceeb2c5..1c46805f485b6fd647dd2e5281ca42dace3d8bfd 100644 (file)
@@ -62,6 +62,9 @@ struct pakfire_repo_appdata {
        // Reference Counter
        int nrefs;
 
+       // SOLV Repo
+       Repo* repo;
+
        // Description
        char description[MAX_DESCRIPTION];
 
@@ -798,20 +801,13 @@ static void pakfire_repo_free_appdata(struct pakfire_repo_appdata* appdata) {
        if (--appdata->nrefs > 0)
                return;
 
+       // If there are no further references, automatically destroy the entire repository
+       repo_free(appdata->repo, 0);
+
        free(appdata);
 }
 
-static void pakfire_repo_free(struct pakfire_repo* self, const int free_repo) {
-       // Optionally free appdata
-       if (free_repo) {
-               if (self->repo) {
-                       if (self->repo->appdata)
-                               pakfire_repo_free_appdata(self->repo->appdata);
-
-                       repo_free(self->repo, 0);
-               }
-       }
-
+static void pakfire_repo_free(struct pakfire_repo* self) {
        if (self->appdata)
                pakfire_repo_free_appdata(self->appdata);
        if (self->mirrorlist)
@@ -826,18 +822,17 @@ static void pakfire_repo_free(struct pakfire_repo* self, const int free_repo) {
 }
 
 void pakfire_repo_free_all(struct pakfire* pakfire) {
+       Repo* repo = NULL;
+       int i;
+
+       // Fetch the pool
        Pool* pool = pakfire_get_solv_pool(pakfire);
        if (!pool)
                return;
 
-       Repo* repo;
-       int i;
-
        FOR_REPOS(i, repo) {
                if (repo->appdata)
                        pakfire_repo_free_appdata(repo->appdata);
-
-               repo_free(repo, 0);
        }
 }
 
@@ -852,6 +847,9 @@ static int pakfire_repo_setup_appdata(struct pakfire_repo* self) {
        // Initialize the reference counter
        appdata->nrefs = 2;
 
+       // Reference the SOLV repository
+       appdata->repo = self->repo;
+
        // Refresh Interval: Set to invalid
        appdata->refresh = -1;
 
@@ -930,7 +928,9 @@ int pakfire_repo_create(struct pakfire_repo** repo,
        return 0;
 
 ERROR:
-       pakfire_repo_free(self, 1);
+       if (self->appdata)
+               pakfire_repo_free_appdata(self->appdata);
+       pakfire_repo_free(self);
 
        return r;
 }
@@ -975,7 +975,7 @@ struct pakfire_repo* pakfire_repo_unref(struct pakfire_repo* repo) {
        if (--repo->nrefs > 0)
                return repo;
 
-       pakfire_repo_free(repo, 0);
+       pakfire_repo_free(repo);
        return NULL;
 }