summaryrefslogtreecommitdiff
path: root/src/app_verify.c
blob: fd1a148e17d4dc96aed2c9c654c3d0e684465843 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* app_verify.c - Alpine Package Keeper (APK)
 *
 * Copyright (C) 2008-2011 Timo Teräs <timo.teras@iki.fi>
 * All rights reserved.
 *
 * SPDX-License-Identifier: GPL-2.0-only
 */

#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

#include "apk_applet.h"
#include "apk_print.h"
#include "apk_extract.h"

static int verify_main(void *ctx, struct apk_ctx *ac, struct apk_string_array *args)
{
	struct apk_out *out = &ac->out;
	struct apk_extract_ctx ectx;
	char **parg;
	int r, rc = 0;

	apk_extract_init(&ectx, ac, 0);

	foreach_array_item(parg, args) {
		r = apk_extract(&ectx, apk_istream_from_file(AT_FDCWD, *parg));
		if (apk_out_verbosity(out) >= 1)
			apk_msg(out, "%s: %s", *parg,
				r < 0 ? apk_error_str(r) : "OK");
		else if (r < 0)
			apk_out(out, "%s", *parg);
		if (r < 0) rc++;
	}

	return rc;
}

static struct apk_applet apk_verify_applet = {
	.name = "verify",
	.main = verify_main,
};

APK_DEFINE_APPLET(apk_verify_applet);