Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Do not print anything if there is nothing to do.
jlaffaye committed 14 years ago
commit 01fc6239b0c63691c1e0a098a0d7888fa09799a7
parent 66cb754
5 files changed +47 -23
modified libpkg/pkg.h
@@ -2,6 +2,7 @@
#define _PKG_H

#include <stdarg.h>
+
#include <stdbool.h>
#include <sys/types.h>
#include <openssl/pem.h>

@@ -659,6 +660,11 @@ void pkg_jobs_free(struct pkg_jobs *jobs);
int pkg_jobs_add(struct pkg_jobs *jobs, struct pkg *pkg);

/**
+
 * Returns true if there are no jobs.
+
 */
+
bool pkg_jobs_empty(struct pkg_jobs *jobs);
+

+
/**
 * Iterates over the packages in the jobs queue.
 * @param pkg Must be set to NULL for the first call.
 * @return An error code.
modified libpkg/pkg_jobs.c
@@ -1,4 +1,5 @@
#include <assert.h>
+
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

@@ -53,6 +54,14 @@ pkg_jobs_add(struct pkg_jobs *j, struct pkg *pkg)
	return (EPKG_OK);
}

+
bool
+
pkg_jobs_empty(struct pkg_jobs *j)
+
{
+
	assert(j != NULL);
+

+
	return (STAILQ_FIRST(&j->jobs) == NULL ? true : false);
+
}
+

int
pkg_jobs(struct pkg_jobs *j, struct pkg **pkg)
{
modified pkg/delete.c
@@ -30,7 +30,7 @@ exec_delete(int argc, char **argv)
	int flags = PKG_LOAD_BASIC;
	int force = 0;
	int yes = 0;
-
	int retcode = EPKG_OK;
+
	int retcode = 1;

	while ((ch = getopt(argc, argv, "agxXfy")) != -1) {
		switch (ch) {
@@ -82,11 +82,10 @@ exec_delete(int argc, char **argv)

	if (match == MATCH_ALL) {
		if ((it = pkgdb_query(db, NULL, match)) == NULL) {
-
			retcode = EPKG_FATAL;
			goto cleanup;
		}

-
		while ((retcode = pkgdb_it_next(it, &pkg, flags)) == EPKG_OK) {
+
		while (pkgdb_it_next(it, &pkg, flags) == EPKG_OK) {
			pkg_jobs_add(jobs, pkg);
			pkg = NULL;
		}
@@ -95,11 +94,10 @@ exec_delete(int argc, char **argv)
	} else {
		for (i = 0; i < argc; i++) {
			if ((it = pkgdb_query(db, argv[i], match)) == NULL) {
-
				retcode = EPKG_FATAL;
				goto cleanup;
			}

-
			while ((retcode = pkgdb_it_next(it, &pkg, flags)) == EPKG_OK) {
+
			while (pkgdb_it_next(it, &pkg, flags) == EPKG_OK) {
				pkg_jobs_add(jobs, pkg);
				pkg = NULL;
			}
@@ -109,8 +107,7 @@ exec_delete(int argc, char **argv)
	}

	/* check if we have something to deinstall */
-
	pkg = NULL;
-
	if ((retcode != EPKG_END) || (pkg_jobs(jobs, &pkg) != EPKG_OK)) {
+
	if (pkg_jobs_empty(jobs) == true) {
		goto cleanup;
	}

@@ -128,11 +125,13 @@ exec_delete(int argc, char **argv)
	} else
		goto cleanup;

-
	retcode = pkgdb_compact(db);
+
	pkgdb_compact(db);
+

+
	retcode = 0;

	cleanup:
	pkgdb_close(db);
	pkg_jobs_free(jobs);

-
	return (retcode == EPKG_OK ? EX_OK : 1);
+
	return (retcode);
}
modified pkg/install.c
@@ -27,7 +27,7 @@ exec_install(int argc, char **argv)
	struct pkgdb_it *it;
	struct pkgdb *db = NULL;
	struct pkg_jobs *jobs = NULL;
