Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Merge remote branch 'pkgng/master'
Will Andrews committed 14 years ago
commit 5bc6216d1a9f320b0832aacf467f1e5229a792bf
parent 3bc9f6e
8 files changed +285 -17
modified Makefile
@@ -1,5 +1,6 @@
SUBDIR=	external \
	libpkg \
-
	pkg
+
	pkg \
+
	pkg2legacy

.include <bsd.subdir.mk>
modified libpkg/pkg.h
@@ -446,7 +446,6 @@ struct pkgdb_it * pkgdb_query_which(struct pkgdb *db, const char *path);
#define PKG_LOAD_SCRIPTS (1<<5)
#define PKG_LOAD_OPTIONS (1<<6)
#define PKG_LOAD_MTREE (1<<7)
-
#define PKG_LOAD_NEWVERSION (1<<8)

/**
 * Get the next pkg.
modified libpkg/pkgdb.c
@@ -18,7 +18,7 @@
#include "pkgdb.h"
#include "pkg_util.h"

-
static struct pkgdb_it * pkgdb_it_new(struct pkgdb *, sqlite3_stmt *);
+
static struct pkgdb_it * pkgdb_it_new(struct pkgdb *, sqlite3_stmt *, int);
static void pkgdb_regex(sqlite3_context *, int, sqlite3_value **, int);
static void pkgdb_regex_basic(sqlite3_context *, int, sqlite3_value **);
static void pkgdb_regex_extended(sqlite3_context *, int, sqlite3_value **);
@@ -299,7 +299,7 @@ pkgdb_close(struct pkgdb *db)
}

static struct pkgdb_it *
-
pkgdb_it_new(struct pkgdb *db, sqlite3_stmt *s)
+
pkgdb_it_new(struct pkgdb *db, sqlite3_stmt *s, int type)
{
	struct pkgdb_it *it;

@@ -311,6 +311,7 @@ pkgdb_it_new(struct pkgdb *db, sqlite3_stmt *s)

	it->db = db;
	it->stmt = s;
+
	it->type = type;
	return (it);
}

@@ -346,6 +347,15 @@ pkgdb_it_next(struct pkgdb_it *it, struct pkg **pkg_p, int flags)
		pkg_set(pkg, PKG_PREFIX, sqlite3_column_text(it->stmt, 11));
		pkg_setflatsize(pkg, sqlite3_column_int64(it->stmt, 12));

+
		if (it->type == IT_UPGRADE) {
+
			pkg->type = PKG_UPGRADE;
+

+
			pkg_set(pkg, PKG_NEWVERSION, sqlite3_column_text(it->stmt, 13));
+
			pkg_setnewflatsize(pkg, sqlite3_column_int64(it->stmt, 14));
+
			pkg_setnewpkgsize(pkg, sqlite3_column_int64(it->stmt, 15));
+
			pkg_set(pkg, PKG_NEWPATH, sqlite3_column_text(it->stmt, 16));
+
		}
+

		if (flags & PKG_LOAD_DEPS)
			if ((ret = pkgdb_loaddeps(it->db, pkg)) != EPKG_OK)
				return (ret);
@@ -378,13 +388,6 @@ pkgdb_it_next(struct pkgdb_it *it, struct pkg **pkg_p, int flags)
			if ((ret = pkgdb_loadmtree(it->db, pkg)) != EPKG_OK)
				return (ret);

-
		if (flags & PKG_LOAD_NEWVERSION) {
-
			pkg_set(pkg, PKG_NEWVERSION, sqlite3_column_text(it->stmt, 13));
-
			pkg_setnewflatsize(pkg, sqlite3_column_int64(it->stmt, 14));
-
			pkg_setnewpkgsize(pkg, sqlite3_column_int64(it->stmt, 15));
-
			pkg_set(pkg, PKG_NEWPATH, sqlite3_column_text(it->stmt, 16));
-
		}
-

		return (EPKG_OK);
	case SQLITE_DONE:
		return (EPKG_END);
@@ -463,7 +466,7 @@ pkgdb_query(struct pkgdb *db, const char *pattern, match_t match)
	if (match != MATCH_ALL)
		sqlite3_bind_text(stmt, 1, pattern, -1, SQLITE_TRANSIENT);

-
	return (pkgdb_it_new(db, stmt));
+
	return (pkgdb_it_new(db, stmt, IT_LOCAL));
}

struct pkgdb_it *
@@ -485,7 +488,7 @@ pkgdb_query_which(struct pkgdb *db, const char *path)

	sqlite3_bind_text(stmt, 1, path, -1, SQLITE_TRANSIENT);

-
	return (pkgdb_it_new(db, stmt));
+
	return (pkgdb_it_new(db, stmt, IT_LOCAL));
}

int
@@ -1272,7 +1275,7 @@ pkgdb_query_upgrades(struct pkgdb *db)
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK)
		return (NULL);

-
	return (pkgdb_it_new(db, stmt));
+
	return (pkgdb_it_new(db, stmt, IT_UPGRADE));
}

struct pkgdb_it *
@@ -1296,5 +1299,5 @@ pkgdb_query_downgrades(struct pkgdb *db)
	if (sqlite3_prepare_v2(db->sqlite, sql, -1, &stmt, NULL) != SQLITE_OK)
		return (NULL);

-
	return (pkgdb_it_new(db, stmt));
+
	return (pkgdb_it_new(db, stmt, IT_UPGRADE));
}
modified libpkg/pkgdb.h
@@ -10,9 +10,13 @@ struct pkgdb {
	pkgdb_t remote;
};

+
#define IT_LOCAL 0
+
#define IT_UPGRADE 1
+

struct pkgdb_it {
	struct pkgdb *db;
	sqlite3_stmt *stmt;
+
	int type;
};

#endif
modified pkg/upgrade.c
@@ -54,7 +54,7 @@ exec_upgrade(int argc, char **argv)
	}

	printf("Packages to be upgraded: \n");
-
	while ((retcode = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC|PKG_LOAD_NEWVERSION)) == EPKG_OK) {
+
	while ((retcode = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC)) == EPKG_OK) {
		oldsize += pkg_flatsize(pkg);
		newsize += pkg_new_flatsize(pkg);
		dlsize += pkg_new_pkgsize(pkg);
@@ -69,7 +69,7 @@ exec_upgrade(int argc, char **argv)
	}

	printf("Packages to be downgraded: \n");
-
	while ((retcode = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC|PKG_LOAD_NEWVERSION)) == EPKG_OK) {
+
	while ((retcode = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC)) == EPKG_OK) {
		oldsize += pkg_flatsize(pkg);
		newsize += pkg_new_flatsize(pkg);
		dlsize += pkg_new_pkgsize(pkg);
added pkg2legacy/Makefile
@@ -0,0 +1,11 @@
+
PROG=	pkg2legacy
+
SRC=	pkg2legacy.c
+
BINDIR=	/usr/sbin
+

+
CFLAGS=	-I${.CURDIR}/../libpkg
+
LDADD=	-L../libpkg \
+
	-lpkgng
+
WARNS?=	6
+
NO_MAN=
+

+
.include <bsd.prog.mk>
added pkg2legacy/README
@@ -0,0 +1 @@
+
This is "throw away code" that in the end will be removed
added pkg2legacy/pkg2legacy.c
@@ -0,0 +1,249 @@
+
#include <err.h>
+

+
#include <bzlib.h>
+
#include <unistd.h>
+
#include <sys/sbuf.h>
+
#include <string.h>
+
#include <sysexits.h>
+
#include <sys/param.h>
+
#include <sys/types.h>
+
#include <sys/stat.h>
+

+
#include <archive.h>
+
#include <archive_entry.h>
+

+
#include <fts.h>
+

+
#include <pkg.h>
+

+
static int
+
usage(void)
+
{
+
	fprintf(stderr, "usage: %s pkgng_repository legacy_repository\n", getprogname());
+
	return (EX_USAGE);
+
}
+

+
int
+
main(int argc, char **argv)
+
{
+
	struct stat st;
+
	FTS *fts;
+
	FTSENT *p;
+
	char *dir[2];
+
	char *category;
+
	char destdir[MAXPATHLEN];
+
	char destpath[MAXPATHLEN];
+
	char relativepath[MAXPATHLEN];
+
	char linkpath[MAXPATHLEN];
+
	char *newpath;
+
	BZFILE *bz;
+
	int bzError;
+
	struct pkg **deps;
+
	struct archive *pkgng;
+
	struct archive *legacypkg;
+
	struct archive_entry *ae;
+
	size_t size;
+
	int i;
+
	int r;
+

+
	char *tmp;
+
	char *buf;
+
	struct pkg *pkg = NULL;
+

+
	struct sbuf *sbuf = sbuf_new_auto();
+
	struct sbuf *indexfile = sbuf_new_auto();
+

+
	FILE *indexf;
+

+
	if (argc != 3)
+
		return (usage());
+

+
	if (lstat(argv[1], &st) != 0)
+
		err(EX_USAGE, "Can't find pkgng repository");
+

+
	dir[0] = argv[1];
+
	dir[1] = NULL;
+

+
	if (!S_ISDIR(st.st_mode))
+
		errx(EX_USAGE, "%s is not a pkgng repository", argv[1]);
+

+
	if (lstat(argv[2], &st) != 0) {
+
		if (mkdir(argv[2], 0755) != 0)
+
			err(EX_CANTCREAT, "Unable to create legacy repository: %s", argv[2]);
+
	} else {
+
		errx(EX_USAGE, "legacy repository already exist");
+
	}
+

+
	getcwd(destdir, MAXPATHLEN);
+

+
	if (argv[2][0] == '/')
+
		strlcpy(destdir, argv[2], MAXPATHLEN);
+
	else
+
		snprintf(destdir, MAXPATHLEN, "%s/%s", destdir, argv[2]);
+

+
	snprintf(destpath, MAXPATHLEN, "%s/All", destdir);
+
	mkdir(destpath, 0755);
+

+
	if ((fts = fts_open(dir, FTS_NOSTAT, NULL)) == NULL)
+
		err(EX_SOFTWARE, "Problem reading the pkgng repository");
+

+
	ae = archive_entry_new();
+

+
	while ((p = fts_read(fts)) != NULL) {
+
		if (!strcmp(p->fts_name, "repo.txz"))
+
			continue;
+

+
		if (p->fts_info != FTS_F)
+
			continue;
+

+
		if (pkg_open(&pkg, p->fts_accpath) != EPKG_OK) {
+
			pkg_error_warn("Unable to open package %s (ignoring)", p->fts_accpath);
+
			continue;
+
		}
+

+
		archive_entry_clear(ae);
+
		category = strdup(pkg_get(pkg, PKG_ORIGIN));
+
		tmp = strrchr(category, '/');
+
		tmp[0] = '\0';
+

+
		/* prepare the indexfile */
