return obj;
}
-static PyObject* Pakfire_get_cache_path(PakfireObject* self) {
- const char* path = pakfire_get_cache_path(self->pakfire);
- if (!path)
- Py_RETURN_NONE;
-
- return PyUnicode_FromString(path);
-}
-
-static int Pakfire_set_cache_path(PakfireObject* self, PyObject* value) {
- const char* path = PyUnicode_AsUTF8(value);
-
- if (path)
- pakfire_set_cache_path(self->pakfire, path);
-
- return 0;
-}
-
static PyObject* Pakfire_get_installed_repo(PakfireObject* self) {
PakfireRepo repo = pakfire_get_installed_repo(self->pakfire);
if (!repo)
NULL,
NULL
},
- {
- "cache_path",
- (getter)Pakfire_get_cache_path,
- (setter)Pakfire_set_cache_path,
- NULL,
- NULL
- },
{
"installed_repo",
(getter)Pakfire_get_installed_repo,
return obj;
}
-static PyObject* Repo_cache_age(RepoObject* self, PyObject* args) {
- const char* path = NULL;
-
- if (!PyArg_ParseTuple(args, "s", &path))
- return NULL;
-
- time_t age = pakfire_repo_cache_age(self->repo, path);
- if (age < 0)
- Py_RETURN_NONE;
-
- return PyLong_FromLong(age);
-}
-
-static PyObject* Repo_cache_exists(RepoObject* self, PyObject* args) {
- const char* path = NULL;
-
- if (!PyArg_ParseTuple(args, "s", &path))
- return NULL;
-
- int r = pakfire_repo_cache_access(self->repo, path, F_OK);
- if (r == 0)
- Py_RETURN_TRUE;
-
- Py_RETURN_FALSE;
-}
-
-static PyObject* Repo_cache_open(RepoObject* self, PyObject* args) {
- const char* path = NULL;
- const char* mode = NULL;
-
- if (!PyArg_ParseTuple(args, "ss", &path, &mode))
- return NULL;
-
- FILE* f = pakfire_repo_cache_open(self->repo, path, mode);
- if (!f) {
- PyErr_Format(PyExc_IOError, "Could not open file %s: %s", path, strerror(errno));
- return NULL;
- }
-
- // XXX might cause some problems with internal buffering
- return PyFile_FromFd(fileno(f), NULL, mode, 1, NULL, NULL, NULL, 1);
-}
-
-static PyObject* Repo_cache_path(RepoObject* self, PyObject* args) {
- const char* path = NULL;
-
- if (!PyArg_ParseTuple(args, "s", &path))
- return NULL;
-
- char* cache_path = pakfire_repo_cache_get_path(self->repo, path);
-
- PyObject* obj = PyUnicode_FromString(cache_path);
- free(cache_path);
-
- return obj;
-}
-
static PyObject* Repo_clean(RepoObject* self, PyObject* args) {
int r = pakfire_repo_clean(self->repo);
METH_VARARGS,
NULL
},
- {
- "cache_age",
- (PyCFunction)Repo_cache_age,
- METH_VARARGS,
- NULL
- },
- {
- "cache_exists",
- (PyCFunction)Repo_cache_exists,
- METH_VARARGS,
- NULL
- },
- {
- "cache_open",
- (PyCFunction)Repo_cache_open,
- METH_VARARGS,
- NULL
- },
- {
- "cache_path",
- (PyCFunction)Repo_cache_path,
- METH_VARARGS,
- NULL
- },
{
"clean",
(PyCFunction)Repo_clean,
snprintf(archive_path, sizeof(archive_path) - 1, "files/%s", filename);
snprintf(cache_path, sizeof(cache_path) - 1, "%s/sources/%s/%s",
- pakfire_get_cache_path(pakfire), name, filename);
+ pakfire_make_cache_path(pakfire, ""), name, filename);
// Download the file if it does not exist in the cache
if (access(cache_path, R_OK) != 0) {
PakfirePackageList pakfire_whatprovides(Pakfire pakfire, const char* provides, int flags);
PakfirePackageList pakfire_search(Pakfire pakfire, const char* what, int flags);
-// Cache
-
-const char* pakfire_get_cache_path(Pakfire pakfire);
-void pakfire_set_cache_path(Pakfire pakfire, const char* path);
-
int pakfire_cache_destroy(Pakfire pakfire, const char* path);
-int pakfire_cache_access(Pakfire pakfire, const char* path, int mode);
-int pakfire_cache_stat(Pakfire pakfire, const char* path, struct stat* buffer);
-time_t pakfire_cache_age(Pakfire pakfire, const char* path);
-FILE* pakfire_cache_open(Pakfire pakfire, const char* path, const char* flags);
// Logging
// Cache
int pakfire_repo_clean(PakfireRepo repo);
-char* pakfire_repo_cache_get_path(PakfireRepo repo, const char* path);
-FILE* pakfire_repo_cache_open(PakfireRepo repo, const char* path, const char* mode);
-int pakfire_repo_cache_access(PakfireRepo repo, const char* path, int mode);
-time_t pakfire_repo_cache_age(PakfireRepo repo, const char* path);
// Scan
global:
# pakfire
pakfire_activate;
- pakfire_cache_age;
- pakfire_cache_stat;
pakfire_count_packages;
pakfire_create;
pakfire_deactivate;
pakfire_execute_command;
pakfire_execute_script;
pakfire_get_arch;
- pakfire_get_cache_path;
pakfire_get_installed_repo;
pakfire_get_installonly;
pakfire_get_path;
pakfire_read_makefile;
pakfire_ref;
pakfire_search;
- pakfire_set_cache_path;
pakfire_set_installed_repo;
pakfire_set_installonly;
pakfire_unref;
# repo
pakfire_repo_add_archive;
- pakfire_repo_cache_access;
- pakfire_repo_cache_age;
- pakfire_repo_cache_get_path;
- pakfire_repo_cache_open;
pakfire_repo_cmp;
pakfire_repo_count;
pakfire_repo_clean;
pakfire_repo_create;
pakfire_repo_get_baseurl;
- pakfire_repo_get_cache;
pakfire_repo_get_config;
pakfire_repo_get_description;
pakfire_repo_get_name;
// Set path
snprintf(p->path, sizeof(p->path) - 1, "%s", path);
+ // Set cache path
+ snprintf(p->cache_path, sizeof(p->cache_path) - 1, "%s", CACHE_PATH);
+
// Set architecture
snprintf(p->arch, sizeof(p->arch) - 1, "%s", arch);
if (r)
goto ERROR;
- // Initialise cache
- pakfire_set_cache_path(p, CACHE_PATH);
-
*pakfire = p;
return 0;
// Cache
-PAKFIRE_EXPORT const char* pakfire_get_cache_path(Pakfire pakfire) {
- return pakfire->cache_path;
-}
-
-PAKFIRE_EXPORT void pakfire_set_cache_path(Pakfire pakfire, const char* path) {
- DEBUG(pakfire, "Setting cache path to %s\n", path);
-
- snprintf(pakfire->cache_path, sizeof(pakfire->cache_path) - 1, "%s", path);
-}
-
PAKFIRE_EXPORT char* pakfire_make_cache_path(Pakfire pakfire, const char* format, ...) {
char path[PATH_MAX];
va_list args;
return r;
}
-PAKFIRE_EXPORT int pakfire_cache_stat(Pakfire pakfire, const char* path, struct stat* buffer) {
- char* cache_path = pakfire_make_cache_path(pakfire, path);
-
- int r = stat(cache_path, buffer);
- free(cache_path);
-
- return r;
-}
-
-PAKFIRE_EXPORT int pakfire_cache_access(Pakfire pakfire, const char* path, int mode) {
- char* cache_path = pakfire_make_cache_path(pakfire, path);
-
- int r = pakfire_access(pakfire, cache_path, NULL, mode);
- free(cache_path);
-
- return r;
-}
-
-PAKFIRE_EXPORT time_t pakfire_cache_age(Pakfire pakfire, const char* path) {
- struct stat buffer;
-
- int r = pakfire_cache_stat(pakfire, path, &buffer);
- if (r == 0) {
- // Get current timestamp
- time_t now = time(NULL);
-
- // Calculate the difference since the file has been created and now.
- return now - buffer.st_ctime;
- }
-
- return -1;
-}
-
-PAKFIRE_EXPORT FILE* pakfire_cache_open(Pakfire pakfire, const char* path, const char* flags) {
- FILE* f = NULL;
- char* cache_path = pakfire_make_cache_path(pakfire, path);
-
- // Ensure that the parent directory exists
- char* cache_dirname = pakfire_dirname(cache_path);
-
- int r = pakfire_mkdir(pakfire, cache_dirname, S_IRUSR|S_IWUSR|S_IXUSR);
- if (r)
- goto FAIL;
-
- // Open the file
- f = fopen(cache_path, flags);
-
-FAIL:
- free(cache_path);
- free(cache_dirname);
-
- return f;
-}
-
PAKFIRE_EXPORT pakfire_log_function_t pakfire_log_get_function(Pakfire pakfire) {
return pakfire->log_function;
}
return pakfire_archive_make_package(archive, repo);
}
-// Cache
-
-static char* pakfire_repo_get_cache_prefix(PakfireRepo repo) {
- char* prefix = calloc(1, STRING_SIZE + 1);
-
- snprintf(prefix, STRING_SIZE, "repodata/%s", pakfire_repo_get_name(repo));
-
- return prefix;
-}
-
-static char* pakfire_repo_make_cache_path(PakfireRepo repo, const char* path) {
- char* prefix = pakfire_repo_get_cache_prefix(repo);
-
- // Add the prefix for the repository first
- char* cache_path = pakfire_path_join(prefix, path);
- free(prefix);
-
- return cache_path;
-}
-
PAKFIRE_EXPORT int pakfire_repo_clean(PakfireRepo repo) {
- char* cache_path = pakfire_repo_make_cache_path(repo, NULL);
+ char* cache_path = pakfire_make_cache_path(repo->pakfire, pakfire_repo_get_name(repo));
if (cache_path)
return pakfire_cache_destroy(repo->pakfire, cache_path);
return -1;
}
-PAKFIRE_EXPORT char* pakfire_repo_cache_get_path(PakfireRepo repo, const char* path) {
- char* repo_cache_path = pakfire_repo_make_cache_path(repo, path);
-
- char* cache_path = pakfire_make_cache_path(repo->pakfire, repo_cache_path);
- free(repo_cache_path);
-
- return cache_path;
-}
-
-PAKFIRE_EXPORT FILE* pakfire_repo_cache_open(PakfireRepo repo, const char* path, const char* mode) {
- char* cache_path = pakfire_repo_make_cache_path(repo, path);
-
- FILE* f = pakfire_cache_open(repo->pakfire, cache_path, mode);
- free(cache_path);
-
- return f;
-}
-
-PAKFIRE_EXPORT int pakfire_repo_cache_access(PakfireRepo repo, const char* path, int mode) {
- char* cache_path = pakfire_repo_make_cache_path(repo, path);
-
- int r = pakfire_cache_access(repo->pakfire, cache_path, mode);
- free(cache_path);
-
- return r;
-}
-
-PAKFIRE_EXPORT time_t pakfire_repo_cache_age(PakfireRepo repo, const char* path) {
- char* cache_path = pakfire_repo_make_cache_path(repo, path);
-
- time_t t = pakfire_cache_age(repo->pakfire, cache_path);
- free(cache_path);
-
- return t;
-}
-
static int pakfire_repo_scan_file(PakfireRepo repo, const char* path) {
PakfireArchive archive = pakfire_archive_open(repo->pakfire, path);
if (!archive)