]> git.ipfire.org Git - pakfire.git/commitdiff
build: Cleanup local repository
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Sep 2021 09:48:53 +0000 (09:48 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Sep 2021 09:48:53 +0000 (09:48 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c
src/libpakfire/include/pakfire/build.h
src/libpakfire/include/pakfire/repo.h
src/libpakfire/pakfire.c
src/libpakfire/repo.c

index d2d3eb461143f77f2ac948ddb9afba04a234bb76..e5dfd6825af2b136d0254ec23e456c8c6292f447 100644 (file)
@@ -808,3 +808,26 @@ PAKFIRE_EXPORT int pakfire_shell(struct pakfire* pakfire) {
 
        return pakfire_execute_shell(pakfire);
 }
+
+int pakfire_build_clean(struct pakfire* pakfire, int flags) {
+       struct pakfire_repo* local = NULL;
+       int r = 0;
+
+       // Fetch local repository
+       local = pakfire_get_repo(pakfire, "@local");
+       if (!local) {
+               ERROR(pakfire, "Could not find local repository: %m\n");
+               goto ERROR;
+       }
+
+       // Destroy everything in it
+       r = pakfire_repo_clean(local, PAKFIRE_REPO_CLEAN_FLAGS_DESTROY);
+       if (r)
+               goto ERROR;
+
+ERROR:
+       if (local)
+               pakfire_repo_unref(local);
+
+       return r;
+}
index cc936f7d98cad231e988e6370cc50d3cbf74f5ec..908511cf2e35cd749271c3fff5b3a6620e7f515a 100644 (file)
@@ -22,6 +22,7 @@
 #define PAKFIRE_BUILD_H
 
 #include <pakfire/execute.h>
+#include <pakfire/pakfire.h>
 
 enum pakfire_build_flags {
        PAKFIRE_BUILD_INTERACTIVE = (1 << 0),
@@ -30,5 +31,6 @@ enum pakfire_build_flags {
 int pakfire_build(struct pakfire* pakfire, const char* path, const char* target,
        const char* id, int flags, pakfire_execute_logging_callback logging_callback, void* data);
 int pakfire_shell(struct pakfire* pakfire);
+int pakfire_build_clean(struct pakfire* pakfire, int flags);
 
 #endif /* PAKFIRE_BUILD_H */
index 0972d200d986c1ac641251844b0282cce3a83319..37c79ab621438d0d679f94f7ec758c799d689cbc 100644 (file)
@@ -72,6 +72,11 @@ int pakfire_repo_write_solv(struct pakfire_repo* repo, FILE *f, int flags);
 
 // Cache
 
+enum pakfire_repo_clean_flags {
+       PAKFIRE_REPO_CLEAN_FLAGS_NONE     = 0,
+       PAKFIRE_REPO_CLEAN_FLAGS_DESTROY  = (1 << 0),
+};
+
 int pakfire_repo_clean(struct pakfire_repo* repo, int flags);
 
 // Scan
index ba51c00649fefca41b3d750458a9f3235656c111..859ae789677888025f99fd4a2ac44d97e811da04 100644 (file)
@@ -1174,7 +1174,22 @@ static int pakfire_foreach_repo(struct pakfire* pakfire,
 }
 
 PAKFIRE_EXPORT int pakfire_clean(struct pakfire* pakfire, int flags) {
-       return pakfire_foreach_repo(pakfire, pakfire_repo_clean, flags);
+       int r;
+
+       // Clean all repositories
+       r = pakfire_foreach_repo(pakfire, pakfire_repo_clean, flags);
+       if (r)
+               return r;
+
+       // Clean build environments
+       // Nothing to do if we are not in build mode
+       if (pakfire_has_flag(pakfire, PAKFIRE_FLAGS_BUILD)) {
+               r = pakfire_build_clean(pakfire, flags);
+               if (r)
+                       return r;
+       }
+
+       return 0;
 }
 
 PAKFIRE_EXPORT int pakfire_refresh(struct pakfire* pakfire, int flags) {
index aaebdc1f868ce6cb95e5a4b80cd967d71f0a9b57..e521fc92e0c1ae91bc580c3d07ac34699dae3fae 100644 (file)
@@ -863,6 +863,7 @@ PAKFIRE_EXPORT int pakfire_repo_write_solv(struct pakfire_repo* repo, FILE *f, i
 
 PAKFIRE_EXPORT int pakfire_repo_clean(struct pakfire_repo* repo, int flags) {
        char cache_path[PATH_MAX];
+       int r;
 
        // Drop all meta-data from memory
        repo_empty(repo->repo, 0);
@@ -872,11 +873,24 @@ PAKFIRE_EXPORT int pakfire_repo_clean(struct pakfire_repo* repo, int flags) {
                return 0;
 
        // Do not destroy files in local repositories
-       if (pakfire_repo_is_local(repo))
+       if (pakfire_repo_is_local(repo)) {
+               if (flags & PAKFIRE_REPO_CLEAN_FLAGS_DESTROY) {
+                       // Find path to repository
+                       const char* path = pakfire_repo_get_path(repo);
+                       if (!path)
+                               return 1;
+
+                       // Destroy it
+                       r = pakfire_rmtree(path, 0);
+                       if (r)
+                               return r;
+               }
+
                return 0;
+       }
 
        // Destroy all files in the cache directory
-       int r = pakfire_make_cache_path(repo->pakfire, cache_path,
+       r = pakfire_make_cache_path(repo->pakfire, cache_path,
                "repodata/%s", pakfire_repo_get_name(repo));
        if (r < 0)
                return r;