1 /*#############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2023 Pakfire development team #
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. #
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. #
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/>. #
19 #############################################################################*/
23 #include <pakfire/client.h>
28 #include "upload_create.h"
30 static const char* args_doc
= "FILES...";
32 static const char* doc
= "Uploads a file";
36 struct cli_local_args
{
37 const char* files
[MAX_FILES
];
38 unsigned int num_files
;
41 static error_t
parse(int key
, char* arg
, struct argp_state
* state
, void* data
) {
42 struct cli_local_args
* args
= data
;
46 if (args
->num_files
>= MAX_FILES
)
49 args
->files
[args
->num_files
++] = arg
;
53 return ARGP_ERR_UNKNOWN
;
59 static int upload_callback(pakfire_client
* client
, const pakfire_xfer_response
* response
,
60 const char* path
, const char* uuid
, void* data
) {
64 r
= cli_api_error(response
, "Failed to upload the archive");
68 printf("Successfully uploaded %s as %s\n", path
, uuid
);
73 static int ready_callback(pakfire_client
* client
, void* data
) {
74 const struct cli_local_args
* local_args
= data
;
78 for (unsigned int i
= 0; i
< local_args
->num_files
; i
++) {
79 r
= pakfire_client_upload_create(client
, local_args
->files
[i
], NULL
, upload_callback
, NULL
);
87 int cli_upload_create(void* data
, int argc
, char* argv
[]) {
88 struct cli_global_args
* global_args
= data
;
89 struct cli_local_args local_args
= {};
92 // Parse the command line
93 r
= cli_parse(NULL
, NULL
, args_doc
, doc
, parse
, 0, argc
, argv
, &local_args
);
98 return cli_run_client(global_args
, ready_callback
, &local_args
);