Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
pkg set -o now change origin for a port and everything that depends on it
Baptiste Daroussin committed 13 years ago
commit ea7b1cd15e03a56c1c14db8abb4e42fb61cdf16f
parent 3b8f8726ec8b2f31f1d62ecfda4eadeaa4eade8b
4 files changed +43 -21
modified libpkg/pkg.h
@@ -182,6 +182,13 @@ typedef enum {
	PKG_TIME,
} pkg_attr;

+
typedef enum {
+
	PKG_SET_FLATSIZE = 1,
+
	PKG_SET_AUTOMATIC,
+
	PKG_SET_DEPORIGIN,
+
	PKG_SET_ORIGIN
+
} pkg_set_attr;
+

/**
 * contains keys to refer to a string attribute
 * Used by pkg_dep_get()
modified libpkg/pkgdb.c
@@ -3073,19 +3073,19 @@ pkgdb_vset(struct pkgdb *db, int64_t id, va_list ap)

	while ((attr = va_arg(ap, int)) > 0) {
		switch (attr) {
-
			case PKG_FLATSIZE:
+
			case PKG_SET_FLATSIZE:
				snprintf(sql, BUFSIZ, "update packages set flatsize=%"PRId64" where id=%"PRId64";",
				    va_arg(ap, int64_t), id);
				sql_exec(db->sqlite, sql);
				break;
-
			case PKG_AUTOMATIC:
+
			case PKG_SET_AUTOMATIC:
				automatic = va_arg(ap, int);
				if (automatic != 0 && automatic != 1)
					continue;
				snprintf(sql, BUFSIZ, "update packages set automatic=%d where id=%"PRId64";", automatic, id);
				sql_exec(db->sqlite, sql);
				break;
-
			case PKG_DEP_ORIGIN:
+
			case PKG_SET_DEPORIGIN:
				oldorigin = va_arg(ap, char *);
				neworigin = va_arg(ap, char *);
				sqlite3_snprintf(BUFSIZ, sql, "update deps set origin='%q', "
@@ -3095,6 +3095,12 @@ pkgdb_vset(struct pkgdb *db, int64_t id, va_list ap)
				    neworigin, neworigin, neworigin, id, oldorigin);
				sql_exec(db->sqlite, sql);
				break;
+
			case PKG_SET_ORIGIN:
+
				neworigin = va_arg(ap, char *);
+
				sqlite3_snprintf(BUFSIZ, sql, "update packages set origin='%q' where id='%d';", neworigin, id);
+
				sql_exec(db->sqlite, sql);
+
				break;
+

		}
	}
	return (EPKG_OK);
modified pkg/check.c
@@ -336,7 +336,7 @@ exec_check(int argc, char **argv)
				newflatsize = pkg_recompute_flatsize(pkg);
				pkg_get(pkg, PKG_FLATSIZE, &flatsize);
				if (newflatsize != flatsize)
-
					pkgdb_set(db, pkg, PKG_FLATSIZE, newflatsize);
+
					pkgdb_set(db, pkg, PKG_SET_FLATSIZE, newflatsize);
			}
		}

modified pkg/set.c
@@ -54,6 +54,7 @@ exec_set(int argc, char **argv)
	int ch;
	int i;
	bool yes_flag = false;
+
	bool yes = yes_flag;
	match_t match = MATCH_EXACT;
	int newautomatic = -1;
	bool automatic = false;
@@ -91,6 +92,7 @@ exec_set(int argc, char **argv)
			case 'o':
				sets |= ORIGIN;
				loads |= PKG_LOAD_DEPS;
+
				match = MATCH_ALL;
				oldorigin = strdup(optarg);
				neworigin = strrchr(oldorigin, ':');
				if (neworigin == NULL) {
@@ -126,26 +128,36 @@ exec_set(int argc, char **argv)
	if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK)
		return (EX_IOERR);

-
	if (neworigin != NULL) {
-
		if ((it = pkgdb_query(db, neworigin, MATCH_EXACT)) == NULL) {
+
	if (!yes_flag)
+
		pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes_flag);
+

+
	if (oldorigin != NULL) {
+
		yes = yes_flag;
+
		match = MATCH_ALL;
+
		if ((it = pkgdb_query(db, oldorigin, MATCH_EXACT)) == NULL) {
			pkgdb_close(db);
			return (EX_IOERR);
		}

		if (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC) != EPKG_OK) {
-
			fprintf(stderr, "%s not installed", neworigin);
+
			fprintf(stderr, "%s not installed\n", oldorigin);
			free(oldorigin);
			pkgdb_it_free(it);
			pkgdb_close(db);
			return (EX_SOFTWARE);
		}
+
		pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version);
+
		if (!yes)
+
			yes = query_yesno("Change origin from %s to %s for %s-%s? [y/N]: ",
+
			    oldorigin, neworigin, name, version);
+
		if (yes) {
+
			if (pkgdb_set(db, pkg, PKG_SET_ORIGIN, neworigin) != EPKG_OK)
+
				return (EPKG_FATAL);
+
		}
		pkgdb_it_free(it);
	}
	i = 0;
	do {
-
		if (!yes_flag)
-
			pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes_flag);
-

		if ((it = pkgdb_query(db, argv[i], match)) == NULL) {
			if (oldorigin != NULL)
				free(oldorigin);
@@ -154,7 +166,7 @@ exec_set(int argc, char **argv)
		}

		while (pkgdb_it_next(it, &pkg, loads) == EPKG_OK) {
-
			bool yes = yes_flag;
+
			yes = yes_flag;
			if ((sets & AUTOMATIC) == AUTOMATIC) {
				pkg_get(pkg, PKG_AUTOMATIC, &automatic);
				if (automatic == newautomatic)
@@ -167,20 +179,17 @@ exec_set(int argc, char **argv)
						yes = query_yesno("Mark %s-%s as not automatically installed? [y/N]: ", name, version);
				}
				if (yes)
-
					pkgdb_set(db, pkg, PKG_AUTOMATIC, newautomatic);
+
					pkgdb_set(db, pkg, PKG_SET_AUTOMATIC, newautomatic);
			}
			if ((sets & ORIGIN) == ORIGIN) {
				struct pkg_dep *d = NULL;
-
				pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version);
				while (pkg_deps(pkg, &d) == EPKG_OK) {
-
					if (strcmp(pkg_dep_get(d, PKG_DEP_ORIGIN), oldorigin) == 0) {
-
						if (!yes)
-
							yes = query_yesno("%s-%s: change %s dependency to %s? [y/N]: ", name, version, oldorigin, neworigin);
-
						if (yes) {
-
							if (pkgdb_set(db, pkg, PKG_DEP_ORIGIN, oldorigin, neworigin) != EPKG_OK)
-
								return (EPKG_FATAL);
-
						}
-
					}
+
					/*
+
					 * Do not query user has he has already
+
					 * been queried
+
					 */
+
					if (pkgdb_set(db, pkg, PKG_SET_DEPORIGIN, oldorigin, neworigin) != EPKG_OK)
+
						return (EPKG_FATAL);
				}
			}
		}