Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Merge pull request #462 from kAworu/master
Baptiste Daroussin committed 13 years ago
commit 14f0e3249f489ec80c50a0f279daf3e561f45983
parent ef541eb
3 files changed +30 -7
modified libpkg/pkg.c
@@ -1188,19 +1188,28 @@ pkg_recompute(struct pkgdb *db, struct pkg *pkg)
}

int
-
pkg_is_installed(struct pkgdb *db, const char *origin)
-
{
-
	struct pkg *pkg = NULL;
+
pkg_try_installed(struct pkgdb *db, const char *origin,
+
		struct pkg **pkg, unsigned flags) {
	struct pkgdb_it *it = NULL;
	int ret = EPKG_FATAL;

	if ((it = pkgdb_query(db, origin, MATCH_EXACT)) == NULL)
		return (EPKG_FATAL);

-
	ret = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC);
+
	ret = pkgdb_it_next(it, pkg, flags);
+
	pkgdb_it_free(it);
+

+
	return (ret);
+
}
+

+
int
+
pkg_is_installed(struct pkgdb *db, const char *origin)
+
{
+
	struct pkg *pkg = NULL;
+
	int ret = EPKG_FATAL;

+
	ret = pkg_try_installed(db, origin, &pkg, PKG_LOAD_BASIC);
	pkg_free(pkg);
-
	pkgdb_it_free(it);

	return (ret);
}
modified libpkg/pkg.h.in
@@ -814,6 +814,20 @@ const char *pkg_shlib_name(struct pkg_shlib const * const);
/**
 * @param db A pointer to a struct pkgdb object
 * @param origin Package origin
+
 * @param pkg An allocated struct pkg or a pointer to a NULL pointer. In the
+
 * last case, the function take care of the allocation.
+
 * @param flags OR'ed PKG_LOAD_*
+
 * @return EPKG_OK if the package is installed,
+
 * and != EPKG_OK if the package is not installed or an error occurred
+
 * Match will be case sensitive or insensitive depending on
+
 * pkgdb_case_sensitive()
+
 */
+
int pkg_try_installed(struct pkgdb *db, const char *origin,
+
		struct pkg **pkg, unsigned flags);
+

+
/**
+
 * @param db A pointer to a struct pkgdb object
+
 * @param origin Package origin
 * @return EPKG_OK if the package is installed,
 * and != EPKG_OK if the package is not installed or an error occurred
 * Match will be case sensitive or insensitive depending on
modified libpkg/pkg_add.c
@@ -215,10 +215,9 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags)
	 * Check if the package is already installed
	 */

-
	ret = pkg_is_installed(db, origin);
+
	ret = pkg_try_installed(db, origin, &pkg_inst, PKG_LOAD_BASIC);
	if (ret == EPKG_OK) {
		pkg_emit_already_installed(pkg_inst);
-
		pkg_free(pkg_inst);
		retcode = EPKG_INSTALLED;
		goto cleanup;
	} else if (ret != EPKG_END) {
@@ -324,6 +323,7 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags)
		archive_read_free(a);

	pkg_free(pkg);
+
	pkg_free(pkg_inst);

	return (retcode);
}