From: Michael Tremer Date: Fri, 31 Jan 2025 10:45:45 +0000 (+0000) Subject: repo: Achor the mirrorlist to the appdata X-Git-Tag: 0.9.30~221 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b7570dfd7673b15a76cdd463f29939574619fa7;p=pakfire.git repo: Achor the mirrorlist to the appdata This is now possible because we won't circle-reference Pakfire any more since we have the ctx object. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/repo.c b/src/pakfire/repo.c index 1c46805f..bbded6c2 100644 --- a/src/pakfire/repo.c +++ b/src/pakfire/repo.c @@ -79,8 +79,10 @@ struct pakfire_repo_appdata { char key[MAX_KEY]; // Mirrorlist + struct pakfire_mirrorlist* mirrorlist; + + // Mirrorlist URL char mirrorlist_url[PATH_MAX]; - char mirrorlist[PATH_MAX]; // Filesystem Layout enum pakfire_repo_filesystem_layout { @@ -101,8 +103,6 @@ struct pakfire_repo { Repo* repo; struct pakfire_repo_appdata* appdata; - struct pakfire_mirrorlist* mirrorlist; - struct pakfire_key* key; }; @@ -490,33 +490,11 @@ CLEANUP: return r; } -struct pakfire_mirrorlist* pakfire_repo_get_mirrorlist(struct pakfire_repo* repo) { - if (!repo->mirrorlist) { - // No cache path set - if (!*repo->appdata->mirrorlist) - return NULL; - - int r = pakfire_mirrorlist_create(&repo->mirrorlist, repo->ctx); - if (r < 0) { - ERROR(repo->ctx, "Could not create mirrorlist: %s\n", strerror(-r)); - return NULL; - } - - // Read the mirrorlist - r = pakfire_mirrorlist_read(repo->mirrorlist, repo->appdata->mirrorlist); - if (r < 0) { - ERROR(repo->ctx, "Could not read mirrorlist %s: %s\n", - repo->appdata->mirrorlist, strerror(-r)); - - // Destroy what we have created - pakfire_mirrorlist_unref(repo->mirrorlist); - repo->mirrorlist = NULL; +struct pakfire_mirrorlist* pakfire_repo_get_mirrorlist(struct pakfire_repo* self) { + if (self->appdata->mirrorlist) + return pakfire_mirrorlist_ref(self->appdata->mirrorlist); - return NULL; - } - } - - return pakfire_mirrorlist_ref(repo->mirrorlist); + return NULL; } static int pakfire_repo_download_database(struct pakfire_repo* repo, @@ -663,55 +641,48 @@ ERROR: return r; } -static int pakfire_repo_refresh_mirrorlist(struct pakfire_repo* repo, const int force) { +static int pakfire_repo_download_mirrorlist(struct pakfire_repo* self, + const char* path, const int force) { struct pakfire_xfer* xfer = NULL; char* url = NULL; + time_t age = -1; int r; - // Local repositories don't need a mirrorlist - if (pakfire_repo_is_local(repo)) - return 0; - // Do nothing if running in offline mode - if (pakfire_ctx_has_flag(repo->ctx, PAKFIRE_CTX_OFFLINE)) + if (pakfire_ctx_has_flag(self->ctx, PAKFIRE_CTX_OFFLINE)) return 0; - // This repository does not have a mirrorlist - if (!*repo->appdata->mirrorlist_url) - return 0; - - // Make path to mirrorlist - r = pakfire_cache_path(repo->pakfire, repo->appdata->mirrorlist, - "repodata/%s/mirrorlist", pakfire_repo_get_name(repo)); - if (r) - goto ERROR; - // Check if this needs to be refreshed if (!force) { - time_t age = pakfire_path_age(repo->appdata->mirrorlist); + age = pakfire_path_age(path); if (age > 0 && age < REFRESH_AGE_MIRRORLIST) { - DEBUG(repo->ctx, "Skip refreshing mirrorlist which is %lds old\n", age); + DEBUG(self->ctx, "Skip refreshing mirrorlist which is %lds old\n", age); return 0; } } // Replace any variables in the URL - url = pakfire_repo_url_replace(repo, repo->appdata->mirrorlist_url); + url = pakfire_repo_url_replace(self, self->appdata->mirrorlist_url); if (!url) { - ERROR(repo->ctx, "Could not expend the mirror list URL: %m\n"); + ERROR(self->ctx, "Could not expand the mirrorlist URL: %m\n"); r = -errno; goto ERROR; } - // Create a new xfer - r = pakfire_repo_xfer_create(&xfer, repo, "%s", url); - if (r) + // Create a new transfer + r = pakfire_repo_xfer_create(&xfer, self, "%s", url); + if (r < 0) goto ERROR; - // Run the xfer + // Set the output path + r = pakfire_xfer_set_output_path(xfer, path); + if (r < 0) + goto ERROR; + + // Perform the transfer r = pakfire_xfer_run(xfer, PAKFIRE_XFER_NO_PROGRESS); - if (r) + if (r < 0) goto ERROR; ERROR: @@ -723,6 +694,58 @@ ERROR: return r; } +static int pakfire_repo_refresh_mirrorlist(struct pakfire_repo* self, const int force) { + struct pakfire_mirrorlist* mirrorlist = NULL; + char path[PATH_MAX]; + int r; + + // Local repositories don't need a mirrorlist + if (pakfire_repo_is_local(self)) + return 0; + + // This repository does not have a mirrorlist + if (!*self->appdata->mirrorlist_url) + return 0; + + // Fetch repo name + const char* name = pakfire_repo_get_name(self); + + // Make path to mirrorlist + r = pakfire_cache_path(self->pakfire, path, "repodata/%s/mirrorlist", name); + if (r < 0) + goto ERROR; + + // Download the mirrorlist + r = pakfire_repo_download_mirrorlist(self, path, force); + if (r < 0) { + ERROR(self->ctx, "Could not download the mirrorlist: %s\n", strerror(-r)); + goto ERROR; + } + + DEBUG(self->ctx, "Reading mirrorlist for %s from %s\n", name, path); + + // Allocate a new mirrorlist + r = pakfire_mirrorlist_create(&mirrorlist, self->ctx); + if (r < 0) + goto ERROR; + +#if 0 // This function seems to SEGV really hard + // Read the mirrorlist + r = pakfire_mirrorlist_read(mirrorlist, path); + if (r < 0) + goto ERROR; +#endif + + // Store the mirrorlist + self->appdata->mirrorlist = pakfire_mirrorlist_ref(mirrorlist); + +ERROR: + if (mirrorlist) + pakfire_mirrorlist_unref(mirrorlist); + + return r; +} + static int pakfire_repo_download_metadata(struct pakfire_repo* repo, const char* path, int force) { struct pakfire_xfer* xfer = NULL; int r; @@ -804,14 +827,14 @@ static void pakfire_repo_free_appdata(struct pakfire_repo_appdata* appdata) { // If there are no further references, automatically destroy the entire repository repo_free(appdata->repo, 0); + if (appdata->mirrorlist) + pakfire_mirrorlist_unref(appdata->mirrorlist); free(appdata); } static void pakfire_repo_free(struct pakfire_repo* self) { if (self->appdata) pakfire_repo_free_appdata(self->appdata); - if (self->mirrorlist) - pakfire_mirrorlist_unref(self->mirrorlist); if (self->pakfire) pakfire_unref(self->pakfire); if (self->key)