Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Properly set repository name for local packages.
Vsevolod Stakhov committed 11 years ago
commit 9f2cf5b78020c3878d68865a6dfc87cf40137318
parent d136a6d
3 files changed +129 -89
modified libpkg/pkg.h.in
@@ -1127,6 +1127,9 @@ int pkgdb_compact(struct pkgdb *db);
int pkg_add(struct pkgdb *db, const char *path, unsigned flags,
    struct pkg_manifest_key *keys, const char *location);

+
int pkg_add_from_remote(struct pkgdb *db, const char *path, unsigned flags,
+
    struct pkg_manifest_key *keys, const char *location, struct pkg *rp);
+

#define PKG_ADD_UPGRADE			(1U << 0)
#define PKG_ADD_USE_UPGRADE_SCRIPTS	(1U << 1)
#define PKG_ADD_AUTOMATIC		(1U << 2)
modified libpkg/pkg_add.c
@@ -153,9 +153,9 @@ cleanup:
	return (retcode);
}

-
int
-
pkg_add(struct pkgdb *db, const char *path, unsigned flags,
-
    struct pkg_manifest_key *keys, const char *location)
+
static int
+
pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
+
    struct pkg_manifest_key *keys, const char *location, struct pkg *remote)
{
	const char	*arch;
	const char	*origin;
@@ -204,99 +204,108 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags,
	/*
	 * Check the architecture
	 */
-

	pkg_get(pkg, PKG_ARCH, &arch, PKG_ORIGIN, &origin, PKG_NAME, &name);

-
	if (!is_valid_abi(arch, true)) {
-
		if ((flags & PKG_ADD_FORCE) == 0) {
-
			retcode = EPKG_FATAL;
-
			goto cleanup;
-
		}
-
	}
-

