Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Print the package message if defined.
jlaffaye committed 15 years ago
commit 5cc32505c68c84bc4f95d4f483b627c2a6cb9c41
parent 634e042
3 files changed +35 -14
modified libpkg/pkg.h
@@ -343,7 +343,7 @@ const char *pkgdb_get_dir(void);
 * Add a new package.
 * @param path The path to the package archive file on the local disk
 */
-
int pkg_add(struct pkgdb *, const char *path);
+
int pkg_add(struct pkgdb *, const char *path, struct pkg **pkg);

/**
 * Archive formats options
modified libpkg/pkg_add.c
@@ -33,13 +33,13 @@ do_extract(struct archive *a, struct archive_entry *ae)
}

int
-
pkg_add(struct pkgdb *db, const char *path)
+
pkg_add(struct pkgdb *db, const char *path, struct pkg **pkg_p)
{
	struct archive *a;
	struct archive_entry *ae;
	struct pkgdb_it *it;
-
	struct pkg *pkg = NULL;
	struct pkg *p = NULL;
+
	struct pkg *pkg = NULL;
	struct pkg **deps;
	struct pkg_exec **execs;
	struct pkg_script **scripts;
@@ -106,7 +106,7 @@ pkg_add(struct pkgdb *db, const char *path)
					 ext);

			if (access(dpath, F_OK) == 0) {
-
				if (pkg_add(db, dpath) == EPKG_OK) {
+
				if (pkg_add(db, dpath, NULL) == EPKG_OK) {
					/*
					 * Recheck the deps because the last installed package may
					 * have installed our deps too.
@@ -204,5 +204,10 @@ pkg_add(struct pkgdb *db, const char *path)
	if (retcode == EPKG_OK)
		retcode = pkgdb_register_pkg(db, pkg);

+
	if (pkg_p != NULL)
+
		*pkg_p = (retcode == EPKG_OK) ? pkg : NULL;
+
	else
+
		pkg_free(pkg);
+

	return (retcode);
}
modified pkg/add.c
@@ -28,9 +28,9 @@ fetch_status(void *data, const char *url, off_t total, off_t done, time_t elapse
static int
is_url(const char *pattern)
{
-
	if (strnstr(pattern, "http://", 7) == 0 ||
-
		strnstr(pattern, "https://", 8) == 0 ||
-
		strnstr(pattern, "ftp://", 6) == 0)
+
	if (strncmp(pattern, "http://", 7) == 0 ||
+
		strncmp(pattern, "https://", 8) == 0 ||
+
		strncmp(pattern, "ftp://", 6) == 0)
		return (0);

	return (-1);
@@ -46,8 +46,11 @@ usage_add(void)
int
exec_add(int argc, char **argv)
{
-
	struct pkgdb *db;
+
	struct pkgdb *db = NULL;
+
	struct pkg *pkg = NULL;
	char *file;
+
	const char *message;
+
	int retcode = 0;

	if (argc != 2) {
		usage_add();
@@ -56,23 +59,36 @@ exec_add(int argc, char **argv)

	if (pkgdb_open(&db) != EPKG_OK) {
		pkg_error_warn("can not open database");
-
		pkgdb_close(db);
-
		return (-1);
+
		return (1);
	}

	if (is_url(argv[1]) == 0) {
		asprintf(&file, "./%s", basename(argv[1]));
		if (pkg_fetch_file(argv[1], file, NULL, &fetch_status) != EPKG_OK) {
			pkg_error_warn("can not fetch %s", argv[1]);
-
			return (1);
+
			retcode = 1;
+
			goto cleanup;
		}
	} else
		file = argv[1];

-
	if (pkg_add(db, file) != EPKG_OK)
+
	if (pkg_add(db, file, &pkg) != EPKG_OK) {
		pkg_error_warn("can not install %s", file);
+
		retcode = 1;
+
		goto cleanup;
+
	}
+

+
	message = pkg_get(pkg, PKG_MESSAGE);
+
	if (message != NULL && message[0] != '\0')
+
		printf("%s", message);
+

+
	cleanup:
+

+
	if (db != NULL)
+
		pkgdb_close(db);

-
	pkgdb_close(db);
+
	if (pkg != NULL)
+
		pkg_free(pkg);

-
	return (0);
+
	return (retcode);
}