// Called when an upload was successful
static int upload_callback(pakfire_client* client,
- pakfire_client_upload_status status, const char* path, const char* uuid, void* data) {
+ const pakfire_xfer_response* response, const char* path, const char* uuid, void* data) {
struct cli_local_args* local_args = data;
int r;
+ // Handle errors
+ r = cli_api_error(response, "Failed to upload the archive");
+ if (r < 0)
+ return 0;
+
// Create the build
r = pakfire_client_build(client, uuid, local_args->repo,
local_args->arches, local_args->flags, build_callback, NULL);
if (r < 0) {
- fprintf(stderr, "Failed to create build from %s: %s\n", path, strerror(-r));
+ fprintf(stderr, "Failed to create build: %s\n", strerror(-r));
// Store the status
local_args->status = r;
#include <pakfire/client.h>
+#include "api.h"
#include "command.h"
#include "pakfire.h"
#include "upload_create.h"
return 0;
}
-static int upload_callback(pakfire_client* client,
- pakfire_client_upload_status status, const char* path, const char* uuid, void* data) {
- switch (status) {
- case PAKFIRE_CLIENT_UPLOAD_SUCCESSFUL:
- printf("Successfully uploaded %s as %s\n", path, uuid);
- return 0;
+static int upload_callback(pakfire_client* client, const pakfire_xfer_response* response,
+ const char* path, const char* uuid, void* data) {
+ int r;
- default:
- break;
- }
+ // Handle errors
+ r = cli_api_error(response, "Failed to upload the archive");
+ if (r < 0)
+ return 0;
+
+ printf("Successfully uploaded %s as %s\n", path, uuid);
return 0;
}
goto ERROR;
}
- // Reference the client
+ // Store a reference to the client
self->client = client;
// Store the path
return r;
}
-static int pakfire_upload_payload_callback(pakfire_xfer* xfer,
- const pakfire_xfer_response* response, void* data) {
- pakfire_client_upload_status s = PAKFIRE_CLIENT_UPLOAD_SUCCESSFUL;
+static int pakfire_upload_payload_callback(
+ pakfire_xfer* xfer, const pakfire_xfer_response* response, void* data) {
pakfire_client_upload* upload = data;
int r = 0;
- // Determine the status
- switch (response->error) {
- case PAKFIRE_XFER_OK:
- break;
-
- default:
- s = PAKFIRE_CLIENT_UPLOAD_ERROR;
- break;
- }
-
// Call the callback (if any)
if (upload->callback)
- r = upload->callback(upload->client, s, upload->path, upload->uuid, upload->data);
+ r = upload->callback(upload->client, response, upload->path, upload->uuid, upload->data);
// Free the upload
pakfire_client_upload_free(upload);
// Uploads
-typedef enum {
- PAKFIRE_CLIENT_UPLOAD_SUCCESSFUL,
- PAKFIRE_CLIENT_UPLOAD_ERROR,
-} pakfire_client_upload_status;
-
typedef int (*pakfire_client_upload_callback)
- (pakfire_client* client, pakfire_client_upload_status status,
- const char* path, const char* uuid, void* data);
+ (pakfire_client* client, const pakfire_xfer_response* response,
+ const char* path, const char* uuid, void* data);
int pakfire_client_upload_create(pakfire_client* client,
const char* path, const char* filename, pakfire_client_upload_callback callback, void* data);
}
static int pakfire_job_package_uploaded(pakfire_client* client,
- pakfire_client_upload_status status, const char* path, const char* uuid, void* data) {
+ const pakfire_xfer_response* response, const char* path, const char* uuid, void* data) {
pakfire_job* self = data;
+ char* error = NULL;
int r;
// Now we have one less uploads running
self->uploads.running--;
- switch (status) {
- case PAKFIRE_CLIENT_UPLOAD_SUCCESSFUL:
- // Store the ID of the upload
- r = pakfire_strings_append(&self->uploads.packages, uuid);
- if (r < 0)
- return r;
- break;
+ // Handle any errors
+ if (response->error) {
+ r = pakfire_xfer_response_get_error(response, &error);
+ if (r < 0)
+ goto ERROR;
- default:
- ERROR(self->ctx, "Failed to upload %s: %s\n", path, strerror(status));
+ ERROR(self->ctx, "Failed to upload: %s\n", error);
- // XXX What do we do here?
+ // XXX What do we do here?
- return status;
+ r = -ECANCELED;
+ goto ERROR;
}
+ // Store the ID of the upload
+ r = pakfire_strings_append(&self->uploads.packages, uuid);
+ if (r < 0)
+ goto ERROR;
+
// Don't do anything if there are any other uploads still running
if (self->uploads.running)
- return 0;
+ goto ERROR;
// Finish the job
- return pakfire_job_finished(self);
+ r = pakfire_job_finished(self);
+
+ERROR:
+ if (error)
+ free(error);
+
+ return r;
}
static int pakfire_job_upload_packages(pakfire_job* self) {
Called when the log file has been uploaded...
*/
static int pakfire_job_logfile_uploaded(pakfire_client* client,
- pakfire_client_upload_status status, const char* path, const char* uuid, void* data) {
+ const pakfire_xfer_response* response, const char* path, const char* uuid, void* data) {
pakfire_job* self = data;
+ char* error = NULL;
+ int r;
- // Check the status
- switch (status) {
- case PAKFIRE_CLIENT_UPLOAD_SUCCESSFUL:
- // Free any previous upload IDs
- if (self->uploads.logfile)
- free(self->uploads.logfile);
-
- // Store the UUID of the upload
- self->uploads.logfile = strdup(uuid);
- if (self->uploads.logfile)
- ERROR(self->ctx, "Failed to store the log file UUID: %m\n");
- break;
+ // Handle any errors
+ if (response->error) {
+ r = pakfire_xfer_response_get_error(response, &error);
+ if (r < 0)
+ goto ERROR;
- // Log an error if we could not upload the log file
- default:
- ERROR(self->ctx, "Failed to upload the log file: %s\n", strerror(status));
- break;
+ ERROR(self->ctx, "Failed to upload the log file: %s\n", error);
+ r = -ECANCELED;
+ goto ERROR;
+ }
+
+ // Free any previous upload IDs
+ if (self->uploads.logfile)
+ free(self->uploads.logfile);
+
+ // Store the UUID of the upload
+ self->uploads.logfile = strdup(uuid);
+ if (!self->uploads.logfile) {
+ ERROR(self->ctx, "Failed to store the log file UUID: %m\n");
+ r = -errno;
+ goto ERROR;
}
// Continue with uploading the packages
- return pakfire_job_upload_packages(self);
+ r = pakfire_job_upload_packages(self);
+
+ERROR:
+ if (error)
+ free(error);
+
+ return r;
}
static int pakfire_job_result(pakfire_ctx* ctx, pakfire_root* root,