return 0;
}
+static int pakfire_setup_path(struct pakfire* self, const char* path) {
+ int r;
+
+ // Template when running Pakfire in a temporary environment
+ char tmppath[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-root-XXXXXX";
+
+ // If we don't have a path, create something temporary...
+ if (!path) {
+ // Create a new temporary directory
+ path = pakfire_mkdtemp(tmppath);
+ if (!path)
+ return -errno;
+
+ // Destroy the temporary directory afterwards
+ self->internal_flags |= PAKFIRE_DESTROY_ON_FREE;
+
+ // Mount the snapshot
+ if (self->snapshot) {
+ r = pakfire_snapshot_mount(self->snapshot, path);
+ if (r < 0) {
+ ERROR(self->ctx, "Could not mount snapshot: %s\n", strerror(-r));
+ return r;
+ }
+
+ // Mount a tmpfs
+ } else {
+ r = mount("pakfire_root", path, "tmpfs", 0, NULL);
+ if (r) {
+ ERROR(self->ctx, "Could not mount tmpfs: %m\n");
+ return -errno;
+ }
+
+ // Umount path later
+ self->internal_flags |= PAKFIRE_UMOUNT_PATH;
+ }
+ }
+
+ // Store the path
+ r = pakfire_string_set(self->path, path);
+ if (r < 0)
+ return r;
+
+ // Open the path
+ r = open(self->path, O_DIRECTORY);
+ if (r < 0) {
+ ERROR(self->ctx, "Could not open %s: %m\n", self->path);
+ return -errno;
+ }
+
+ // Store the file descriptor
+ self->fd = r;
+
+ return 0;
+}
+
static int pakfire_lock_running_kernel(struct pakfire* pakfire) {
struct utsname utsname;
char buffer[NAME_MAX];
}
}
- // If we don't have a path, create something temporary...
- if (!path) {
- // Template when running Pakfire in a temporary environment
- char tmppath[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-root-XXXXXX";
-
- // Create a new temporary directory
- path = pakfire_mkdtemp(tmppath);
- if (!path) {
- r = -errno;
- goto ERROR;
- }
-
- // Destroy the temporary directory afterwards
- p->internal_flags |= PAKFIRE_DESTROY_ON_FREE;
-
- // Mount the snapshot
- if (p->snapshot) {
- r = pakfire_snapshot_mount(p->snapshot, path);
- if (r < 0) {
- ERROR(p->ctx, "Could not mount snapshot: %s\n", strerror(-r));
- goto ERROR;
- }
-
- // Mount a tmpfs
- } else {
- r = mount("pakfire_root", path, "tmpfs", 0, NULL);
- if (r) {
- ERROR(p->ctx, "Could not mount tmpfs: %m\n");
- r = -errno;
- goto ERROR;
- }
-
- // Umount path later
- p->internal_flags |= PAKFIRE_UMOUNT_PATH;
- }
- }
-
- // Store the path
- r = pakfire_string_set(p->path, path);
+ // Setup path
+ r = pakfire_setup_path(p, path);
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;
- }
-
// Setup the pool
r = pakfire_setup_pool(p);
if (r < 0)