Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
Merge branch 'sqlite' of etoilebsd.net:pkgng into sqlite
jlaffaye committed 15 years ago
commit cdc035bc6a9cbcd8df9a09b9f112fa76a49b1456
parent f627c6be969dad5a22a8c1e8e6edb4312cfeab66
8 files changed +86 -21
modified libpkg/Makefile
@@ -9,6 +9,7 @@ SHLIB_MAJOR= 0
SRCS=		pkg.c \
		pkgdb.c \
		pkg_conflict.c \
+
		pkg_ports.c \
		pkg_file.c \
		pkg_manifest.c \
		pkg_version.c \
modified libpkg/pkg.c
@@ -124,11 +124,10 @@ pkg_open(const char *path, struct pkg **pkg, int query_flags)

	if (archive_read_open_filename(a, path, 4096) != ARCHIVE_OK) {
		archive_read_finish(a);
-
		printf("la");
		return (-1);
	}

-
	/* first patch to check is the archive is corrupted bye the way retreive
+
	/* first path to check is the archive is corrupted bye the way retreive
	 * informations */

	pkg_new(pkg);
modified libpkg/pkg.h
@@ -104,4 +104,9 @@ int pkg_create(const char *, pkg_formats, const char *, const char *, struct pkg
/* version */
int pkg_version_cmp(const char *, const char *);

+
/* glue to deal with ports */
+
int ports_parse_plist(struct pkg *, char *, const char *);
+
int ports_parse_depends(struct pkg *, char *);
+
int ports_parse_conflicts(struct pkg *, char *);
+

#endif
modified libpkg/pkg_conflict.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+
#include <err.h>

#include "pkg.h"
#include "pkg_private.h"
@@ -12,8 +13,8 @@ pkg_conflict_glob(struct pkg_conflict *c)
int
pkg_conflict_new(struct pkg_conflict **c)
{
-
	if ((*c = calloc(1, sizeof(struct pkg_conflict))))
-
		return (-1);
+
	if ((*c = calloc(1, sizeof(struct pkg_conflict))) == NULL)
+
		err(EXIT_FAILURE, "calloc()");

	return (0);
}
modified pkg/Makefile
@@ -6,7 +6,7 @@ SRCS= main.c \
	version.c \
	add.c

-
CFLAGS+=	-I${.CURDIR}/../libpkg -I${.CURDIR}/../external/tinycdb/
+
CFLAGS+=	-I${.CURDIR}/../libpkg
LDADD+=	-L${.CURDIR}/../external -L../libpkg -lpkg -lutil
WARNS?=	6
NO_MAN= true
modified pkg/main.c
@@ -10,6 +10,7 @@
#include "which.h"
#include "add.h"
#include "version.h"
+
#include "register.h"

static void usage(void);
static void usage_help(void);
@@ -29,6 +30,7 @@ static struct commands {
	{ "version", exec_version, usage_version},
	{ "which", exec_which, usage_which},
	{ "help", exec_help, usage_help},
+
	{ "register", exec_register, usage_register},
};
#define cmd_len (int)(sizeof(cmd)/sizeof(cmd[0]))

modified pkg/register.c
@@ -5,40 +5,47 @@
#include <pkg.h>
#include <string.h>
#include <unistd.h>
+
#include <stdlib.h>

#include "register.h"

+
void
+
usage_register(void)
+
{
+
	fprintf(stderr, "register ...\n"
+
			"register\n");
+
}
+

int
-
cmd_register(int argc, char **argv)
+
exec_register(int argc, char **argv)
{
	struct pkg *pkg;
+
	struct pkgdb *db;
+

	char ch;
-
	char *comment = NULL;
-
	char *descpath = NULL;
-
	char *oldplist = NULL;
-
	char *flattenedplist = NULL;
+
	char *plist = NULL;
	char *prefix = NULL;
	char *mtree = NULL;
-
	char *origin = NULL;
	char *depends = NULL;
+
	char *conflicts = NULL;

-
(void)pkg;
-
(void)flattenedplist;
+
	int ret = 0;

-
	while ((ch = getopt(argc, argv, "vc:d:f:p:P:m:o:O:")) != -1) {
+
	pkg_new(&pkg);
+
	while ((ch = getopt(argc, argv, "vc:d:f:p:P:m:o:O:C:")) != -1) {
		switch (ch) {
			case 'O':
			case 'v':
				/* IGNORE */
				break;
			case 'c':
-
				comment = strdup(optarg);
+
				ret += pkg_setcomment(pkg, optarg);
				break;
			case 'd':
-
				descpath = strdup(optarg);
+
				ret += pkg_setdesc_from_file(pkg, optarg);
				break;
			case 'f':
-
				oldplist = strdup(optarg);
+
				plist = strdup(optarg);
				break;
			case 'p':
				prefix = strdup(optarg);
@@ -50,11 +57,60 @@ cmd_register(int argc, char **argv)
				mtree = strdup(optarg);
				break;
			case 'o':
-
				origin = strdup(optarg);
+
				ret += pkg_setorigin(pkg, optarg);
+
				break;
+
			case 'C':
+
				conflicts = strdup(optarg);
				break;
+
			default:
+
				printf("%c\n", ch);
+
				usage_register();
+
				return (-1);
		}
	}
-
	printf("%s\n", comment);

-
	return(0);
+
	if (ret < 0) {
+
		pkg_free(pkg);
+
		return (ret);
+
	}
+

+
	if (depends != NULL) {
+
		ret += ports_parse_depends(pkg, depends);
+
		if (ret < 0)
+
			return (ret);
+
	}
+

+
	if (conflicts != NULL) {
+
		ret += ports_parse_conflicts(pkg, conflicts);
+
		if (ret < 0)
+
			return (ret);
+
	}
+

+
	ret += ports_parse_plist(pkg, plist, prefix);
+

+
	if (ret < 0)
+
		return (ret);
+

+
	if (prefix != NULL)
+
		free(prefix);
+

+
	if (plist != NULL)
+
		free(plist);
+

+
	if (conflicts != NULL)
+
		free(conflicts);
+

+
	if (depends != NULL)
+
		free(depends);
+

+
	if (pkgdb_open(&db) == -1) {
+
		pkgdb_warn(db);
+
		return (-1);
+
	}
+

+
	pkgdb_register_pkg(db, pkg);
+
	pkgdb_close(db);
+
	pkg_free(pkg);
+

+
	return (0);
}
modified pkg/register.h
@@ -1,5 +1,6 @@
#ifndef _REGISTER_H
#define _REGISTER_H

-
int cmd_register(int argc, char **argv);
+
void usage_register(void);
+
int exec_register(int argc, char **argv);
#endif