]> git.ipfire.org Git - pakfire.git/commitdiff
repo: Cleanup old metadata before writing new stuff
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 2 Feb 2025 15:06:56 +0000 (15:06 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 2 Feb 2025 15:06:56 +0000 (15:06 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/repo.c

index 29a24dcec285db52e34d57cb14c78d5a7165b77b..c65cc3bcb99edb51849c6a3873b6967ed09c03c3 100644 (file)
@@ -1967,6 +1967,23 @@ int pakfire_repo_refresh(struct pakfire_repo* repo, int force) {
        return 0;
 }
 
+static int pakfire_repo_cleanup_metadata(struct pakfire_repo* self) {
+       char path[PATH_MAX];
+       int r;
+
+       // Make sure we are running only on local repositories
+       if (!pakfire_repo_is_local(self))
+               return -ENOTSUP;
+
+       // Make the path
+       r = pakfire_repo_path(self, path, "%s", "repodata");
+       if (r < 0)
+               return r;
+
+       // Remove it all
+       return pakfire_rmtree(path, 0);
+}
+
 static int pakfire_repo_metadata_add_file(struct pakfire_repo* self,
                struct json_object* repomd, const char* type, const char* path) {
        struct pakfire_digests digests = {};
@@ -2174,6 +2191,11 @@ int pakfire_repo_write_metadata(struct pakfire_repo* self, struct pakfire_key* k
        if (!pakfire_repo_is_local(self))
                return -ENOTSUP;
 
+       // Cleanup any previous metadata
+       r = pakfire_repo_cleanup_metadata(self);
+       if (r < 0)
+               goto ERROR;
+
        // Make path to repomd.json
        r = pakfire_repo_path(self, repomd_path, "%s", "repodata/repomd.json");
        if (r < 0)