PAKFIRE_EXPORT int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* ctx,
const char* path, const char* arch, FILE* conf, int flags) {
+ struct pakfire* p = NULL;
char tempdir[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-root-XXXXXX";
char private_dir[PATH_MAX];
int r = 1;
- // Reset pakfire pointer
- *pakfire = NULL;
-
// Default to the native architecture
if (!arch)
arch = pakfire_arch_native();
- struct pakfire* p = calloc(1, sizeof(*p));
+ // Allocate a new object
+ p = calloc(1, sizeof(*p));
if (!p)
return -errno;
// Reference the context
p->ctx = pakfire_ctx_ref(ctx);
+ // Initialize the reference counter
p->nrefs = 1;
+
+ // Store the flags
p->flags = flags;
// Store the nominal architecture
r = pakfire_string_set(p->arches.nominal, arch);
- if (r)
+ if (r < 0)
goto ERROR;
// Determine the effective architecture
// Setup user/group
r = pakfire_setup_user(p);
- if (r)
+ if (r < 0)
goto ERROR;
// Initialise configuration
}
// Set path
- pakfire_string_set(p->path, path);
+ r = pakfire_string_set(p->path, path);
+ if (r < 0)
+ goto ERROR;
// Read /etc/os-release
r = pakfire_read_os_release(p);
// Populate pool
r = pakfire_populate_pool(p);
- if (r)
+ if (r < 0)
goto ERROR;
// Create repositories
r = pakfire_repo_import(p, p->config);
- if (r)
+ if (r < 0)
goto ERROR;
- *pakfire = p;
+ // Return the pointer
+ *pakfire = pakfire_ref(p);
return 0;
ERROR:
- pakfire_free(p);
+ if (p)
+ pakfire_unref(p);
return r;
}
return pakfire;
pakfire_free(pakfire);
-
return NULL;
}