]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Keep a fd open to the root
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Jan 2025 06:02:34 +0000 (06:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Jan 2025 06:02:34 +0000 (06:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c

index b6591c7365e88617de5898ea314aa550f63823d4..f9a22c45def4ac922f35e30a652da1b9a6b29772 100644 (file)
@@ -70,6 +70,8 @@ struct pakfire {
        int nrefs;
 
        char path[PATH_MAX];
+       int fd;
+
        char cache_path[PATH_MAX];
 
        struct pakfire_arches {
@@ -394,6 +396,10 @@ static void pakfire_free(struct pakfire* pakfire) {
                pakfire_repo_unref(repo);
        }
 
+       // Close the path
+       if (pakfire->fd >= 0)
+               close(pakfire->fd);
+
        // Umount the snapshot
        if (pakfire->snapshot) {
                r = pakfire_snapshot_umount(pakfire->snapshot);
@@ -947,6 +953,14 @@ PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx*
        if (r < 0)
                goto ERROR;
 
+       // Open the path
+       r = p->fd = open(p->path, O_DIRECTORY);
+       if (r < 0) {
+               ERROR(p->ctx, "Could not open %s: %m\n", p->path);
+               r = -errno;
+               goto ERROR;
+       }
+
        // Populate pool
        r = pakfire_populate_pool(p);
        if (r < 0)