From: Michael Tremer Date: Sat, 13 Mar 2021 14:43:50 +0000 (+0000) Subject: repo: Group all metadata functions together X-Git-Tag: 0.9.28~1285^2~535 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=869cf6a1af3c97e47b5f4048870ffbb05840d53a;p=pakfire.git repo: Group all metadata functions together Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index c2690b9cb..702c44e82 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -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;