Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Calculate the content of symlink passed.
Vsevolod Stakhov committed 11 years ago
commit be6abed19c3f66fce70ee70865e6592246876bcf
parent 9eecfc4
1 file changed +25 -11
modified libpkg/pkg_create.c
@@ -74,22 +74,36 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
		snprintf(fpath, sizeof(fpath), "%s%s%s", root ? root : "",
		    obj ? pkg_object_string(obj) : "", pkg_path);

-
		if (lstat(fpath, &st) != 0 || S_ISLNK(st.st_mode))
-
			continue;
-

+
		if (lstat(fpath, &st) == -1) {
+
			pkg_emit_errno("pkg_create_from_dir", "lstat failed");
+
			return (EPKG_FATAL);
+
		}
		if (file->size == 0)
			file->size = (int64_t)st.st_size;
		flatsize += file->size;

-
		if (pkg_sum == NULL || pkg_sum[0] == '\0') {
-
			if (pkg->type == PKG_OLD_FILE) {
-
				if (md5_file(fpath, sha256) != EPKG_OK)
-
					return (EPKG_FATAL);
-
			} else {
-
				if (sha256_file(fpath, sha256) != EPKG_OK)
-
					return (EPKG_FATAL);
+
		if (S_ISLNK(st.st_mode)) {
+
			char linkbuf[MAXPATHLEN];
+
			if ((ret = readlink(fpath, linkbuf, sizeof(linkbuf))) == -1) {
+
				pkg_emit_errno("pkg_create_from_dir", "readlink failed");
+
				return (EPKG_FATAL);
+
			}
+
			if (pkg_sum == NULL || pkg_sum[0] == '\0') {
+
				sha256_buf(linkbuf, ret, sha256);
+
				strlcpy(file->sum, sha256, sizeof(file->sum));
+
			}
+
		}
+
		else {
+
			if (pkg_sum == NULL || pkg_sum[0] == '\0') {
+
				if (pkg->type == PKG_OLD_FILE) {
+
					if (md5_file(fpath, sha256) != EPKG_OK)
+
						return (EPKG_FATAL);
+
				} else {
+
					if (sha256_file(fpath, sha256) != EPKG_OK)
+
						return (EPKG_FATAL);
+
				}
+
				strlcpy(file->sum, sha256, sizeof(file->sum));
			}
-
			strlcpy(file->sum, sha256, sizeof(file->sum));
		}
	}
	pkg_set(pkg, PKG_FLATSIZE, flatsize);