Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
pkg register support input dir to sync datas from (aka fakeroot) changes in the api: if a directory is given to packing_init then the packing will write datas to that directory instead of creating a package new pkg_copy_tree function changes in userland: new -i option to pkg register to specify a directory to take as a fakeroot
Baptiste Daroussin committed 15 years ago
commit 70197210c0942076bef0abcdae586f8ae3baccee
parent 2748cf7
6 files changed +62 -16
modified libpkg/packing.c
@@ -34,17 +34,22 @@ packing_init(struct packing **pack, const char *path, pkg_formats format)

	(*pack)->entry = archive_entry_new();

-
	(*pack)->awrite = archive_write_new();
-
	archive_write_set_format_pax_restricted((*pack)->awrite);
-
	if ((ext = packing_set_format((*pack)->awrite, format)) == NULL) {
-
		archive_read_finish((*pack)->aread);
-
		archive_write_finish((*pack)->awrite);
-
		archive_entry_free((*pack)->entry);
-
		return (pkg_error_set(EPKG_FORMAT, "Unsupported format"));
+
	if (!is_dir(path)) {
+
		(*pack)->awrite = archive_write_new();
+
		archive_write_set_format_pax_restricted((*pack)->awrite);
+
		if ((ext = packing_set_format((*pack)->awrite, format)) == NULL) {
+
			archive_read_finish((*pack)->aread);
+
			archive_write_finish((*pack)->awrite);
+
			archive_entry_free((*pack)->entry);
+
			return (pkg_error_set(EPKG_FORMAT, "Unsupported format"));
+
		}
+
		snprintf(archive_path, sizeof(archive_path), "%s.%s", path, ext);
+

+
		archive_write_open_filename((*pack)->awrite, archive_path);
+
	} else { /* pass mode directly write to the disk */
+
		(*pack)->awrite = archive_write_disk_new();
+
		archive_write_disk_set_options((*pack)->awrite, EXTRACT_ARCHIVE_FLAGS);
	}
-
	snprintf(archive_path, sizeof(archive_path), "%s.%s", path, ext);
-

-
	archive_write_open_filename((*pack)->awrite, archive_path);

	return (EPKG_OK);
}
modified libpkg/pkg.c
@@ -658,3 +658,28 @@ pkg_addconflict(struct pkg *pkg, const char *glob)

	return (EPKG_OK);
}
+

+
int
+
pkg_copy_tree(struct pkg *pkg, const char *src, const char *dest)
+
{
+
	struct packing *pack;
+
	struct pkg_file **files;
+
	char spath[MAXPATHLEN];
+
	char dpath[MAXPATHLEN];
+
	int i;
+

+
	if (packing_init(&pack, dest, 0) != EPKG_OK) {
+
		/* TODO */
+
		return (pkg_error_set(EPKG_FATAL, "unable to create archive"));
+
	}
+

+
	files = pkg_files(pkg);
+
	for (i = 0; files[i] != NULL; i++) {
+
		snprintf(spath, MAXPATHLEN, "%s%s", src, pkg_file_path(files[i]));
+
		snprintf(dpath, MAXPATHLEN, "%s%s", dest, pkg_file_path(files[i]));
+
		printf("%s -> %s\n", spath, dpath);
+
		packing_append_file(pack, spath, dpath);
+
	}
+

+
	return (packing_finish(pack));
+
}
modified libpkg/pkg.h
@@ -554,4 +554,10 @@ const char * pkg_error_string(void);
 */
void pkg_error_warn(const char *fmt, ...);

+
/**
+
 * TODO
+
 */
+
int pkg_copy_tree(struct pkg *, const char *src, const char *dest);
+

+

#endif
modified libpkg/pkg_add.c
@@ -11,10 +11,6 @@
#include "pkg_error.h"
#include "pkg_private.h"

-
#define EXTRACT_ARCHIVE_FLAGS  (ARCHIVE_EXTRACT_OWNER |ARCHIVE_EXTRACT_PERM| \
-
		ARCHIVE_EXTRACT_TIME  |ARCHIVE_EXTRACT_ACL | \
-
		ARCHIVE_EXTRACT_FFLAGS|ARCHIVE_EXTRACT_XATTR)
-

static int
do_extract(struct archive *a, struct archive_entry *ae)
{
modified libpkg/pkg_private.h
@@ -11,6 +11,10 @@

#define PKG_NUM_FIELDS 14

+
#define EXTRACT_ARCHIVE_FLAGS  (ARCHIVE_EXTRACT_OWNER |ARCHIVE_EXTRACT_PERM| \
+
		ARCHIVE_EXTRACT_TIME  |ARCHIVE_EXTRACT_ACL | \
+
		ARCHIVE_EXTRACT_FFLAGS|ARCHIVE_EXTRACT_XATTR)
+

struct pkg {
	struct {
		struct sbuf *value;
modified pkg/register.c
@@ -35,7 +35,7 @@ usage_register(void)
	fprintf(stderr, "usage: pkg register -c comment -d desc -f plist_file -p prefix\n");
	fprintf(stderr, "                    -m mtree_file -n pkgname -o origin -r maintainer\n");
	fprintf(stderr, "                    [-P depends] [-C conflicts] [-M message_file] [-s scripts]\n");
-
	fprintf(stderr, "                    [-a arch] [-w www] [-O options] [-H]\n\n");
+
	fprintf(stderr, "                    [-a arch] [-w www] [-O options] [-H] [-i input_dir]\n\n");
	fprintf(stderr, "For more information see 'pkg help register'.\n");
}

@@ -54,6 +54,7 @@ exec_register(int argc, char **argv)
	char *v = NULL;
	char *arch = NULL;
	char *www = NULL;
+
	char *input_path = NULL;

	const char *desc = NULL;
	size_t size;
@@ -69,7 +70,7 @@ exec_register(int argc, char **argv)
	}

	pkg_new(&pkg);
-
	while ((ch = getopt(argc, argv, "vHc:d:f:p:P:m:o:C:n:M:s:a:r:w:O:")) != -1) {
+
	while ((ch = getopt(argc, argv, "vHc:d:f:p:P:m:o:C:n:M:s:a:r:w:O:i:")) != -1) {
		switch (ch) {
			case 'v':
				/* IGNORE */
@@ -134,6 +135,10 @@ exec_register(int argc, char **argv)
			case 'H':
				heuristic = true;
				break;
+
			case 'i':
+
				if ((input_path = strdup(optarg)) == NULL)
+
					errx(1, "cannot allocate memory");
+
				break;
			default:
				printf("%c\n", ch);
				usage_register();
@@ -206,6 +211,11 @@ exec_register(int argc, char **argv)
	if (heuristic)
		pkg_analyse_files(db, pkg);

+
	if (input_path != NULL) {
+
		pkg_copy_tree(pkg, input_path, "/");
+
		free(input_path);
+
	}
+

	if (pkgdb_register_pkg(db, pkg) != EPKG_OK) {
		pkg_error_warn("can not register package");
		retcode = 1;