]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Move cache into Pakfire object
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Jan 2018 00:23:05 +0000 (01:23 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 19 Jan 2018 00:23:05 +0000 (01:23 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/constants.h
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/pakfire.c

index 8f587c03d2f4e929feb017113223a818cb185313..9404b3a3aaff9cb20dbb861526d237d986f3b087 100644 (file)
@@ -25,4 +25,6 @@
 
 #define PAKFIRE_REPO_SYSTEM_NAME "@system"
 
+#define CACHE_PATH "/var/cache/pakfire"
+
 #endif /* PAKFIRE_CONSTANTS_H */
index e7aea8cbf5f7d91c2af44cdbc2ab226f5dd7e23d..18f899f277f36b4ad140239cf8f0b23ea5609d26 100644 (file)
@@ -50,6 +50,11 @@ void pakfire_set_installed_repo(Pakfire pakfire, PakfireRepo repo);
 PakfirePackageList pakfire_whatprovides(Pakfire pakfire, const char* provides, int flags);
 PakfirePackageList pakfire_search(Pakfire pakfire, const char* what, int flags);
 
+// Cache
+
+char* pakfire_get_cache_path(Pakfire pakfire, const char* path);
+void pakfire_set_cache_path(Pakfire pakfire, const char* path);
+
 #ifdef PAKFIRE_PRIVATE
 
 #include <solv/pool.h>
index d28abda7a048b99bce41995ccb6457ec9040146f..a685c4455f1c32ef9288108b8971b3fdead1801e 100644 (file)
@@ -25,6 +25,7 @@
 #include <solv/poolarch.h>
 #include <solv/queue.h>
 
+#include <pakfire/constants.h>
 #include <pakfire/logging.h>
 #include <pakfire/package.h>
 #include <pakfire/packagelist.h>
@@ -38,6 +39,7 @@
 
 struct _Pakfire {
        char* path;
+       char* cache_path;
        char* arch;
 
        // Pool stuff
@@ -83,6 +85,9 @@ PAKFIRE_EXPORT Pakfire pakfire_create(const char* path, const char* arch) {
 
                // Set architecture of the pool
                pool_setarch(pakfire->pool, pakfire->arch);
+
+               // Initialise cache
+               pakfire_set_cache_path(pakfire, CACHE_PATH);
        }
 
        return pakfire;
@@ -120,6 +125,7 @@ PAKFIRE_EXPORT Pakfire pakfire_unref(Pakfire pakfire) {
        queue_free(&pakfire->installonly);
 
        pakfire_free(pakfire->path);
+       pakfire_free(pakfire->cache_path);
        pakfire_free(pakfire->arch);
 
        pakfire_free(pakfire);
@@ -308,3 +314,19 @@ PAKFIRE_EXPORT PakfirePackageList pakfire_whatprovides(Pakfire pakfire, const ch
 PAKFIRE_EXPORT PakfirePackageList pakfire_search(Pakfire pakfire, const char* what, int flags) {
        return pakfire_pool_dataiterator(pakfire, what, 0, PAKFIRE_SUBSTRING);
 }
+
+// Cache
+
+PAKFIRE_EXPORT char* pakfire_get_cache_path(Pakfire pakfire, const char* path) {
+       return pakfire_path_join(pakfire->cache_path, path);
+}
+
+PAKFIRE_EXPORT void pakfire_set_cache_path(Pakfire pakfire, const char* path) {
+       // Release old path
+       if (pakfire->cache_path)
+               pakfire_free(pakfire->cache_path);
+
+       pakfire->cache_path = pakfire_strdup(path);
+
+       DEBUG("Set cache path to %s\n", pakfire->cache_path);
+}