+
		sbuf_printf(indexfile, "%s-%s|" /* name */
+
				"/usr/ports/%s|" /* path */
+
				"%s|" /* prefix */
+
				"%s|" /* comment */
+
				"/usr/ports/%s/pkg-descr|" /* origin */
+
				"%s|" /*maintainer */
+
				"%s|" /* categories */
+
				"|", /* build depends */
+
				pkg_get(pkg, PKG_NAME), pkg_get(pkg, PKG_VERSION),
+
				pkg_get(pkg, PKG_ORIGIN),
+
				pkg_get(pkg, PKG_PREFIX),
+
				pkg_get(pkg, PKG_COMMENT),
+
				pkg_get(pkg, PKG_ORIGIN),
+
				pkg_get(pkg, PKG_MAINTAINER),
+
				category /* FIXME where are the other categories */
+
			   );
+

+

+
		snprintf(destpath, MAXPATHLEN, "%s/%s", destdir, category);
+
		bzero(&st, sizeof(struct stat));
+
		if (lstat(category, &st) != 0)
+
			mkdir(destpath, 0755);
+

+
		snprintf(destpath, MAXPATHLEN, "%s/%s-%s.tbz", destpath, pkg_get(pkg, PKG_NAME), pkg_get(pkg, PKG_VERSION));
