]> git.ipfire.org Git - pakfire.git/commitdiff
buildservice: Implement deleting repositories
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Oct 2023 14:04:05 +0000 (14:04 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Oct 2023 14:04:05 +0000 (14:04 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/repo_delete.c [new file with mode: 0644]
src/cli/lib/repo_delete.h [new file with mode: 0644]

diff --git a/src/cli/lib/repo_delete.c b/src/cli/lib/repo_delete.c
new file mode 100644 (file)
index 0000000..cf70d88
--- /dev/null
@@ -0,0 +1,93 @@
+/*#############################################################################
+#                                                                             #
+# 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 <json.h>
+
+#include <pakfire/buildservice.h>
+
+#include "command.h"
+#include "dump.h"
+#include "pakfire.h"
+#include "repo_delete.h"
+
+static const char* args_doc = "DISTRO NAME";
+
+static const char* doc = "Delete a repository";
+
+struct config {
+       const char* distro;
+       const char* name;
+};
+
+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->distro)
+                               config->distro = arg;
+
+                       else if (!config->name)
+                               config->name = arg;
+
+                       else
+                               argp_usage(state);
+                       break;
+
+               default:
+                       return ARGP_ERR_UNKNOWN;
+       }
+
+       return 0;
+}
+
+int cli_repo_delete(void* data, int argc, char* argv[]) {
+       struct pakfire_buildservice* service = NULL;
+       struct json_object* repo = NULL;
+       struct config config = {};
+       int r;
+
+       struct cli_config* cli_config = 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, cli_config->ctx);
+       if (r)
+               goto ERROR;
+
+       // Delete the repository
+       r = pakfire_buildservice_delete_repo(service, config.distro, config.name);
+       if (r)
+               goto ERROR;
+
+ERROR:
+       if (service)
+               pakfire_buildservice_unref(service);
+       if (repo)
+               json_object_put(repo);
+
+       return r;
+}
diff --git a/src/cli/lib/repo_delete.h b/src/cli/lib/repo_delete.h
new file mode 100644 (file)
index 0000000..4aa0962
--- /dev/null
@@ -0,0 +1,26 @@
+/*#############################################################################
+#                                                                             #
+# 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_REPO_DELETE_H
+#define PAKFIRE_CLI_REPO_DELETE_H
+
+int cli_repo_delete(void* data, int argc, char* argv[]);
+
+#endif /* PAKFIRE_CLI_REPO_DELETE_H */