// HTTP Client
struct pakfire_httpclient* client;
+ // Build Service
+ struct pakfire_buildservice* service;
+
// URL
char url[PATH_MAX];
sd_event_source_unref(daemon->connect_timer);
if (daemon->stats_timer)
sd_event_source_unref(daemon->stats_timer);
+ if (daemon->service)
+ pakfire_buildservice_unref(daemon->service);
if (daemon->client)
pakfire_httpclient_unref(daemon->client);
if (daemon->cgroup)
if (r)
goto ERROR;
+ // Connect to the build service
+ r = pakfire_buildservice_create(&d->service, d->ctx, d->url);
+ if (r < 0)
+ goto ERROR;
+
// Create the cgroup
r = pakfire_cgroup_create(&d->cgroup, d->ctx, NULL, "pakfire-daemon", 0);
if (r < 0)
return sd_event_ref(daemon->loop);
}
+struct pakfire_buildservice* pakfire_daemon_buildservice(struct pakfire_daemon* daemon) {
+ return pakfire_buildservice_ref(daemon->service);
+}
+
struct pakfire_httpclient* pakfire_daemon_httpclient(struct pakfire_daemon* daemon) {
return pakfire_httpclient_ref(daemon->client);
}
struct pakfire_ctx* ctx;
int nrefs;
+ // Daemon
struct pakfire_daemon* daemon;
+ // Build Service
+ struct pakfire_buildservice* service;
+
// Event Loop
sd_event* loop;
PAKFIRE_JOB_STATE_EXITED,
PAKFIRE_JOB_STATE_KILLED,
} state;
+
+ // Uploads
+ char** uploads;
};
static int pakfire_parse_job(struct pakfire_job* job, json_object* data) {
if (job->log.stderr)
pakfire_log_stream_unref(job->log.stderr);
+ if (job->service)
+ pakfire_buildservice_unref(job->service);
+ if (job->uploads)
+ pakfire_strings_free(job->uploads);
if (job->config)
pakfire_config_unref(job->config);
if (job->loop)
return r;
}
+static int pakfire_job_result(struct pakfire_ctx* ctx, struct pakfire* pakfire,
+ struct pakfire_build* build, struct pakfire_archive* archive, void* data) {
+ struct pakfire_job* job = data;
+ struct pakfire_package* pkg = NULL;
+ char* uuid = NULL;
+ int r;
+
+ // Fetch package metadata
+ r = pakfire_archive_make_package(archive, NULL, &pkg);
+ if (r < 0)
+ goto ERROR;
+
+ // Fetch NEVRA
+ const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA);
+ if (!nevra) {
+ r = -EINVAL;
+ goto ERROR;
+ }
+
+ // Fetch filename
+ const char* filename = pakfire_package_get_filename(pkg);
+ if (!filename) {
+ r = -EINVAL;
+ goto ERROR;
+ }
+
+ // Fetch path
+ const char* path = pakfire_archive_get_path(archive);
+ if (!path) {
+ r = -EINVAL;
+ goto ERROR;
+ }
+
+ // Upload the file
+ r = pakfire_buildservice_upload(job->service, path, filename, &uuid);
+ if (r < 0) {
+ ERROR(job->ctx, "Could not upload %s: %s\n", nevra, strerror(-r));
+ goto ERROR;
+ }
+
+ // Store the ID of the upload
+ r = pakfire_strings_append(&job->uploads, uuid);
+ if (r < 0)
+ goto ERROR;
+
+ERROR:
+ if (pkg)
+ pakfire_package_unref(pkg);
+ if (uuid)
+ free(uuid);
+
+ return r;
+}
+
/*
This method is triggered by SIGCHLD whenever the job exits
*/
// XXX need to set target
// Run the build
- r = pakfire_build_exec(build, job->pkg, NULL, NULL);
+ r = pakfire_build_exec(build, job->pkg, pakfire_job_result, job);
ERROR:
if (build)
goto ERROR;
}
+ // Fetch a reference to the build service
+ j->service = pakfire_daemon_buildservice(daemon);
+
// Initialize the PID file descriptor
j->pidfd = -1;