From: Michael Tremer Date: Fri, 7 Apr 2017 16:00:13 +0000 (+0200) Subject: Delete the repo cache to clean a repository X-Git-Tag: 0.9.28~1285^2~1357 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b4ac59c66d3b6401d2bc8f00b0849c134bcb8879;p=pakfire.git Delete the repo cache to clean a repository Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/repo.c b/src/_pakfire/repo.c index c21a43635..ee2e0c335 100644 --- a/src/_pakfire/repo.c +++ b/src/_pakfire/repo.c @@ -291,6 +291,17 @@ static PyObject* Repo_cache_path(RepoObject* self, PyObject* args) { return obj; } +static PyObject* Repo_clean(RepoObject* self, PyObject* args) { + int r = pakfire_repo_clean(self->repo); + + if (r) { + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + + Py_RETURN_NONE; +} + static struct PyMethodDef Repo_methods[] = { { "cache_age", @@ -316,6 +327,12 @@ static struct PyMethodDef Repo_methods[] = { METH_VARARGS, NULL }, + { + "clean", + (PyCFunction)Repo_clean, + METH_VARARGS, + NULL, + }, { "read_solv", (PyCFunction)Repo_read_solv, diff --git a/src/libpakfire/include/pakfire/repo.h b/src/libpakfire/include/pakfire/repo.h index 7cdcee1ce..44ac244d9 100644 --- a/src/libpakfire/include/pakfire/repo.h +++ b/src/libpakfire/include/pakfire/repo.h @@ -56,6 +56,8 @@ int pakfire_repo_write_solv_fp(PakfireRepo repo, FILE *f, int flags); PakfireRepoCache pakfire_repo_get_cache(PakfireRepo repo); +int pakfire_repo_clean(PakfireRepo repo); + #ifdef PAKFIRE_PRIVATE struct _PakfireRepo { diff --git a/src/libpakfire/include/pakfire/repocache.h b/src/libpakfire/include/pakfire/repocache.h index 5d426a306..19824165e 100644 --- a/src/libpakfire/include/pakfire/repocache.h +++ b/src/libpakfire/include/pakfire/repocache.h @@ -36,6 +36,8 @@ 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 { diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index f28358660..047a7a0bb 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -162,6 +162,7 @@ global: # repo pakfire_repo_cmp; pakfire_repo_count; + pakfire_repo_clean; pakfire_repo_create; pakfire_repo_free; pakfire_repo_get_cache; @@ -183,6 +184,7 @@ global: # repocache pakfire_repocache_age; pakfire_repocache_create; + pakfire_repocache_destroy; pakfire_repocache_free; pakfire_repocache_get_cache_path; pakfire_repocache_get_full_path; diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 5f17f2ad4..ff7693bad 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -18,6 +18,7 @@ # # #############################################################################*/ +#include #include #include @@ -231,5 +232,16 @@ PakfirePackage pakfire_repo_add_package(PakfireRepo repo) { } PakfireRepoCache pakfire_repo_get_cache(PakfireRepo repo) { + assert(repo); + return repo->cache; } + +int pakfire_repo_clean(PakfireRepo repo) { + PakfireRepoCache cache = pakfire_repo_get_cache(repo); + + if (cache) + return pakfire_repocache_destroy(cache); + + return 0; +} diff --git a/src/libpakfire/repocache.c b/src/libpakfire/repocache.c index 257606f02..95865b6cf 100644 --- a/src/libpakfire/repocache.c +++ b/src/libpakfire/repocache.c @@ -18,6 +18,8 @@ # # #############################################################################*/ +#define _XOPEN_SOURCE 500 +#include #include #include @@ -96,3 +98,12 @@ FILE* pakfire_repocache_open(PakfireRepoCache repo_cache, const char* filename, return fp; } + +static int _unlink(const char* path, const struct stat* stat, int typeflag, struct FTW* ftwbuf) { + return remove(path); +} + +int pakfire_repocache_destroy(PakfireRepoCache repo_cache) { + // Completely delete the tree of files + return nftw(repo_cache->prefix, _unlink, 64, FTW_DEPTH|FTW_PHYS); +} diff --git a/src/pakfire/repository/base.py b/src/pakfire/repository/base.py index 0682d5f90..9dae65db3 100644 --- a/src/pakfire/repository/base.py +++ b/src/pakfire/repository/base.py @@ -65,15 +65,6 @@ class RepositoryFactory(_pakfire.Repo): """ self.opened = False - def clean(self): - """ - Cleanup all temporary files of this repository. - """ - log.info("Cleaning up repository '%s'..." % self.name) - - # Clear all packages in the index. - self.index.clear() - def dump(self, long=False, filelist=False): dumps = [] # Dump all package information of the packages in this repository. diff --git a/src/pakfire/repository/remote.py b/src/pakfire/repository/remote.py index 1d0c67928..5a101ad2d 100644 --- a/src/pakfire/repository/remote.py +++ b/src/pakfire/repository/remote.py @@ -99,22 +99,6 @@ class RepositoryRemote(base.RepositoryFactory): return priority - def cache_path(self, *paths): - return os.path.join( - "repodata", - self.distro.sname, - self.distro.release, - self.name, - self.distro.arch, - *paths - ) - - def clean(self): - base.RepositoryFactory.clean(self) - - # Remove all files in the files cache. - self.cache.destroy() - def open(self): # First update the repository metadata. self.update_metadata()