Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Report the proper path when checksum fails
Baptiste Daroussin committed 11 years ago
commit f8334d0825558fd9f719e3888a6dde722c87a2cb
parent c3020d3
3 files changed +16 -7
modified libpkg/pkg.c
@@ -119,6 +119,7 @@ pkg_reset(struct pkg *pkg, pkg_t type)
	if (pkg->rootfd != -1)
		close(pkg->rootfd);
	pkg->rootfd = -1;
+
	pkg->rootpath[0] = '\0';

	pkg->type = type;
}
@@ -1803,16 +1804,19 @@ pkg_has_dir(struct pkg *p, const char *path)
int
pkg_open_root_fd(struct pkg *pkg)
{
+
	const char *path;
	const ucl_object_t 	*obj, *an;

	if (pkg->rootfd != -1)
		return (EPKG_OK);

-
	pkg_get(pkg, PKG_ANNOTATIONS, &an);
-
	obj = pkg_object_find(an, "relocated");
+
	path = pkg_getannotation(pkg, "relocated");
+
	if (path == NULL)
+
		path = "/";
+

+
	strlcpy(pkg->rootpath, path, sizeof(pkg->rootpath));

-
	if ((pkg->rootfd = open(obj ? pkg_object_string(obj) : "/" ,
-
	    O_DIRECTORY|O_CLOEXEC)) >= 0 )
+
	if ((pkg->rootfd = open(path , O_DIRECTORY|O_CLOEXEC)) >= 0 )
		return (EPKG_OK);

	pkg_emit_errno("open", obj ? pkg_object_string(obj) : "/");
modified libpkg/pkg_delete.c
@@ -240,7 +240,9 @@ pkg_delete_file(struct pkg *pkg, struct pkg_file *file, unsigned force)
	/* check sha256 */
	if (!force && sum[0] != '\0') {
		if (fstatat(pkg->rootfd, path, &st, AT_SYMLINK_NOFOLLOW) == -1) {
-
			pkg_emit_error("cannot stat %s: %s", path, strerror(errno));
+
			pkg_emit_error("cannot stat %s%s%s: %s", pkg->rootpath,
+
			    pkg->rootpath[strlen(pkg->rootpath) - 1] == '/' ? "" : "/",
+
			    path, strerror(errno));
			return;
		}
		if (S_ISLNK(st.st_mode)) {
@@ -253,8 +255,10 @@ pkg_delete_file(struct pkg *pkg, struct pkg_file *file, unsigned force)
				return;
		}
		if (strcmp(sha256, sum)) {
-
			pkg_emit_error("%s fails original SHA256 "
-
				"checksum, not removing", path);
+
			pkg_emit_error("%s%s%s fails original SHA256 "
+
				"checksum, not removing", pkg->rootpath,
+
				pkg->rootpath[strlen(pkg->rootpath) - 1] == '/' ? "" : "/",
+
				path);
			return;
		}
	}
modified libpkg/private/pkg.h
@@ -137,6 +137,7 @@ struct pkg {
	struct pkg_provide	*provides;
	unsigned			flags;
	int		rootfd;
+
	char		rootpath[MAXPATHLEN];
	char		**dir_to_del;
	size_t		dir_to_del_cap;
	size_t		dir_to_del_len;