]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Load mirrorlist when loading repositories
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 24 Mar 2021 15:52:17 +0000 (15:52 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 24 Mar 2021 15:52:17 +0000 (15:52 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/repo.c

index 10446df7d5a751ca7642bff4fa53940e5a3afe8c..be06c568fa588c67913edf2684bb65067a608321 100644 (file)
@@ -90,13 +90,6 @@ static struct pakfire_downloader* pakfire_repo_downloader(PakfireRepo repo) {
                // Set baseurl
                if (repo->appdata->baseurl)
                        pakfire_downloader_set_baseurl(repo->downloader, repo->appdata->baseurl);
-
-               // Load all mirrors (if the mirrorlist exists)
-               if (repo->appdata->mirrorlist && pakfire_path_exists(repo->appdata->mirrorlist)) {
-                       r = pakfire_mirrorlist_read(repo->appdata->mirrors, repo->appdata->mirrorlist);
-                       if (r)
-                               return NULL;
-               }
        }
 
        return pakfire_downloader_ref(repo->downloader);
@@ -370,18 +363,25 @@ PAKFIRE_EXPORT PakfireRepo pakfire_repo_create(Pakfire pakfire, const char* name
        if (*name == '@')
                return repo;
 
-       // Make path for metadata
-       r = pakfire_make_cache_path(pakfire, repo->appdata->metadata, sizeof(repo->appdata->metadata) - 1,
-               "repodata/%s/repomd.json", pakfire_repo_get_name(repo));
-       if (r < 0)
-               goto ERROR;
-
        // Make path to mirrorlist
        r = pakfire_make_cache_path(pakfire, repo->appdata->mirrorlist, sizeof(repo->appdata->mirrorlist) - 1,
                "repodata/%s/mirrorlist", pakfire_repo_get_name(repo));
        if (r < 0)
                goto ERROR;
 
+       // Try loading the mirrorlist
+       r = pakfire_mirrorlist_read(repo->appdata->mirrors, repo->appdata->mirrorlist);
+       if (r && errno != ENOENT) {
+               ERROR(repo->pakfire, "Could not read the mirrorlist: %s\n", strerror(errno));
+               goto ERROR;
+       }
+
+       // Make path for metadata
+       r = pakfire_make_cache_path(pakfire, repo->appdata->metadata, sizeof(repo->appdata->metadata) - 1,
+               "repodata/%s/repomd.json", pakfire_repo_get_name(repo));
+       if (r < 0)
+               goto ERROR;
+
        // Try loading metadata
        r = pakfire_repo_read_metadata(repo, repo->appdata->metadata, 0);
        if (r) {