From 5ade5e8a1e31e0eb0f4128c0e2fd39916198289e Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 19 Jan 2018 14:20:44 +0100 Subject: [PATCH] libpakfire: Drop repocache Signed-off-by: Michael Tremer --- Makefile.am | 2 - src/_pakfire/repo.c | 56 ++++------- src/libpakfire/include/pakfire/repo.h | 9 +- src/libpakfire/include/pakfire/repocache.h | 60 ------------ src/libpakfire/libpakfire.sym | 14 +-- src/libpakfire/package.c | 1 - src/libpakfire/repo.c | 48 +++++++--- src/libpakfire/repocache.c | 102 --------------------- 8 files changed, 67 insertions(+), 225 deletions(-) delete mode 100644 src/libpakfire/include/pakfire/repocache.h delete mode 100644 src/libpakfire/repocache.c diff --git a/Makefile.am b/Makefile.am index b64a95a03..cfe38bf93 100644 --- a/Makefile.am +++ b/Makefile.am @@ -260,7 +260,6 @@ libpakfire_la_SOURCES = \ src/libpakfire/relation.c \ src/libpakfire/relationlist.c \ src/libpakfire/repo.c \ - src/libpakfire/repocache.c \ src/libpakfire/request.c \ src/libpakfire/selector.c \ src/libpakfire/solution.c \ @@ -288,7 +287,6 @@ pkginclude_HEADERS += \ src/libpakfire/include/pakfire/relation.h \ src/libpakfire/include/pakfire/relationlist.h \ src/libpakfire/include/pakfire/repo.h \ - src/libpakfire/include/pakfire/repocache.h \ src/libpakfire/include/pakfire/request.h \ src/libpakfire/include/pakfire/selector.h \ src/libpakfire/include/pakfire/solution.h \ diff --git a/src/_pakfire/repo.c b/src/_pakfire/repo.c index 9d96cc3f7..48b17e74c 100644 --- a/src/_pakfire/repo.c +++ b/src/_pakfire/repo.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include "package.h" @@ -226,74 +225,55 @@ static PyObject* Repo__add_package(RepoObject* self, PyObject* args) { } static PyObject* Repo_cache_age(RepoObject* self, PyObject* args) { - const char* filename = NULL; + const char* path = NULL; - if (!PyArg_ParseTuple(args, "s", &filename)) + if (!PyArg_ParseTuple(args, "s", &path)) return NULL; - PakfireRepoCache cache = pakfire_repo_get_cache(self->repo); - if (!cache) - Py_RETURN_NONE; - - int age = pakfire_repocache_age(cache, filename); - + time_t age = pakfire_repo_cache_age(self->repo, path); if (age < 0) Py_RETURN_NONE; - PyObject* ret = PyLong_FromLong(age); - return ret; + return PyLong_FromLong(age); } static PyObject* Repo_cache_exists(RepoObject* self, PyObject* args) { - const char* filename = NULL; + const char* path = NULL; - if (!PyArg_ParseTuple(args, "s", &filename)) + if (!PyArg_ParseTuple(args, "s", &path)) return NULL; - PakfireRepoCache cache = pakfire_repo_get_cache(self->repo); - if (!cache) - Py_RETURN_NONE; - - int ret = pakfire_repocache_has_file(cache, filename); - - if (ret) + 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* filename = NULL; - char* mode = NULL; + const char* path = NULL; + const char* mode = NULL; - if (!PyArg_ParseTuple(args, "ss", &filename, &mode)) + if (!PyArg_ParseTuple(args, "ss", &path, &mode)) return NULL; - PakfireRepoCache cache = pakfire_repo_get_cache(self->repo); - if (!cache) - Py_RETURN_NONE; - - FILE* fp = pakfire_repocache_open(cache, filename, mode); - if (!fp) { - PyErr_Format(PyExc_IOError, "Could not open file %s: %s", filename, strerror(errno)); + 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(fp), NULL, mode, 1, NULL, NULL, NULL, 1); + return PyFile_FromFd(fileno(f), NULL, mode, 1, NULL, NULL, NULL, 1); } static PyObject* Repo_cache_path(RepoObject* self, PyObject* args) { - const char* filename = NULL; + const char* path = NULL; - if (!PyArg_ParseTuple(args, "s", &filename)) + if (!PyArg_ParseTuple(args, "s", &path)) return NULL; - PakfireRepoCache cache = pakfire_repo_get_cache(self->repo); - if (!cache) - Py_RETURN_NONE; - - char* cache_path = pakfire_repocache_get_full_path(cache, filename); + char* cache_path = pakfire_repo_cache_get_path(self->repo, path); PyObject* obj = PyUnicode_FromString(cache_path); pakfire_free(cache_path); diff --git a/src/libpakfire/include/pakfire/repo.h b/src/libpakfire/include/pakfire/repo.h index baf985205..d65b83b67 100644 --- a/src/libpakfire/include/pakfire/repo.h +++ b/src/libpakfire/include/pakfire/repo.h @@ -21,6 +21,9 @@ #ifndef PAKFIRE_REPO_H #define PAKFIRE_REPO_H +#include +#include + #include PakfireRepo pakfire_repo_create(Pakfire pakfire, const char* name); @@ -53,9 +56,13 @@ int pakfire_repo_read_solv_fp(PakfireRepo repo, FILE *f, int flags); int pakfire_repo_write_solv(PakfireRepo repo, const char* filename, int flags); int pakfire_repo_write_solv_fp(PakfireRepo repo, FILE *f, int flags); -PakfireRepoCache pakfire_repo_get_cache(PakfireRepo repo); +// 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); #ifdef PAKFIRE_PRIVATE diff --git a/src/libpakfire/include/pakfire/repocache.h b/src/libpakfire/include/pakfire/repocache.h deleted file mode 100644 index 02f5307ae..000000000 --- a/src/libpakfire/include/pakfire/repocache.h +++ /dev/null @@ -1,60 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2013 Pakfire development team # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -#############################################################################*/ - -#ifndef PAKFIRE_REPOCACHE_H -#define PAKFIRE_REPOCACHE_H - -#include - -#include - -PakfireRepoCache pakfire_repocache_create(PakfireRepo repo); -void pakfire_repocache_free(PakfireRepoCache repo_cache); - -char* pakfire_repocache_get_cache_path(PakfireRepoCache repo_cache, const char* path); -char* pakfire_repocache_get_full_path(PakfireRepoCache repo_cache, const char* path); - -int pakfire_repocache_has_file(PakfireRepoCache repo_cache, const char* filename); -int pakfire_repocache_age(PakfireRepoCache repo_cache, const char* filename); - -FILE* pakfire_repocache_open(PakfireRepoCache repo_cache, const char* filename, const char* flags); - -int pakfire_repocache_destroy(PakfireRepoCache repo_cache); - -#ifdef PAKFIRE_PRIVATE - -struct _PakfireRepoCache { - PakfireRepo repo; - char* prefix; -}; - -inline PakfirePool pakfire_repocache_pool(PakfireRepoCache repo_cache) { - return pakfire_repo_get_pool(repo_cache->repo); -} - -inline PakfireCache pakfire_repocache_cache(PakfireRepoCache repo_cache) { - PakfirePool pool = pakfire_repocache_pool(repo_cache); - - return pakfire_pool_get_cache(pool); -} - -#endif - -#endif /* PAKFIRE_REPOCACHE_H */ diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 9dbb252da..5c7db0be7 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -220,6 +220,10 @@ global: pakfire_problem_unref; # repo + 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; @@ -243,16 +247,6 @@ global: pakfire_repo_write_solv_fp; pakfire_repo_unref; - # repocache - pakfire_repocache_age; - pakfire_repocache_create; - pakfire_repocache_destroy; - pakfire_repocache_free; - pakfire_repocache_get_cache_path; - pakfire_repocache_get_full_path; - pakfire_repocache_has_file; - pakfire_repocache_open; - # relation pakfire_relation_create; pakfire_relation_create_from_id; diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 1b3e9e416..19a4ad926 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -43,7 +43,6 @@ #include #include #include -#include #include struct _PakfirePackage { diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index d1104088d..0220fc089 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -37,7 +37,6 @@ #include #include #include -#include #include #include @@ -47,7 +46,6 @@ const size_t XZ_HEADER_LENGTH = sizeof(XZ_HEADER_MAGIC); struct _PakfireRepo { Pakfire pakfire; Repo* repo; - PakfireRepoCache cache; Repodata* filelist; int nrefs; }; @@ -109,7 +107,6 @@ PAKFIRE_EXPORT PakfireRepo pakfire_repo_create_from_repo(Pakfire pakfire, Repo* repo->pakfire = pakfire_ref(pakfire); repo->repo = r; - repo->cache = pakfire_repocache_create(repo); repo->filelist = repo_add_repodata(r, REPO_EXTEND_SOLVABLES|REPO_LOCALPOOL|REPO_NO_INTERNALIZE|REPO_NO_LOCATION); @@ -128,9 +125,6 @@ static void pakfire_repo_free(PakfireRepo repo) { if (repo->repo) repo->repo->appdata = NULL; - if (repo->cache) - pakfire_repocache_free(repo->cache); - pakfire_unref(repo->pakfire); pakfire_free(repo); @@ -430,11 +424,7 @@ PAKFIRE_EXPORT PakfirePackage pakfire_repo_add_package(PakfireRepo repo) { return pakfire_package_create(repo->pakfire, id); } -PAKFIRE_EXPORT PakfireRepoCache pakfire_repo_get_cache(PakfireRepo repo) { - assert(repo); - - return repo->cache; -} +// Cache static char* pakfire_repo_get_cache_prefix(PakfireRepo repo) { char* prefix = pakfire_calloc(1, STRING_SIZE + 1); @@ -462,3 +452,39 @@ 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_get_cache_path(repo->pakfire, repo_cache_path); + pakfire_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); + pakfire_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); + pakfire_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); + pakfire_free(cache_path); + + return t; +} diff --git a/src/libpakfire/repocache.c b/src/libpakfire/repocache.c deleted file mode 100644 index 9bc1b8c30..000000000 --- a/src/libpakfire/repocache.c +++ /dev/null @@ -1,102 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2013 Pakfire development team # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -#############################################################################*/ - -#define _XOPEN_SOURCE 500 -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -static char* pakfire_repocache_prefix(PakfireRepoCache repo_cache) { - const char* repo_name = pakfire_repo_get_name(repo_cache->repo); - - char buffer[STRING_SIZE] = ""; - snprintf(buffer, sizeof(buffer), "repodata/%s", repo_name); - - return pakfire_strdup(buffer); -} - -PAKFIRE_EXPORT PakfireRepoCache pakfire_repocache_create(PakfireRepo repo) { - PakfireRepoCache repo_cache = pakfire_calloc(1, sizeof(*repo_cache)); - - repo_cache->repo = repo; - repo_cache->prefix = pakfire_repocache_prefix(repo_cache); - - return repo_cache; -} - -PAKFIRE_EXPORT void pakfire_repocache_free(PakfireRepoCache repo_cache) { - pakfire_free(repo_cache->prefix); - pakfire_free(repo_cache); -} - -PAKFIRE_EXPORT char* pakfire_repocache_get_cache_path(PakfireRepoCache repo_cache, const char* path) { - return pakfire_path_join(repo_cache->prefix, path); -} - -PAKFIRE_EXPORT char* pakfire_repocache_get_full_path(PakfireRepoCache repo_cache, const char* path) { - char* cache_path = pakfire_repocache_get_cache_path(repo_cache, path); - - PakfireCache cache = pakfire_repocache_cache(repo_cache); - char* full_path = pakfire_cache_get_full_path(cache, cache_path); - - pakfire_free(cache_path); - - return full_path; -} - -PAKFIRE_EXPORT int pakfire_repocache_has_file(PakfireRepoCache repo_cache, const char* filename) { - char* cache_filename = pakfire_repocache_get_cache_path(repo_cache, filename); - - PakfireCache cache = pakfire_repocache_cache(repo_cache); - int r = pakfire_cache_access(cache, cache_filename, R_OK); - - pakfire_free(cache_filename); - return r; -} - -PAKFIRE_EXPORT int pakfire_repocache_age(PakfireRepoCache repo_cache, const char* filename) { - char* cache_filename = pakfire_repocache_get_cache_path(repo_cache, filename); - - PakfireCache cache = pakfire_repocache_cache(repo_cache); - int age = pakfire_cache_age(cache, cache_filename); - pakfire_free(cache_filename); - - return age; -} - -PAKFIRE_EXPORT FILE* pakfire_repocache_open(PakfireRepoCache repo_cache, const char* filename, const char* flags) { - char* cache_filename = pakfire_repocache_get_cache_path(repo_cache, filename); - - PakfireCache cache = pakfire_repocache_cache(repo_cache); - FILE* fp = pakfire_cache_open(cache, cache_filename, flags); - pakfire_free(cache_filename); - - return fp; -} -- 2.39.5