Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Preliminary updating
Baptiste Daroussin committed 14 years ago
commit 066a57650c4e3584a5e24468aad98bb1ed54a964
parent cc6be70
2 files changed +133 -0
added pkg/updating.c
@@ -0,0 +1,126 @@
+
#include <sys/param.h>
+
#include <sys/queue.h>
+

+
#define _WITH_GETLINE
+
#include <err.h>
+
#include <pkg.h>
+
#include <stdio.h>
+
#include <string.h>
+
#include <sysexits.h>
+
#include <unistd.h>
+

+
#include "updating.h"
+

+
struct installed_ports {
+
	char *origin;
+
	SLIST_ENTRY(installed_ports) next;
+
};
+

+
void
+
usage_updating(void)
+
{
+
	fprintf(stderr, "usage: pkg updating [-h] [-d YYYYMMDD] [-f file] [portname ...]\n");
+

+
}
+

+
int
+
exec_updating(int argc, char **argv)
+
{
+
	char *date = NULL;
+
	char *dateline = NULL;
+
	char *updatingfile = NULL;
+
	struct installed_ports *port;
+
	SLIST_HEAD(,installed_ports) origins;
+
	int ch;
+
	char *line = NULL;
+
	size_t linecap = 0;
+
	ssize_t linelen;
+
	char *tmp;
+
	int head = 0;
+
	int found = 0;
+
	struct pkgdb *db;
+
	struct pkg *pkg;
+
	struct pkgdb_it *it;
+
	FILE *fd;
+

+
	while ((ch = getopt(argc, argv, "d:f:")) != -1) {
+
		switch (ch) {
+
			case 'd':
+
				date = optarg;
+
				break;
+
			case 'f':
+
				updatingfile = optarg;
+
				break;
+
			default:
+
				usage_updating();
+
				return (EX_USAGE);
+
		}
+
	}
+
	argc -= optind;
+
	argv += optind;
+

+
	/* checking date format */
+
	if (date != NULL)
+
		if (strlen(date) != 8 || strspn(date, "0123456789") != 8)
+
			err(EX_DATAERR, "Invalid date format");
+

+
	if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK)
+
		return (EX_IOERR);
+

+
	SLIST_INIT(&origins);
+
	if (argc == 0) {
+
		if (( it = pkgdb_query(db, NULL, MATCH_ALL)) == NULL)
+
			goto cleanup;
+

+
		while (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC) == EPKG_OK) {
+
			port = malloc(sizeof(struct installed_ports));
+
			port->origin = strdup(pkg_get(pkg, PKG_ORIGIN));
+
			SLIST_INSERT_HEAD(&origins, port, next);
+
		}
+
	} else {
+
	/* TODO missing per port */
+
	}
+

+
	if (updatingfile == NULL)
+
		asprintf(&updatingfile, "%s/UPDATING", pkg_config("PORTSDIR"));
+

+
	fd = fopen(updatingfile, "r");
+
	if (fd == NULL)
+
		errx(EX_UNAVAILABLE, "Unable to open: %s", updatingfile);
+

+
	while ((linelen = getline(&line, &linecap, fd)) > 0) {
+
		if (strspn(line, "0123456789:") == 9) {
+
			dateline = strdup(line);
+
			found = 0;
+
			head = 1;
+
		} else if (head == 0) {
+
			continue;
+
		}
+

+
		tmp = NULL;
+
		if (found == 0) {
+
			if (strstr(line, "AFFECTS") != NULL) {
+
				SLIST_FOREACH(port, &origins, next) {
+
					if ((tmp = strstr(line, port->origin)) != NULL) {
+
						break;
+
					}
+
				}
+
				if (tmp != NULL) {
+
					if ((date != NULL) && strncmp(dateline, date, 8) < 0)
+
						continue;
+
					printf("%s%s",dateline, line);
+
					found = 1;
+
				}
+
			}
+
		} else {
+
			printf("%s",line);
+
		}
+
	}
+
	fclose(fd);
+
cleanup:
+
	pkgdb_close(db);
+
	pkgdb_it_free(it);
+
	pkg_free(pkg);
+

+
	return (EXIT_SUCCESS);
+
}
added pkg/updating.h
@@ -0,0 +1,7 @@
+
#ifndef _UPDATING_H
+
#define _UPDATING_H
+

+
int exec_updating(int, char **);
+
void usage_updating(void);
+
#endif
+