-
	int retcode = EPKG_OK;
+
	int retcode = 1;
	int i, ch, yes = 0;
	match_t match = MATCH_EXACT;

@@ -68,17 +68,15 @@ exec_install(int argc, char **argv)
	}

	if (pkg_jobs_new(&jobs, PKG_JOBS_INSTALL, db) != EPKG_OK) {
-
		retcode = EPKG_FATAL;
		goto cleanup;
	}

	for (i = 0; i < argc; i++) {
		if ((it = pkgdb_rquery(db, argv[i], match, FIELD_NAME)) == NULL) {
-
			retcode = EPKG_FATAL;
			goto cleanup;
		}

-
		while (( retcode = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC)) == EPKG_OK) {
+
		while (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC) == EPKG_OK) {
			pkg_jobs_add(jobs, pkgdb_query_remote(db, pkg_get(pkg, PKG_ORIGIN)));
		}
		
@@ -86,6 +84,9 @@ exec_install(int argc, char **argv)
	}
	pkg_free(pkg);

+
	if (pkg_jobs_empty(jobs) == true)
+
		goto cleanup;
+

	/* print a summary before applying the jobs */
	pkg = NULL;
	printf("The following packages will be installed:\n");
@@ -97,12 +98,14 @@ exec_install(int argc, char **argv)
		yes = query_yesno("\nProceed with installing packages [y/N]: ");

	if (yes == 1)
-
		retcode = pkg_jobs_apply(jobs, 0);
+
		if (pkg_jobs_apply(jobs, 0) != EPKG_OK)
+
			goto cleanup;
+

+
	retcode = 0;

	cleanup:
-
	
	pkg_jobs_free(jobs);
	pkgdb_close(db);

-
	return (retcode == EPKG_OK ? EX_OK : 1);
+
	return (retcode);
}
modified pkg/upgrade.c
@@ -29,7 +29,7 @@ exec_upgrade(int argc, char **argv)
	struct pkgdb_it *it;
	struct pkg *pkg = NULL;
	struct pkg_jobs *jobs = NULL;
-
	int retcode = EPKG_OK;
+
	int retcode = 1;
	int64_t oldsize = 0, newsize = 0;
	int64_t dlsize = 0;
	char size[7];
@@ -62,18 +62,23 @@ exec_upgrade(int argc, char **argv)
	}

	if (pkg_jobs_new(&jobs, PKG_JOBS_UPGRADE, db) != EPKG_OK) {
-
		retcode = EPKG_FATAL;
		goto cleanup;
	}

	if ((it = pkgdb_query_upgrades(db)) == NULL) {
-
		retcode = EPKG_FATAL;
		goto cleanup;
	}

-
	printf("The following packages will be upgraded: \n");
-
	while ((retcode = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC)) == EPKG_OK) {
+
	while (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC) == EPKG_OK) {
		pkg_jobs_add(jobs, pkgdb_query_remote(db, pkg_get(pkg, PKG_ORIGIN)));
+
	}
+

+
	if (pkg_jobs_empty(jobs) == true)
+
		goto cleanup;
+

+
	printf("The following packages will be upgraded: \n");
+
	pkg = NULL;
+
	while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
		oldsize += pkg_flatsize(pkg);
		newsize += pkg_new_flatsize(pkg);
		dlsize += pkg_new_pkgsize(pkg);
@@ -95,10 +100,12 @@ exec_upgrade(int argc, char **argv)
		yes = query_yesno("\nProceed with upgrading packages [y/N]: ");

	if (yes == 1)
-
		retcode = pkg_jobs_apply(jobs, 0);
+
		if (pkg_jobs_apply(jobs, 0) != EPKG_OK)
+
			goto cleanup;

-
	cleanup:
+
	retcode = 0;

+
	cleanup:
	pkgdb_it_free(it);
	pkg_jobs_free(jobs);
	pkgdb_close(db);