update.c 1.49 KB
Newer Older
1 2 3
/* update.c - Alpine Package Keeper (APK)
 *
 * Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
4
 * Copyright (C) 2008-2011 Timo Teräs <timo.teras@iki.fi>
5 6
 * All rights reserved.
 *
Timo Teräs's avatar
Timo Teräs committed
7
 * This program is free software; you can redistribute it and/or modify it
8 9 10 11 12 13 14 15 16
 * under the terms of the GNU General Public License version 2 as published
 * by the Free Software Foundation. See http://www.gnu.org/ for details.
 */

#include <stdio.h>
#include "apk_defines.h"
#include "apk_applet.h"
#include "apk_database.h"
#include "apk_version.h"
Natanael Copa's avatar
Natanael Copa committed
17
#include "apk_print.h"
18

19
static int update_main(void *ctx, struct apk_database *db, struct apk_string_array *args)
20
{
21 22
	struct apk_repository *repo;
	int i;
23
	char buf[32] = "OK:";
24 25

	if (apk_verbosity < 1)
26
		return db->repo_update_errors;
27 28 29 30 31 32 33

	for (i = 0; i < db->num_repos; i++) {
		repo = &db->repos[i];

		if (APK_BLOB_IS_NULL(repo->description))
			continue;

34 35
		apk_message(BLOB_FMT " [%s]",
			    BLOB_PRINTF(repo->description),
36 37 38
			    db->repos[i].url);
	}

39 40 41 42
	if (db->repo_update_errors != 0)
		snprintf(buf, sizeof(buf), "%d errors;",
			 db->repo_update_errors);
	apk_message("%s %d distinct packages available", buf,
43 44
		db->available.packages.num_items);

45
	return db->repo_update_errors;
46 47 48 49
}

static struct apk_applet apk_update = {
	.name = "update",
50
	.help = "Update repository indexes from all remote repositories",
Timo Teräs's avatar
Timo Teräs committed
51
	.open_flags = APK_OPENF_WRITE,
52
	.forced_force = APK_FORCE_REFRESH,
53
	.command_groups = APK_COMMAND_GROUP_SYSTEM,
54 55 56 57 58
	.main = update_main,
};

APK_DEFINE_APPLET(apk_update);