]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Add a function to clone a Pakfire instance
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 18 Oct 2024 12:53:12 +0000 (12:53 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 18 Oct 2024 12:53:12 +0000 (12:53 +0000)
This will create a new independant instance based on the previous one.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/pakfire.c

index ab64a0cf0d29f920e2058d442bb1d035e033cae4..987f48576c0940045f06d31262d4d4acb490539d 100644 (file)
@@ -95,6 +95,8 @@ int pakfire_check(struct pakfire* pakfire, struct pakfire_filelist* errors);
 #include <pakfire/config.h>
 #include <pakfire/pwd.h>
 
+int pakfire_clone(struct pakfire** clone, struct pakfire* pakfire, const char* path);
+
 struct pakfire_ctx* pakfire_ctx(struct pakfire* pakfire);
 
 const char* pakfire_get_effective_arch(struct pakfire* pakfire);
index 664cce0a4b1e5a913ad61b1c46c220a1229a6a0f..da88562f9658d24d1005817e46b35c037245225a 100644 (file)
@@ -965,6 +965,35 @@ ERROR:
        return r;
 }
 
+int pakfire_clone(struct pakfire** clone, struct pakfire* pakfire, const char* path) {
+       struct pakfire* p = NULL;
+       FILE* f = NULL;
+       int r;
+
+       // Dump the configuration
+       f = pakfire_config_fdump(pakfire->config);
+       if (!f) {
+               r = -errno;
+               goto ERROR;
+       }
+
+       // Create a new Pakfire instance
+       r = pakfire_create(&p, pakfire->ctx, path, pakfire->arches.nominal, f, 0);
+       if (r < 0)
+               goto ERROR;
+
+       // Return the pointer
+       *clone = pakfire_ref(p);
+
+ERROR:
+       if (p)
+               pakfire_unref(p);
+       if (f)
+               fclose(f);
+
+       return r;
+}
+
 PAKFIRE_EXPORT struct pakfire* pakfire_ref(struct pakfire* pakfire) {
        ++pakfire->nrefs;