From: Michael Tremer Date: Wed, 22 Sep 2021 09:48:53 +0000 (+0000) Subject: build: Cleanup local repository X-Git-Tag: 0.9.28~943 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=397371db592de0392baf397336dfce2513ed72fb;p=pakfire.git build: Cleanup local repository Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index d2d3eb461..e5dfd6825 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -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; +} diff --git a/src/libpakfire/include/pakfire/build.h b/src/libpakfire/include/pakfire/build.h index cc936f7d9..908511cf2 100644 --- a/src/libpakfire/include/pakfire/build.h +++ b/src/libpakfire/include/pakfire/build.h @@ -22,6 +22,7 @@ #define PAKFIRE_BUILD_H #include +#include 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 */ diff --git a/src/libpakfire/include/pakfire/repo.h b/src/libpakfire/include/pakfire/repo.h index 0972d200d..37c79ab62 100644 --- a/src/libpakfire/include/pakfire/repo.h +++ b/src/libpakfire/include/pakfire/repo.h @@ -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 diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index ba51c0064..859ae7896 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -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) { diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index aaebdc1f8..e521fc92e 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -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;