Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Implement --relocate for pkg add
Baptiste Daroussin committed 12 years ago
commit c11fddd206ed03468cc51a36a25d2285f0c383ec
parent b48249d
5 files changed +34 -12
modified libpkg/pkg.c
@@ -1290,7 +1290,7 @@ pkg_open_fd(struct pkg **pkg_p, int fd, struct pkg_manifest_key *keys, int flags

int
pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae,
-
		const char *path, struct pkg_manifest_key *keys, int flags, int fd)
+
    const char *path, struct pkg_manifest_key *keys, int flags, int fd)
{
	struct pkg	 *pkg;
	pkg_error_t	  retcode = EPKG_OK;
modified libpkg/pkg.h.in
@@ -1122,7 +1122,8 @@ int pkgdb_compact(struct pkgdb *db);
 * @param path The path to the package archive file on the local disk
 * @return An error code.
 */
-
int pkg_add(struct pkgdb *db, const char *path, unsigned flags, struct pkg_manifest_key *keys);
+
int pkg_add(struct pkgdb *db, const char *path, unsigned flags,
+
    struct pkg_manifest_key *keys, const char *location);

#define PKG_ADD_UPGRADE			(1U << 0)
#define PKG_ADD_USE_UPGRADE_SCRIPTS	(1U << 1)
modified libpkg/pkg_add.c
@@ -42,15 +42,19 @@
#include "private/pkg.h"

static int
-
do_extract(struct archive *a, struct archive_entry *ae)
+
do_extract(struct archive *a, struct archive_entry *ae, const char *location)
{
	int	retcode = EPKG_OK;
	int	ret = 0;
-
	char	path[MAXPATHLEN];
+
	char	path[MAXPATHLEN], pathname[MAXPATHLEN];
	struct stat st;

	do {
-
		const char *pathname = archive_entry_pathname(ae);
+
		snprintf(pathname, sizeof(pathname), "%s/%s",
+
		    location ? location : "",
+
		    archive_entry_pathname(ae)
+
		);
+
		archive_entry_set_pathname(ae, pathname);

		ret = archive_read_extract(a, ae, EXTRACT_ARCHIVE_FLAGS);
		if (ret != ARCHIVE_OK) {
@@ -150,7 +154,8 @@ cleanup:
}

int
-
pkg_add(struct pkgdb *db, const char *path, unsigned flags, struct pkg_manifest_key *keys)
+
pkg_add(struct pkgdb *db, const char *path, unsigned flags,
+
    struct pkg_manifest_key *keys, const char *location)
{
	const char	*arch;
	const char	*origin;
@@ -264,7 +269,7 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags, struct pkg_manifest_

			if ((flags & PKG_ADD_UPGRADE) == 0 &&
			    access(dpath, F_OK) == 0) {
-
				ret = pkg_add(db, dpath, PKG_ADD_AUTOMATIC, keys);
+
				ret = pkg_add(db, dpath, PKG_ADD_AUTOMATIC, keys, location);
				if (ret != EPKG_OK) {
					retcode = EPKG_FATAL;
					goto cleanup;
@@ -319,7 +324,7 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags, struct pkg_manifest_
	/*
	 * Extract the files on disk.
	 */
-
	if (extract && (retcode = do_extract(a, ae)) != EPKG_OK) {
+
	if (extract && (retcode = do_extract(a, ae, location)) != EPKG_OK) {
		/* If the add failed, clean up (silently) */
		pkg_delete_files(pkg, 2);
		pkg_delete_dirs(db, pkg, 1);
modified libpkg/pkg_jobs.c
@@ -1895,7 +1895,7 @@ pkg_jobs_handle_install(struct pkg_solved *ps, struct pkg_jobs *j, bool handle_r
			goto cleanup;
		}
	}
-
	if ((retcode = pkg_add(j->db, target, flags, keys)) != EPKG_OK) {
+
	if ((retcode = pkg_add(j->db, target, flags, keys, NULL)) != EPKG_OK) {
		pkgdb_transaction_rollback(j->db->sqlite, "upgrade");
		goto cleanup;
	}
modified src/add.c
@@ -34,6 +34,7 @@
#include <string.h>
#include <sysexits.h>
#include <unistd.h>
+
#include <getopt.h>

#include <pkg.h>

@@ -72,8 +73,20 @@ exec_add(int argc, char **argv)
	int failedpkgcount = 0;
	pkg_flags f = PKG_FLAG_NONE;
	struct pkg_manifest_key *keys = NULL;
-

-
	while ((ch = getopt(argc, argv, "IAfqM")) != -1) {
+
	const char *location = NULL;
+

+
	/* options descriptor */
+
	struct option longopts[] = {
+
		{ "no-scripts",          no_argument,            NULL,           'I' },
+
		{ "automatic",           no_argument,            NULL,           'A' },
+
		{ "force",               no_argument,            NULL,           'f' },
+
		{ "accept-missing",      no_argument,            NULL,           'M' },
+
		{ "quiet",               no_argument,            NULL,           'q' },
+
		{ "relocate",            required_argument,      NULL,            1  },
+
		{ NULL,                  0,                      NULL,            0  }
+
	};
+

+
	while ((ch = getopt_long(argc, argv, "IAfqM", longopts, NULL)) != -1) {
		switch (ch) {
		case 'I':
			f |= PKG_ADD_NOSCRIPT;
@@ -90,6 +103,9 @@ exec_add(int argc, char **argv)
		case 'q':
			quiet = true;
			break;
+
		case 1:
+
			location = optarg;
+
			break;
		default:
			usage_add();
			return (EX_USAGE);
@@ -154,7 +170,7 @@ exec_add(int argc, char **argv)

		}

-
		if ((retcode = pkg_add(db, file, f, keys)) != EPKG_OK) {
+
		if ((retcode = pkg_add(db, file, f, keys, location)) != EPKG_OK) {
			sbuf_cat(failedpkgs, argv[i]);
			if (i != argc - 1)
				sbuf_printf(failedpkgs, ", ");