+
		snprintf(relativepath, MAXPATHLEN, "../%s/%s-%s.tbz", category, pkg_get(pkg, PKG_NAME), pkg_get(pkg, PKG_VERSION));
+
		snprintf(linkpath, MAXPATHLEN, "%s/All/%s.tbz",destdir, pkg_get(pkg, PKG_NAME));
+

+
		pkgng = archive_read_new();
+
		archive_read_support_format_tar(pkgng);
+
		archive_read_support_compression_all(pkgng);
+
		archive_read_open_filename(pkgng, p->fts_accpath, 4096);
+

+
		legacypkg = archive_write_new();
+
		archive_write_set_format_ustar(legacypkg);
+
		archive_write_set_compression_bzip2(legacypkg);
+
		archive_write_open_filename(legacypkg, destpath);
+

+
		archive_entry_set_pathname(ae, "+COMMENT");
+
		archive_entry_set_filetype(ae, AE_IFREG);
+
		archive_entry_set_perm(ae, 0644);
+
		archive_entry_set_gname(ae, "wheel");
+
		archive_entry_set_uname(ae, "root");
+
		archive_entry_set_size(ae, strlen(pkg_get(pkg, PKG_COMMENT)));
+
		archive_write_header(legacypkg, ae);
+
		archive_write_data(legacypkg, pkg_get(pkg, PKG_COMMENT), strlen(pkg_get(pkg, PKG_COMMENT)));
