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 {
Repo* repo;
struct pakfire_repo_appdata* appdata;
- struct pakfire_mirrorlist* mirrorlist;
-
struct pakfire_key* key;
};
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,
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:
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;
// 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)