return pakfire_repo_set_mirrorlist(self->repo, mirrorlist);
}
+static PyObject* Repo_refresh(RepoObject* self, PyObject* args, PyObject* kwds) {
+ char* kwlist[] = { "force", NULL };
+
+ int force = 0;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|p", kwlist, &force))
+ return NULL;
+
+ int r = pakfire_repo_refresh(self->repo, force);
+ if (r) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
static PyObject* Repo_get_config(RepoObject* self) {
char* config = pakfire_repo_get_config(self->repo);
METH_VARARGS,
NULL
},
+ {
+ "refresh",
+ (PyCFunction)Repo_refresh,
+ METH_VARARGS|METH_KEYWORDS,
+ NULL,
+ },
{
"write_solv",
(PyCFunction)Repo_write_solv,
#include <assert.h>
#include <errno.h>
#include <fts.h>
+#include <linux/limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <pakfire/archive.h>
#include <pakfire/constants.h>
+#include <pakfire/downloader.h>
#include <pakfire/errno.h>
#include <pakfire/logging.h>
#include <pakfire/package.h>
char* description;
char* baseurl;
char* keyfile;
- char* mirrorlist;
+
+ // Mirrorlist
+ char* mirrorlist_url;
+ char mirrorlist[PATH_MAX];
};
struct _PakfireRepo {
Repo* repo;
struct pakfire_repo_appdata* appdata;
int nrefs;
+
+ struct pakfire_downloader* downloader;
};
Id pakfire_repo_add_solvable(PakfireRepo repo) {
if (appdata->keyfile)
free(appdata->keyfile);
- if (appdata->mirrorlist)
- free(appdata->mirrorlist);
+ if (appdata->mirrorlist_url)
+ free(appdata->mirrorlist_url);
free(appdata);
}
repo->appdata->repodata = repo_add_repodata(repo->repo,
REPO_EXTEND_SOLVABLES|REPO_LOCALPOOL|REPO_NO_INTERNALIZE|REPO_NO_LOCATION);
+
+ // Make path to mirrorlist
+ snprintf(repo->appdata->mirrorlist, sizeof(repo->appdata->mirrorlist) - 1,
+ "%s/repodata/%s/mirrorlist", pakfire_get_cache_path(repo->pakfire),
+ pakfire_repo_get_name(repo));
}
return repo;
static void pakfire_repo_free(PakfireRepo repo) {
DEBUG(repo->pakfire, "Releasing Repo at %p\n", repo);
+
+ if (repo->downloader)
+ pakfire_downloader_unref(repo->downloader);
pakfire_unref(repo->pakfire);
free(repo);
}
PAKFIRE_EXPORT const char* pakfire_repo_get_mirrorlist(PakfireRepo repo) {
- return repo->appdata->mirrorlist;
+ return repo->appdata->mirrorlist_url;
}
PAKFIRE_EXPORT int pakfire_repo_set_mirrorlist(PakfireRepo repo, const char* mirrorlist) {
- if (repo->appdata->mirrorlist)
- free(repo->appdata->mirrorlist);
+ if (repo->appdata->mirrorlist_url)
+ free(repo->appdata->mirrorlist_url);
if (mirrorlist)
- repo->appdata->mirrorlist = strdup(mirrorlist);
+ repo->appdata->mirrorlist_url = strdup(mirrorlist);
else
- repo->appdata->mirrorlist = NULL;
+ repo->appdata->mirrorlist_url = NULL;
return 0;
}
return r;
}
-static int pakfire_repo_refresh_mirrorlist(PakfireRepo repo, int force) {
- return 0;
+static struct pakfire_downloader* pakfire_repo_downloader(PakfireRepo repo) {
+ const char* mirrorlist = repo->appdata->mirrorlist;
+
+ if (!repo->downloader) {
+ int r = pakfire_downloader_create(&repo->downloader, repo->pakfire);
+ if (r)
+ return NULL;
+
+ // Load all mirrors
+ if (*mirrorlist) {
+ r = pakfire_downloader_read_mirrorlist(repo->downloader, mirrorlist);
+ if (r)
+ return NULL;
+ }
+ }
+
+ return pakfire_downloader_ref(repo->downloader);
+}
+
+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) {
+ 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, int force) {
+static int pakfire_repo_refresh_metadata(PakfireRepo repo, const int force) {
return 0;
}
return 0;
}
-PAKFIRE_EXPORT int pakfire_repo_refresh(PakfireRepo repo, int force) {
+PAKFIRE_EXPORT int pakfire_repo_refresh(PakfireRepo repo, const int force) {
int r;
+ // Do nothing if this repository is not enabled
+ int enabled = pakfire_repo_get_enabled(repo);
+ if (!enabled) {
+ DEBUG(repo->pakfire, "Skip refreshing repository '%s'\n",
+ pakfire_repo_get_name(repo));
+ return 0;
+ }
+
// Refresh mirrorlist
r = pakfire_repo_refresh_mirrorlist(repo, force);
if (r)