+

+
		sbuf_clear(sbuf);
+
		sbuf_printf(sbuf, "@comment PKG_FORMAT_REVISION:1.1\n"
+
				"@name %s-%s\n"
+
				"@comment ORIGIN:%s\n"
+
				"@cwd %s\n",
+
				pkg_get(pkg, PKG_NAME),
+
				pkg_get(pkg, PKG_VERSION),
+
				pkg_get(pkg, PKG_ORIGIN),
+
				pkg_get(pkg, PKG_PREFIX));
+

+
		if ((deps = pkg_deps(pkg)) != NULL) {
+
			for (i = 0; deps[i] != NULL; i++) {
+
				sbuf_printf(sbuf, "@pkgdep %s-%s\n"
+
						"@comment DEPORIGIN:%s\n",
+
						pkg_get(deps[i], PKG_NAME),
+
						pkg_get(deps[i], PKG_VERSION),
+
						pkg_get(deps[i], PKG_ORIGIN));
+
				sbuf_printf(indexfile, "%s-%s ", pkg_get(deps[i], PKG_NAME), pkg_get(deps[i], PKG_VERSION));
+
			}
+
		}
+

+
		sbuf_cat(indexfile, "|");
+
		sbuf_printf(indexfile, "%s|"
+
				"|" /* extract depends */
+
				"|" /* patch depends */
+
				"\n", /* fetch depends */
+
				pkg_get(pkg, PKG_WWW));
+
		archive_entry_clear(ae);
+
		while ((r = archive_read_next_header(pkgng, &ae)) != ARCHIVE_EOF) {
+
			if (archive_entry_pathname(ae)[0] == '+') {
+
				if (strcmp(archive_entry_pathname(ae), "+MANIFEST") == 0)
+
					continue;
+
				else {
+
					size = archive_entry_size(ae);
+
					buf = malloc(size + 1);
+
					archive_write_header(legacypkg, ae);
+
					archive_read_data(pkgng, buf, size);
+
					archive_write_data(legacypkg, buf, size);
+
					free(buf);
+
					continue;
+
				}
+
			}
+

+
			size = archive_entry_size(ae);
+

+
			strlcpy(destpath, archive_entry_pathname(ae), MAXPATHLEN);
+
			if (strncmp(destpath, pkg_get(pkg, PKG_PREFIX), strlen(pkg_get(pkg, PKG_PREFIX))) == 0)
+
				newpath = destpath + strlen(pkg_get(pkg, PKG_PREFIX));
+
			else {
+
				sbuf_cat(sbuf, "@cwd /");
+
				newpath = destpath;
+
			}
+

+
			if (newpath[0] == '/')
+
				newpath++;
+

+
			sbuf_printf(sbuf, "%s\n", newpath);
+
			archive_entry_set_pathname(ae, newpath);
+
			buf = malloc(size + 1);
+
			archive_write_header(legacypkg, ae);
+
			archive_read_data(pkgng, buf, size);
+
			archive_write_data(legacypkg, buf, size);
+
			free(buf);
+
		}
+

+
		archive_entry_set_pathname(ae, "+CONTENTS");
+
		archive_entry_set_filetype(ae, AE_IFREG);
+
		archive_entry_set_perm(ae, 0644);
+
		archive_entry_set_gname(ae, "wheel");
+
		archive_entry_set_uname(ae, "root");
+
		archive_entry_set_size(ae, sbuf_len(sbuf));
+
		archive_write_header(legacypkg, ae);
+
		archive_write_data(legacypkg, sbuf_data(sbuf), sbuf_len(sbuf));
+

+
		archive_write_finish(legacypkg);
+
		archive_read_finish(pkgng);
+

+
		snprintf(destpath, MAXPATHLEN, "%s/All", destdir);
+
		symlink(relativepath, linkpath);
+
	}
+

+
	snprintf(destpath, MAXPATHLEN, "%s/INDEX.bz2", destdir);
+
	indexf = fopen(destpath, "w");
+
	bz = BZ2_bzWriteOpen(&bzError, indexf, 9, 0, 0);
+
	BZ2_bzWrite(&bzError, bz, sbuf_data(indexfile), sbuf_len(indexfile));
+
	BZ2_bzWriteClose(&bzError, bz, 0, NULL, NULL);
+
	fclose(indexf);
+

+
	pkg_free(pkg);
+
	sbuf_delete(indexfile);
+
	sbuf_delete(sbuf);
+

+
	return (EXIT_SUCCESS);
+
}