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
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",
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;