src/cli/lib/upload.h \
src/cli/lib/upload_create.c \
src/cli/lib/upload_create.h \
+ src/cli/lib/upload_delete.c \
+ src/cli/lib/upload_delete.h \
src/cli/lib/upload_list.c \
src/cli/lib/upload_list.h \
src/cli/lib/version.c \
#include "command.h"
#include "upload.h"
#include "upload_create.h"
+#include "upload_delete.h"
#include "upload_list.h"
static const char* args_doc =
"create PATH\n"
- "list";
+ "list\n"
+ "delete UUID...";
int cli_upload(void* data, int argc, char* argv[]) {
static const struct command commands[] = {
{ "create", cli_upload_create, 1, -1, 0 },
+ { "delete", cli_upload_delete, 1, -1, 0 },
{ "list", cli_upload_list, 0, 0, 0 },
{ NULL },
};
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2023 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#include <argp.h>
+
+#include <pakfire/buildservice.h>
+#include <pakfire/ctx.h>
+#include <pakfire/util.h>
+
+#include "command.h"
+#include "upload_delete.h"
+
+static const char* args_doc = "FILES...";
+
+static const char* doc = "Deletes an uploaded file";
+
+#define MAX_UPLOADS 32
+
+struct config {
+ const char* uploads[MAX_UPLOADS];
+ unsigned int num_uploads;
+};
+
+static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
+ struct config* config = data;
+
+ switch (key) {
+ case ARGP_KEY_ARG:
+ if (config->num_uploads >= MAX_UPLOADS)
+ return -ENOBUFS;
+
+ // Validate the UUID
+ if (!pakfire_uuid_is_valid(arg))
+ argp_error(state, "Invalid UUID");
+
+ config->uploads[config->num_uploads++] = arg;
+ break;
+
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+
+ return 0;
+}
+
+int cli_upload_delete(void* data, int argc, char* argv[]) {
+ struct pakfire_buildservice* service = NULL;
+ struct config config = {};
+ int r;
+
+ struct pakfire_ctx* ctx = data;
+
+ // Parse the command line
+ r = cli_parse(NULL, NULL, args_doc, doc, parse, argc, argv, &config);
+ if (r)
+ goto ERROR;
+
+ // Connect to the build service
+ r = pakfire_buildservice_create(&service, ctx);
+ if (r)
+ goto ERROR;
+
+ // Delete uploads
+ for (unsigned int i = 0; i < config.num_uploads; i++) {
+ r = pakfire_buildservice_delete_upload(service, config.uploads[i]);
+ if (r)
+ goto ERROR;
+ }
+
+ERROR:
+ if (service)
+ pakfire_buildservice_unref(service);
+
+ return r;
+}
--- /dev/null
+/*#############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2023 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#ifndef PAKFIRE_CLI_UPLOAD_DELETE_H
+#define PAKFIRE_CLI_UPLOAD_DELETE_H
+
+int cli_upload_delete(void* data, int argc, char* argv[]);
+
+#endif /* PAKFIRE_CLI_UPLOAD_DELETE_H */
return r;
}
+
+PAKFIRE_EXPORT int pakfire_buildservice_delete_upload(
+ struct pakfire_buildservice* service, const char* uuid) {
+ struct pakfire_transfer* transfer = NULL;
+ struct json_object* response = NULL;
+ char* buffer = NULL;
+ size_t length = 0;
+ char url[PATH_MAX];
+ int r;
+
+ // Compose the URL
+ r = pakfire_string_format(url, "/api/v1/uploads/%s", uuid);
+ if (r)
+ goto ERROR;
+
+ // Create a new transfer
+ r = pakfire_buildservice_create_transfer(&transfer, service, url);
+ if (r)
+ goto ERROR;
+
+ // Ask to DELETE
+ r = pakfire_downloader_transfer_set_method(transfer, PAKFIRE_METHOD_DELETE);
+ if (r)
+ goto ERROR;
+
+ // Enable authentication
+ r = pakfire_downloader_transfer_auth(transfer);
+ if (r)
+ goto ERROR;
+
+ // Write the response to the buffer
+ r = pakfire_downloader_transfer_set_output_buffer(transfer, &buffer, &length);
+ if (r)
+ goto ERROR;
+
+ // Run the transfer
+ r = pakfire_downloader_transfer_run(transfer, PAKFIRE_TRANSFER_NO_PROGRESS);
+ if (r)
+ goto ERROR;
+
+ // Parse the response
+ r = pakfire_buildservice_parse_response(service, transfer, buffer, length, &response);
+ if (r) {
+ CTX_ERROR(service->ctx, "Could not parse the response: %s\n", strerror(-r));
+ goto ERROR;
+ }
+
+ERROR:
+ if (transfer)
+ pakfire_downloader_transfer_unref(transfer);
+ if (response)
+ json_object_put(response);
+ if (buffer)
+ free(buffer);
+
+ return r;
+}
const char* path, const char* filename);
int pakfire_buildservice_list_uploads(
struct pakfire_buildservice* service, struct json_object** uploads);
+int pakfire_buildservice_delete_upload(
+ struct pakfire_buildservice* service, const char* uuid);
#endif /* PAKFIRE_BUILDSERVICE_H */