]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Group all metadata functions together
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 13 Mar 2021 14:43:50 +0000 (14:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 13 Mar 2021 14:43:50 +0000 (14:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/repo.c

index c2690b9cbcdf5fa1d026bc393b03abb75ccac38c..702c44e820b1bd73c78eee7d605c4702e7117108 100644 (file)
@@ -182,6 +182,90 @@ ERROR:
        return r;
 }
 
+static int pakfire_repo_refresh_mirrorlist(PakfireRepo repo, const int force) {
+       const char* mirrorlist_url = repo->appdata->mirrorlist_url;
+       const char* mirrorlist = repo->appdata->mirrorlist;
+       int r;
+       char path[PATH_MAX];
+
+       // This repository does not have a mirrorlist
+       if (!mirrorlist_url || !*mirrorlist)
+               return 0;
+
+       // Get the downloader
+       struct pakfire_downloader* downloader = pakfire_repo_downloader(repo);
+       if (!downloader)
+               return 1;
+
+       // Make download path
+       snprintf(path, sizeof(path) - 1, "%s/repodata/%s/.mirrorlist",
+               pakfire_get_cache_path(repo->pakfire), pakfire_repo_get_name(repo));
+
+       // Try to retrieve the mirrorlist
+       r = pakfire_downloader_retrieve(downloader, mirrorlist_url, path);
+       if (r)
+               goto ERROR;
+
+       // Parse it
+       r = pakfire_downloader_read_mirrorlist(downloader, path);
+       if (r && errno != ENOENT) {
+               unlink(path);
+               goto ERROR;
+       }
+
+       // Drop previous version of the mirrorlist
+       unlink(mirrorlist);
+
+       // Link the temporary file to the permanent location
+       r = link(path, mirrorlist);
+       if (r) {
+               ERROR(repo->pakfire, "Could not write mirrorlist %s: %s\n",
+                       mirrorlist, strerror(errno));
+               goto ERROR;
+       }
+
+       // Success
+       r = 0;
+
+ERROR:
+       pakfire_downloader_unref(downloader);
+
+       return r;
+}
+
+static int pakfire_repo_refresh_metadata(PakfireRepo repo, const int force) {
+       // Get the downloader
+       struct pakfire_downloader* downloader = pakfire_repo_downloader(repo);
+       if (!downloader)
+               return 1;
+
+       // Make download path
+       char path[PATH_MAX];
+       snprintf(path, sizeof(path) - 1, "%s/repodata/%s/.repomd.json",
+               pakfire_get_cache_path(repo->pakfire), pakfire_repo_get_name(repo));
+
+       // Try to download the metadata
+       int r = pakfire_downloader_retrieve(downloader, "repodata/repomd.json", path);
+       if (r)
+               goto ERROR;
+
+       // Parse metadata
+       r = pakfire_repo_read_metadata(repo, path, 1);
+       if (r)
+               goto ERROR;
+
+       // Store repodata permanently
+
+       // Success
+       r = 0;
+
+ERROR:
+       pakfire_downloader_unref(downloader);
+       unlink(path);
+
+       return 0;
+}
+
 static void free_repo_appdata(struct pakfire_repo_appdata* appdata) {
        // repodata is being destroyed with the repository
 
@@ -290,7 +374,7 @@ PAKFIRE_EXPORT PakfireRepo pakfire_repo_create(Pakfire pakfire, const char* name
        if (!repo->appdata->mirrorlist)
                goto ERROR;
 
-       // Try loading metadata (ignore if it does not exist)
+       // Try loading metadata
        int r = pakfire_repo_read_metadata(repo, repo->appdata->metadata, 0);
        if (r) {
                ERROR(repo->pakfire, "Could not initialize repository metadata: %s\n",
@@ -871,90 +955,6 @@ ERROR:
        return r;
 }
 
-static int pakfire_repo_refresh_mirrorlist(PakfireRepo repo, const int force) {
-       const char* mirrorlist_url = repo->appdata->mirrorlist_url;
-       const char* mirrorlist = repo->appdata->mirrorlist;
-       int r;
-       char path[PATH_MAX];
-
-       // This repository does not have a mirrorlist
-       if (!mirrorlist_url || !*mirrorlist)
-               return 0;
-
-       // Get the downloader
-       struct pakfire_downloader* downloader = pakfire_repo_downloader(repo);
-       if (!downloader)
-               return 1;
-
-       // Make download path
-       snprintf(path, sizeof(path) - 1, "%s/repodata/%s/.mirrorlist",
-               pakfire_get_cache_path(repo->pakfire), pakfire_repo_get_name(repo));
-
-       // Try to retrieve the mirrorlist
-       r = pakfire_downloader_retrieve(downloader, mirrorlist_url, path);
-       if (r)
-               goto ERROR;
-
-       // Parse it
-       r = pakfire_downloader_read_mirrorlist(downloader, path);
-       if (r && errno != ENOENT) {
-               unlink(path);
-               goto ERROR;
-       }
-
-       // Drop previous version of the mirrorlist
-       unlink(mirrorlist);
-
-       // Link the temporary file to the permanent location
-       r = link(path, mirrorlist);
-       if (r) {
-               ERROR(repo->pakfire, "Could not write mirrorlist %s: %s\n",
-                       mirrorlist, strerror(errno));
-               goto ERROR;
-       }
-
-       // Success
-       r = 0;
-
-ERROR:
-       pakfire_downloader_unref(downloader);
-
-       return r;
-}
-
-static int pakfire_repo_refresh_metadata(PakfireRepo repo, const int force) {
-       // Get the downloader
-       struct pakfire_downloader* downloader = pakfire_repo_downloader(repo);
-       if (!downloader)
-               return 1;
-
-       // Make download path
-       char path[PATH_MAX];
-       snprintf(path, sizeof(path) - 1, "%s/repodata/%s/.repomd.json",
-               pakfire_get_cache_path(repo->pakfire), pakfire_repo_get_name(repo));
-
-       // Try to download the metadata
-       int r = pakfire_downloader_retrieve(downloader, "repodata/repomd.json", path);
-       if (r)
-               goto ERROR;
-
-       // Parse metadata
-       r = pakfire_repo_read_metadata(repo, path, 1);
-       if (r)
-               goto ERROR;
-
-       // Store repodata permanently
-
-       // Success
-       r = 0;
-
-ERROR:
-       pakfire_downloader_unref(downloader);
-       unlink(path);
-
-       return 0;
-}
-
 PAKFIRE_EXPORT int pakfire_repo_refresh(PakfireRepo repo, const int force) {
        int r;