#include <pakfire/cgroup.h>
#include <pakfire/dist.h>
#include <pakfire/file.h>
+#include <pakfire/i18n.h>
#include <pakfire/jail.h>
#include <pakfire/logging.h>
#include <pakfire/mount.h>
// Jail
struct pakfire_jail* jail;
+
+ // Local build repo
+ struct pakfire_repo* repo;
};
static const char* stages[] = {
FILE* f = NULL;
int r = 1;
- // Fetch the local repository
- struct pakfire_repo* repo = pakfire_get_repo(build->pakfire, PAKFIRE_REPO_LOCAL);
- if (!repo) {
- DEBUG(build->pakfire, "Could not find repository '%s': %m\n", PAKFIRE_REPO_LOCAL);
- return 0;
- }
-
// Fetch repository configuration
- char* config = pakfire_repo_get_config(repo);
+ char* config = pakfire_repo_get_config(build->repo);
if (!config) {
ERROR(build->pakfire, "Could not generate repository configuration: %m\n");
goto ERROR;
}
- const char* path = pakfire_repo_get_path(repo);
+ const char* path = pakfire_repo_get_path(build->repo);
// Make sure the source directory exists
r = pakfire_mkdir(path, 0700);
fclose(f);
if (config)
free(config);
- pakfire_repo_unref(repo);
return r;
}
}
static void pakfire_build_free(struct pakfire_build* build) {
+ if (build->repo)
+ pakfire_repo_unref(build->repo);
+
if (build->jail)
pakfire_jail_unref(build->jail);
*/
static int pakfire_build_set_default_target(struct pakfire_build* build) {
// Look for the "local" repository
- struct pakfire_repo* repo = pakfire_get_repo(build->pakfire, PAKFIRE_REPO_LOCAL);
- if (repo) {
- const char* target = pakfire_repo_get_path(repo);
+ if (build->repo) {
+ const char* target = pakfire_repo_get_path(build->repo);
if (target)
pakfire_string_set(build->target, target);
-
- pakfire_repo_unref(repo);
}
// Default to the current working directory
return 0;
}
+static int pakfire_build_setup_repos(struct pakfire_build* build) {
+ int r;
+
+ // Create a new repository
+ r = pakfire_repo_create(&build->repo, build->pakfire, PAKFIRE_REPO_LOCAL);
+ if (r) {
+ ERROR(build->pakfire, "Could not create repository %s: %m\n", PAKFIRE_REPO_LOCAL);
+ return 1;
+ }
+
+ // Set description
+ pakfire_repo_set_description(build->repo, _("Locally Built Packages"));
+
+ // Set path
+ pakfire_repo_set_baseurl(build->repo, PAKFIRE_REPO_LOCAL_PATH);
+
+ // Set priority
+ pakfire_repo_set_priority(build->repo, PAKFIRE_REPO_LOCAL_PRIORITY);
+
+ return 0;
+}
+
PAKFIRE_EXPORT int pakfire_build_create(struct pakfire_build** build,
struct pakfire* pakfire, const char* id, int flags) {
int r;
if (r)
goto ERROR;
+ // Setup repos
+ r = pakfire_build_setup_repos(b);
+ if (r)
+ goto ERROR;
+
// Set target
r = pakfire_build_set_default_target(b);
if (r)
char path[PATH_MAX];
int r;
+ // Refresh the local repository
+ if (build->repo) {
+ r = pakfire_repo_refresh(repo, 0);
+ if (r) {
+ ERROR(build->pakfire, "Could not refresh the local repository: %m\n");
+ return 1;
+ }
+ }
+
// Check if the user wants a snapshot extracted
if (pakfire_build_has_flag(build, PAKFIRE_BUILD_DISABLE_SNAPSHOT)) {
DEBUG(build->pakfire, "Snapshot extraction has been disabled for this build\n");
pakfire_repo_unref(repo);
}
- // Add local repository (in build mode)
- if (pakfire_has_flag(pakfire, PAKFIRE_FLAGS_BUILD)) {
- // Does this repository exist already?
- repo = pakfire_get_repo(pakfire, PAKFIRE_REPO_LOCAL);
-
- // Create it if it doesn't exist, yet
- if (!repo) {
- r = pakfire_repo_create(&repo, pakfire, PAKFIRE_REPO_LOCAL);
- if (r) {
- ERROR(pakfire, "Could not create repository %s: %m\n", PAKFIRE_REPO_LOCAL);
- goto ERROR;
- }
-
- // Set description
- pakfire_repo_set_description(repo, _("Locally built packages"));
-
- // Set path
- pakfire_repo_set_baseurl(repo, PAKFIRE_REPO_LOCAL_PATH);
-
- // Set priority
- pakfire_repo_set_priority(repo, PAKFIRE_REPO_LOCAL_PRIORITY);
-
- pakfire_repo_unref(repo);
- }
- }
-
// Refresh repositories
r = pakfire_refresh(pakfire, 0);
if (r)