From: Michael Tremer Date: Sat, 13 Mar 2021 18:25:53 +0000 (+0000) Subject: libpakfire: Drop old cache stuff X-Git-Tag: 0.9.28~1285^2~527 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ada6cb9e249325c4da9756b3f5e13a8862069744;p=pakfire.git libpakfire: Drop old cache stuff Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 429c4938a..be1ee0dc4 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -143,23 +143,6 @@ static PyObject* Pakfire_get_repo(PakfireObject* self, PyObject* args) { 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) @@ -805,13 +788,6 @@ static struct PyGetSetDef Pakfire_getsetters[] = { NULL, NULL }, - { - "cache_path", - (getter)Pakfire_get_cache_path, - (setter)Pakfire_set_cache_path, - NULL, - NULL - }, { "installed_repo", (getter)Pakfire_get_installed_repo, diff --git a/src/_pakfire/repo.c b/src/_pakfire/repo.c index cee9054c7..9010480ce 100644 --- a/src/_pakfire/repo.c +++ b/src/_pakfire/repo.c @@ -344,63 +344,6 @@ static PyObject* Repo_add_archive(RepoObject* self, PyObject* args) { 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); @@ -452,30 +395,6 @@ static struct PyMethodDef Repo_methods[] = { 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, diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index f7c5f06be..1f41640ce 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -153,7 +153,7 @@ static int pakfire_dist_add_source(Pakfire pakfire, struct pakfire_packager* pac 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) { diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index 5ab5d6179..afff55f79 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -56,16 +56,7 @@ void pakfire_set_installed_repo(Pakfire pakfire, PakfireRepo repo); 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 diff --git a/src/libpakfire/include/pakfire/repo.h b/src/libpakfire/include/pakfire/repo.h index 7a8efc78f..0297b1ec2 100644 --- a/src/libpakfire/include/pakfire/repo.h +++ b/src/libpakfire/include/pakfire/repo.h @@ -74,10 +74,6 @@ PakfirePackage pakfire_repo_add_archive(PakfireRepo repo, PakfireArchive archive // 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 diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 200719a2c..5790240f0 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -22,8 +22,6 @@ LIBPAKFIRE_0 { global: # pakfire pakfire_activate; - pakfire_cache_age; - pakfire_cache_stat; pakfire_count_packages; pakfire_create; pakfire_deactivate; @@ -31,7 +29,6 @@ global: pakfire_execute_command; pakfire_execute_script; pakfire_get_arch; - pakfire_get_cache_path; pakfire_get_installed_repo; pakfire_get_installonly; pakfire_get_path; @@ -42,7 +39,6 @@ global: pakfire_read_makefile; pakfire_ref; pakfire_search; - pakfire_set_cache_path; pakfire_set_installed_repo; pakfire_set_installonly; pakfire_unref; @@ -291,16 +287,11 @@ global: # 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; diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index a5eb1f015..87260978c 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -176,6 +176,9 @@ PAKFIRE_EXPORT int pakfire_create(Pakfire* pakfire, const char* path, const char // 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); @@ -206,9 +209,6 @@ PAKFIRE_EXPORT int pakfire_create(Pakfire* pakfire, const char* path, const char if (r) goto ERROR; - // Initialise cache - pakfire_set_cache_path(p, CACHE_PATH); - *pakfire = p; return 0; @@ -651,16 +651,6 @@ PAKFIRE_EXPORT PakfirePackageList pakfire_search(Pakfire pakfire, const char* wh // 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; @@ -691,60 +681,6 @@ PAKFIRE_EXPORT int pakfire_cache_destroy(Pakfire pakfire, const char* path) { 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; } diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 945b1952e..4120d6ffa 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -836,28 +836,8 @@ PAKFIRE_EXPORT PakfirePackage pakfire_repo_add_archive(PakfireRepo repo, Pakfire 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); @@ -865,42 +845,6 @@ PAKFIRE_EXPORT int pakfire_repo_clean(PakfireRepo repo) { 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)