	/*
-
	 * Check if the package is already installed
+
	 * Additional checks for non-remote package
	 */
-

-
	ret = pkg_try_installed(db, origin, &pkg_inst, PKG_LOAD_BASIC);
-
	if (ret == EPKG_OK) {
-
		if ((flags & PKG_ADD_FORCE) == 0) {
-
			pkg_emit_already_installed(pkg_inst);
-
			retcode = EPKG_INSTALLED;
-
			pkg_free(pkg_inst);
-
			pkg_inst = NULL;
-
			goto cleanup;
-
		}
-
		else {
-
			pkg_emit_notice("package %s is already installed, forced install", name);
-
			pkg_free(pkg_inst);
-
			pkg_inst = NULL;
+
	if (remote == NULL) {
+
		if (!is_valid_abi(arch, true)) {
+
			if ((flags & PKG_ADD_FORCE) == 0) {
+
				retcode = EPKG_FATAL;
+
				goto cleanup;
+
			}
		}
-
	} else if (ret != EPKG_END) {
-
		retcode = ret;
-
		goto cleanup;
-
	}
-

-
	/*
-
	 * Check for dependencies by searching the same directory as
-
	 * the package archive we're reading.  Of course, if we're
-
	 * reading from a file descriptor or a unix domain socket or
-
	 * somesuch, there's no valid directory to search.
-
	 */
-

-
	if (strncmp(path, "-", 2) != 0 && (flags & PKG_ADD_UPGRADE) == 0) {
-
		basedir = dirname(path);
-
		if ((ext = strrchr(path, '.')) == NULL) {
-
			pkg_emit_error("%s has no extension", path);
-
			retcode = EPKG_FATAL;
+
		ret = pkg_try_installed(db, origin, &pkg_inst, PKG_LOAD_BASIC);
+
		if (ret == EPKG_OK) {
+
			if ((flags & PKG_ADD_FORCE) == 0) {
+
				pkg_emit_already_installed(pkg_inst);
+
				retcode = EPKG_INSTALLED;
+
				pkg_free(pkg_inst);
+
				pkg_inst = NULL;
+
				goto cleanup;
+
			}
+
			else {
+
				pkg_emit_notice("package %s is already installed, forced install",
+
						name);
+
				pkg_free(pkg_inst);
+
				pkg_inst = NULL;
+
			}
+
		} else if (ret != EPKG_END) {
+
			retcode = ret;
			goto cleanup;
		}
-
	} else {
-
		basedir = NULL;
-
		ext = NULL;
-
	}

-
	while (pkg_deps(pkg, &dep) == EPKG_OK) {
-
		if (pkg_is_installed(db, pkg_dep_origin(dep)) == EPKG_OK)
-
			continue;
-

-
		if (basedir != NULL) {
-
			const char *dep_name = pkg_dep_name(dep);
-
			const char *dep_ver = pkg_dep_version(dep);
+
		/*
+
		 * Check for dependencies by searching the same directory as
+
		 * the package archive we're reading.  Of course, if we're
+
		 * reading from a file descriptor or a unix domain socket or
+
		 * somesuch, there's no valid directory to search.
+
		 */

-
			snprintf(dpath, sizeof(dpath), "%s/%s-%s%s", basedir,
-
			    dep_name, dep_ver, ext);
+
		if (strncmp(path, "-", 2) != 0 && (flags & PKG_ADD_UPGRADE) == 0) {
+
			basedir = dirname(path);
+
			if ((ext = strrchr(path, '.')) == NULL) {
+
				pkg_emit_error("%s has no extension", path);
+
				retcode = EPKG_FATAL;
+
				goto cleanup;
+
			}
+
		} else {
+
			basedir = NULL;
+
			ext = NULL;
+
		}

-
			if ((flags & PKG_ADD_UPGRADE) == 0 &&
-
			    access(dpath, F_OK) == 0) {
-
				ret = pkg_add(db, dpath, PKG_ADD_AUTOMATIC, keys, location);
-
				if (ret != EPKG_OK) {
-
					retcode = EPKG_FATAL;
-
					goto cleanup;
+
		while (pkg_deps(pkg, &dep) == EPKG_OK) {
+
			if (pkg_is_installed(db, pkg_dep_origin(dep)) == EPKG_OK)
+
				continue;
+

+
			if (basedir != NULL) {
+
				const char *dep_name = pkg_dep_name(dep);
+
				const char *dep_ver = pkg_dep_version(dep);
+

+
				snprintf(dpath, sizeof(dpath), "%s/%s-%s%s", basedir,
+
						dep_name, dep_ver, ext);
+

+
				if ((flags & PKG_ADD_UPGRADE) == 0 &&
+
						access(dpath, F_OK) == 0) {
+
					ret = pkg_add(db, dpath, PKG_ADD_AUTOMATIC, keys, location);
+
					if (ret != EPKG_OK) {
+
						retcode = EPKG_FATAL;
+
						goto cleanup;
+
					}
+
				} else {
+
					pkg_emit_error("Missing dependency matching "
+
							"Origin: '%s' Version: '%s'",
+
							pkg_dep_get(dep, PKG_DEP_ORIGIN),
+
							pkg_dep_get(dep, PKG_DEP_VERSION));
+
					if ((flags & PKG_ADD_FORCE_MISSING) == 0) {
+
						retcode = EPKG_FATAL;
+
						goto cleanup;
+
					}
				}
			} else {
-
				pkg_emit_error("Missing dependency matching "
-
				    "Origin: '%s' Version: '%s'",
-
				    pkg_dep_get(dep, PKG_DEP_ORIGIN),
-
				    pkg_dep_get(dep, PKG_DEP_VERSION));
-
				if ((flags & PKG_ADD_FORCE_MISSING) == 0) {
-
					retcode = EPKG_FATAL;
-
					goto cleanup;
-
				}
+
				retcode = EPKG_FATAL;
+
				pkg_emit_missing_dep(pkg, dep);
+
				goto cleanup;
			}
-
		} else {
-
			retcode = EPKG_FATAL;
-
			pkg_emit_missing_dep(pkg, dep);
-
			goto cleanup;
		}
	}
+
	else {
+
		/* Save reponame */
+
		const char *reponame;
+

+
		pkg_get(remote, PKG_REPONAME, &reponame);
+
		pkg_addannotation(pkg, "repository", reponame);
+
	}

	if (location != NULL)
		pkg_addannotation(pkg, "relocated", location);

	/* register the package before installing it in case there are
	 * problems that could be caught here. */
-
	retcode = pkgdb_register_pkg(db, pkg, flags & PKG_ADD_UPGRADE, flags & PKG_ADD_FORCE);
+
	retcode = pkgdb_register_pkg(db, pkg,
+
			flags & PKG_ADD_UPGRADE,
+
			flags & PKG_ADD_FORCE);

	if (retcode != EPKG_OK)
		goto cleanup;
@@ -373,3 +382,17 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags,

	return (retcode);
}
+

+
int
+
pkg_add(struct pkgdb *db, const char *path, unsigned flags,
+
    struct pkg_manifest_key *keys, const char *location)
+
{
+
	return pkg_add_common(db, path, flags, keys, location, NULL);
+
}
+

+
int
+
pkg_add_from_remote(struct pkgdb *db, const char *path, unsigned flags,
+
    struct pkg_manifest_key *keys, const char *location, struct pkg *rp)
+
{
+
	return pkg_add_common(db, path, flags, keys, location, rp);
+
}
modified libpkg/pkg_jobs.c
@@ -1257,26 +1257,49 @@ static bool
pkg_need_upgrade(struct pkg *rp, struct pkg *lp, bool recursive)
{
	int ret, ret1, ret2;
-
	const char *lversion, *rversion, *larch, *rarch;
+
	const char *lversion, *rversion, *larch, *rarch, *reponame, *origin;
	struct pkg_option *lo = NULL, *ro = NULL;
	struct pkg_dep *ld = NULL, *rd = NULL;
	struct pkg_shlib *ls = NULL, *rs = NULL;
	struct pkg_conflict *lc = NULL, *rc = NULL;
	struct pkg_provide *lpr = NULL, *rpr = NULL;
+
	const ucl_object_t *an, *obj;

	/* Do not upgrade locked packages */
	if (pkg_is_locked(lp))
		return (false);

-
	pkg_get(lp, PKG_VERSION, &lversion, PKG_ARCH, &larch);
+
	pkg_get(lp, PKG_VERSION, &lversion, PKG_ARCH, &larch, PKG_ORIGIN, &origin);
	pkg_get(rp, PKG_VERSION, &rversion, PKG_ARCH, &rarch);

+
	/*
+
	 * XXX: for a remote package we also need to check whether options
+
	 * are compatible.
+
	 */
	ret = pkg_version_cmp(lversion, rversion);
	if (ret > 0)
		return (false);
	else if (ret < 0)
		return (true);

+
	/* Check reponame */
+
	pkg_get(rp, PKG_REPONAME, &reponame);
+
	pkg_get(lp, PKG_ANNOTATIONS, &obj);
+
	an = pkg_object_find(obj, "repository");
+
	if (an != NULL)  {
+
		if (strcmp(pkg_repo_ident(pkg_repo_find_name(reponame)),
+
				ucl_object_tostring(an)) != 0)  {
+
			/*
+
			 * If we have packages from some different repo, then
+
			 * we should not try to detect options changed and so on,
+
			 * basically, we need to check a version only and suggest upgrade
+
			 */
+
			pkg_debug(2, "package %s was installed from repo %s, so we ignore "
+
					"the same version of %s in %s repository", origin,
+
					ucl_object_tostring(an), origin, reponame);
+
			return (false);
+
		}
+
	}
	/* Compare archs */
	if (strcmp (larch, rarch) != 0) {
		pkg_set(rp, PKG_REASON, "ABI changed");
@@ -1411,8 +1434,6 @@ newer_than_local_pkg(struct pkg_jobs *j, struct pkg *rp, bool force)
		if (strcmp(pkg_repo_ident(pkg_repo_find_name(reponame)),
		    ucl_object_tostring(an)) != 0)  {
			return (false);
-
		} else {
-
			pkg_addannotation(rp, "repository", ucl_object_tostring(an));
		}
	}

@@ -2035,7 +2056,6 @@ pkg_jobs_handle_install(struct pkg_solved *ps, struct pkg_jobs *j, bool handle_r
{
	struct pkg *new, *old;
	const char *pkguid, *oldversion = NULL;
-
	const ucl_object_t *an, *obj;
	char path[MAXPATHLEN], *target;
	bool automatic;
	int flags = 0;
@@ -2044,13 +2064,10 @@ pkg_jobs_handle_install(struct pkg_solved *ps, struct pkg_jobs *j, bool handle_r
	old = ps->items[1] ? ps->items[1]->pkg : NULL;
	new = ps->items[0]->pkg;

-
	pkg_get(new, PKG_UNIQUEID, &pkguid, PKG_ANNOTATIONS, &obj,
-
			PKG_AUTOMATIC, &automatic);
+
	pkg_get(new, PKG_UNIQUEID, &pkguid, PKG_AUTOMATIC, &automatic);
	if (old != NULL)
		pkg_get(old, PKG_VERSION, &oldversion);

-
	an = pkg_object_find(obj, "repository");
-

	if (ps->items[0]->jp != NULL && ps->items[0]->jp->is_file) {
		/*
		 * We have package as a file
@@ -2087,15 +2104,12 @@ 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, NULL)) != EPKG_OK) {
+
	if ((retcode = pkg_add_from_remote(j->db, target, flags, keys,
+
			NULL, new)) != EPKG_OK) {
		pkgdb_transaction_rollback(j->db->sqlite, "upgrade");
		goto cleanup;
	}

-
	if (an != NULL) {
-
		pkgdb_add_annotation(j->db, new, "repository", ucl_object_tostring(an));
-
	}
-

	if (oldversion != NULL)
		pkg_emit_upgrade_finished(new, old);
	else