]> git.ipfire.org Git - pakfire.git/blob - src/cli/lib/upload_create.c
buildservice: Export upload UUID
[pakfire.git] / src / cli / lib / upload_create.c
1 /*#############################################################################
2 # #
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2023 Pakfire development team #
5 # #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
18 # #
19 #############################################################################*/
20
21 #include <argp.h>
22
23 #include <pakfire/buildservice.h>
24 #include <pakfire/ctx.h>
25
26 #include "command.h"
27 #include "upload_create.h"
28
29 static const char* args_doc = "FILES...";
30
31 static const char* doc = "Uploads a file";
32
33 #define MAX_FILES 32
34
35 struct config {
36 const char* files[MAX_FILES];
37 unsigned int num_files;
38 };
39
40 static error_t parse(int key, char* arg, struct argp_state* state, void* data) {
41 struct config* config = data;
42
43 switch (key) {
44 case ARGP_KEY_ARG:
45 if (config->num_files >= MAX_FILES)
46 return -ENOBUFS;
47
48 config->files[config->num_files++] = arg;
49 break;
50
51 default:
52 return ARGP_ERR_UNKNOWN;
53 }
54
55 return 0;
56 }
57
58 int cli_upload_create(void* data, int argc, char* argv[]) {
59 struct pakfire_buildservice* service = NULL;
60 struct config config = {};
61 char* uuid = NULL;
62 int r;
63
64 struct pakfire_ctx* ctx = data;
65
66 // Parse the command line
67 r = cli_parse(NULL, NULL, args_doc, doc, parse, argc, argv, &config);
68 if (r)
69 goto ERROR;
70
71 // Connect to the build service
72 r = pakfire_buildservice_create(&service, ctx);
73 if (r)
74 goto ERROR;
75
76 // List uploads
77 for (unsigned int i = 0; i < config.num_files; i++) {
78 r = pakfire_buildservice_upload(service, config.files[i], NULL, &uuid);
79 if (r)
80 goto ERROR;
81
82 if (uuid) {
83 printf("Uploaded %s as %s\n", config.files[i], uuid);
84 free(uuid);
85 }
86 }
87
88 ERROR:
89 if (service)
90 pakfire_buildservice_unref(service);
91
92 return r;
93 }