Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add a pkg_symlink_cksumat to fix pkg-delete
Bryan Drewery committed 11 years ago
commit 86552e2e2a32deb1e026c5a07d3c30c2a0fc7f9e
parent c780eb5
3 files changed +39 -13
modified libpkg/pkg_delete.c
@@ -128,7 +128,8 @@ pkg_delete_file(struct pkg *pkg, struct pkg_file *file, unsigned force)
			return;
		}
		if (S_ISLNK(st.st_mode)) {
-
			if (pkg_symlink_cksum(path, NULL, sha256) != EPKG_OK)
+
			if (pkg_symlink_cksumat(pkg->rootfd, path, NULL,
+
			    sha256) != EPKG_OK)
				return;
		}
		else {
modified libpkg/private/utils.h
@@ -122,6 +122,8 @@ void set_nonblocking(int fd);
void print_trace(void);

int pkg_symlink_cksum(const char *path, const char *root, char *cksum);
+
int pkg_symlink_cksumat(int fd, const char *path, const char *root,
+
    char *cksum);

pid_t process_spawn_pipe(FILE *inout[2], const char *command);

modified libpkg/utils.c
@@ -942,20 +942,12 @@ print_trace(void)
#endif
}

-
int
-
pkg_symlink_cksum(const char *path, const char *root, char *cksum)
+
static int
+
pkg_symlink_cksum_readlink(const char *linkbuf, int linklen, const char *root,
+
    char *cksum)
{
-
	char linkbuf[MAXPATHLEN];
	const char *lnk;
-
	int ret;

-
	if ((ret = readlink(path, linkbuf, sizeof(linkbuf) - 1)) == -1) {
-
		pkg_emit_errno("pkg_symlink_cksum", "readlink failed");
-
		return (EPKG_FATAL);
-
	}
-

-
	/* Null terminate */
-
	linkbuf[ret] = '\0';
	lnk = linkbuf;
	if (root != NULL) {
		/* Skip root from checksum, as it is meaningless */
@@ -967,7 +959,38 @@ pkg_symlink_cksum(const char *path, const char *root, char *cksum)
	while(*lnk == '/')
		lnk ++;

-
	sha256_buf(lnk, ret, cksum);
+
	sha256_buf(lnk, linklen, cksum);

	return (EPKG_OK);
}
+

+
int
+
pkg_symlink_cksum(const char *path, const char *root, char *cksum)
+
{
+
	char linkbuf[MAXPATHLEN];
+
	int linklen;
+

+
	if ((linklen = readlink(path, linkbuf, sizeof(linkbuf) - 1)) == -1) {
+
		pkg_emit_errno("pkg_symlink_cksum", "readlink failed");
+
		return (EPKG_FATAL);
+
	}
+
	linkbuf[linklen] = '\0';
+

+
	return (pkg_symlink_cksum_readlink(linkbuf, linklen, root, cksum));
+
}
+

+
int
+
pkg_symlink_cksumat(int fd, const char *path, const char *root, char *cksum)
+
{
+
	char linkbuf[MAXPATHLEN];
+
	int linklen;
+

+
	if ((linklen = readlinkat(fd, path, linkbuf, sizeof(linkbuf) - 1)) ==
+
	    -1) {
+
		pkg_emit_errno("pkg_symlink_cksum", "readlink failed");
+
		return (EPKG_FATAL);
+
	}
+
	linkbuf[linklen] = '\0';
+

+
	return (pkg_symlink_cksum_readlink(linkbuf, linklen, root, cksum));
+
}