]> git.ipfire.org Git - pakfire.git/commitdiff
Delete the repo cache to clean a repository
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 7 Apr 2017 16:00:13 +0000 (18:00 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 7 Apr 2017 16:00:13 +0000 (18:00 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/repo.c
src/libpakfire/include/pakfire/repo.h
src/libpakfire/include/pakfire/repocache.h
src/libpakfire/libpakfire.sym
src/libpakfire/repo.c
src/libpakfire/repocache.c
src/pakfire/repository/base.py
src/pakfire/repository/remote.py

index c21a43635255dd4ce2225f1a3438d6c858ae2f96..ee2e0c335fd1bd3f1d2f893e25339e770f6b940e 100644 (file)
@@ -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,
index 7cdcee1ce427ba81491a8a09d35dc191b3a2d735..44ac244d92784d5dbc1107024cf72f2a3cf8ea25 100644 (file)
@@ -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 {
index 5d426a30658b17e9e92d8d68bca5b04679f4e399..19824165e6e76b0edb0f6eaedc87e49a021874ac 100644 (file)
@@ -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 {
index f2835866052098706417e9891d27c8225a0e0de4..047a7a0bb31034b46c5da844a02904bcce34c7c4 100644 (file)
@@ -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;
index 5f17f2ad444032cf4f05b09df7334f4dcf52789e..ff7693bad0ede0d1d4c29a2784ee3f6f70c0b546 100644 (file)
@@ -18,6 +18,7 @@
 #                                                                             #
 #############################################################################*/
 
+#include <assert.h>
 #include <string.h>
 
 #include <solv/repo.h>
@@ -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;
+}
index 257606f0262e99a920869c97f5b67d31a5c7db8f..95865b6cfad32c790a156fbd5c9b7c5bc36001d8 100644 (file)
@@ -18,6 +18,8 @@
 #                                                                             #
 #############################################################################*/
 
+#define _XOPEN_SOURCE 500
+#include <ftw.h>
 #include <stdio.h>
 #include <sys/stat.h>
 
@@ -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);
+}
index 0682d5f9014a5c152bf359242614d30a2699e776..9dae65db30fd0252d3602006010c6d0b8b52f080 100644 (file)
@@ -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.
index 1d0c679284126ddbea424ca6d2bdead83200a1fd..5a101ad2d72cd363dc1d6e5fc33ca48d807ea689 100644 (file)
@@ -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()