]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Define and always create private dir
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 19 Jan 2021 20:27:19 +0000 (20:27 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 19 Jan 2021 20:27:19 +0000 (20:27 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
configure.ac
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/libpakfire.sym
src/libpakfire/pakfire.c

index bef8cbbcd6f9eedbf2f9746f16bfc38d7cee605f..e58b78ad582e191a87748be0ef2e42e0f6877490 100644 (file)
@@ -186,6 +186,9 @@ AC_ARG_WITH([systemdsystemunitdir],
 AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
 AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir"])
 
+AC_DEFINE_UNQUOTED([PAKFIRE_PRIVATE_DIR], ["/var/lib/${PACKAGE_NAME}"],
+       [The path where Pakfire stores its private data])
+
 AC_CONFIG_FILES([
        Makefile
        po/Makefile.in
index a975a73bab760c7e4cbe1d85d207d897d163eeae..a8d17931a7661461669bebac133cf25a84878d3a 100644 (file)
@@ -34,6 +34,7 @@ Pakfire pakfire_ref(Pakfire pakfire);
 Pakfire pakfire_unref(Pakfire pakfire);
 
 const char* pakfire_get_path(Pakfire pakfire);
+char* pakfire_make_path(Pakfire pakfire, const char* path);
 const char* pakfire_get_arch(Pakfire pakfire);
 
 const char** pakfire_get_installonly(Pakfire pakfire);
index 3331d3e504fc2c49af177e6daf5496dbb5cc675d..2398ad0789b775c010033151c81035367891a293 100644 (file)
@@ -34,6 +34,7 @@ global:
        pakfire_get_path;
        pakfire_get_pool;
        pakfire_get_repo;
+       pakfire_make_path;
        pakfire_ref;
        pakfire_search;
        pakfire_set_cache_path;
index d1583721852c9affde05eb05b9bdf175ab3b9ce4..6ce262f4eb195c424605d2841a9ee2b54b2643f5 100644 (file)
@@ -114,6 +114,8 @@ static void _pakfire_free(Pakfire pakfire) {
 }
 
 PAKFIRE_EXPORT int pakfire_create(Pakfire* pakfire, const char* path, const char* arch) {
+       int r;
+
        // Default to the native architecture
        if (!arch)
                arch = pakfire_arch_native();
@@ -155,8 +157,20 @@ PAKFIRE_EXPORT int pakfire_create(Pakfire* pakfire, const char* path, const char
        DEBUG(p, "  arch = %s\n", pakfire_get_arch(p));
        DEBUG(p, "  path = %s\n", pakfire_get_path(p));
 
+       // Make sure that our private directory exists
+       char* private_dir = pakfire_make_path(p, PAKFIRE_PRIVATE_DIR);
+       r = pakfire_mkdir(p, private_dir, 0);
+       if (r) {
+               ERROR(p, "Could not create private directory %s: %s\n",
+                       private_dir, strerror(errno));
+               free(private_dir);
+
+               _pakfire_free(p);
+               return r;
+       }
+
        // Initialise the database environment
-       int r = pakfire_db_env_init(p, &p->mdb_env);
+       r = pakfire_db_env_init(p, &p->mdb_env);
        if (r) {
                _pakfire_free(p);
 
@@ -201,6 +215,14 @@ PAKFIRE_EXPORT const char* pakfire_get_path(Pakfire pakfire) {
        return pakfire->path;
 }
 
+PAKFIRE_EXPORT char* pakfire_make_path(Pakfire pakfire, const char* path) {
+       // Make sure that path never starts with /
+       if (path && path[0] == '/')
+               path++;
+
+       return pakfire_path_join(pakfire->path, path);
+}
+
 PAKFIRE_EXPORT const char* pakfire_get_arch(Pakfire pakfire) {
        return pakfire->arch;
 }