Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Fix return code of pkg check.
Vsevolod Stakhov committed 13 years ago
commit 9d0dfc9b99783ab6db22aa4ff7fed944bc298eb3
parent 0882c9e
3 files changed +33 -15
modified libpkg/pkg.c
@@ -1131,13 +1131,14 @@ pkg_copy_tree(struct pkg *pkg, const char *src, const char *dest)
	return (packing_finish(pack));
}

-
void
+
int
pkg_test_filesum(struct pkg *pkg)
{
	struct pkg_file *f = NULL;
	const char *path;
	const char *sum;
	char sha256[SHA256_DIGEST_LENGTH * 2 + 1];
+
	int rc = EPKG_OK;

	assert(pkg != NULL);

@@ -1146,13 +1147,17 @@ pkg_test_filesum(struct pkg *pkg)
		sum = pkg_file_cksum(f);
		if (*sum != '\0') {
			sha256_file(path, sha256);
-
			if (strcmp(sha256, sum) != 0)
+
			if (strcmp(sha256, sum) != 0) {
				pkg_emit_file_mismatch(pkg, f, sum);
+
				rc = EPKG_FATAL;
+
			}
		}
	}
+

+
	return (rc);
}

-
void
+
int
pkg_recompute(struct pkgdb *db, struct pkg *pkg)
{
	struct pkg_file *f = NULL;
@@ -1164,6 +1169,7 @@ pkg_recompute(struct pkgdb *db, struct pkg *pkg)
	bool regular = false;
	const char *sum;
	char sha256[SHA256_DIGEST_LENGTH * 2 + 1];
+
	int rc = EPKG_OK;

	while (pkg_files(pkg, &f) == EPKG_OK) {
		path = pkg_file_path(f);
@@ -1173,8 +1179,12 @@ pkg_recompute(struct pkgdb *db, struct pkg *pkg)
			if (S_ISLNK(st.st_mode)) {
				regular = false;
				*sha256 = '\0';
-
			} else
-
				sha256_file(path, sha256);
+
			} else {
+
				if (sha256_file(path, sha256) != EPKG_OK) {
+
					rc = EPKG_FATAL;
+
					break;
+
				}
+
			}

			/* special case for hardlinks */
			if (st.st_nlink > 1)
@@ -1190,6 +1200,8 @@ pkg_recompute(struct pkgdb *db, struct pkg *pkg)
	pkg_get(pkg, PKG_FLATSIZE, &oldflatsize);
	if (flatsize != oldflatsize)
		pkgdb_set(db, pkg, PKG_SET_FLATSIZE, flatsize);
+

+
	return (rc);
}

int
modified libpkg/pkg.h.in
@@ -1277,8 +1277,8 @@ int pkg_init(const char *);
int pkg_initialized(void);
int pkg_shutdown(void);

-
void pkg_test_filesum(struct pkg *);
-
void pkg_recompute(struct pkgdb *, struct pkg *);
+
int pkg_test_filesum(struct pkg *);
+
int pkg_recompute(struct pkgdb *, struct pkg *);
int pkgdb_reanalyse_shlibs(struct pkgdb *, struct pkg *);

int pkg_get_myarch(char *pkgarch, size_t sz);
modified pkg/check.c
@@ -248,7 +248,7 @@ exec_check(int argc, char **argv)
	struct pkgdb *db = NULL;
	match_t match = MATCH_EXACT;
	int flags = PKG_LOAD_BASIC;
-
	int ret;
+
	int ret, rc = EX_OK;
	int ch;
	bool yes;
	bool dcheck = false;
@@ -360,22 +360,31 @@ exec_check(int argc, char **argv)
				if (verbose)
					printf("Checking dependencies: %s\n", pkgname);
				nbpkgs += check_deps(db, pkg, &dh, noinstall);
+
				if (noinstall && nbpkgs > 0) {
+
					rc = EX_UNAVAILABLE;
+
				}
			}
			if (checksums) {
				if (verbose)
					printf("Checking checksums: %s\n", pkgname);
-
				pkg_test_filesum(pkg);
+
				if (pkg_test_filesum(pkg) != EPKG_OK) {
+
					rc = EX_DATAERR;
+
				}
			}
			if (recompute) {
				if (verbose)
					printf("Recomputing size and checksums: %s\n", pkgname);
-
				pkg_recompute(db, pkg);
+
				if (pkg_recompute(db, pkg) != EPKG_OK) {
+
					rc = EX_DATAERR;
+
				}
			}
			if (reanalyse_shlibs) {
				if (verbose)
					printf("Reanalyzing files for shlibs: %s\n", pkgname);
-
				if (pkgdb_reanalyse_shlibs(db, pkg) != EPKG_OK)
+
				if (pkgdb_reanalyse_shlibs(db, pkg) != EPKG_OK) {
					printf("Failed to reanalyse for shlibs: %s\n", pkgname);
+
					rc = EX_UNAVAILABLE;
+
				}
			}
		}

@@ -399,8 +408,5 @@ exec_check(int argc, char **argv)
	pkg_free(pkg);
	pkgdb_close(db);

-
	if (noinstall && nbpkgs > 0)
-
		return (EX_UNAVAILABLE);
-

-
	return (EX_OK);
+
	return (rc);
}