Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
lua: filecmp: Fix for symlink
Emmanuel Vadot committed 5 years ago
commit 240e1aaa8912dbbe11cd16180f52c61385b0f650
parent 1b7f519
2 files changed +88 -6
modified libpkg/lua.c
@@ -205,18 +205,14 @@ lua_pkg_filecmp(lua_State *L)
	lua_getglobal(L, "package");
	struct pkg *pkg = lua_touserdata(L, -1);

-
	if (fstatat(pkg->rootfd, RELATIVE_PATH(file1), &s1, AT_SYMLINK_NOFOLLOW) == -1) {
+
	if (fstatat(pkg->rootfd, RELATIVE_PATH(file1), &s1, 0) == -1) {
		lua_pushinteger(L, 2);
		return (1);
	}
-
	if (fstatat(pkg->rootfd, RELATIVE_PATH(file2), &s2, AT_SYMLINK_NOFOLLOW) == -1) {
+
	if (fstatat(pkg->rootfd, RELATIVE_PATH(file2), &s2, 0) == -1) {
		lua_pushinteger(L, 2);
		return (1);
	}
-
	if (!S_ISREG(s1.st_mode) || !S_ISREG(s2.st_mode)) {
-
		lua_pushinteger(L, -1);
-
		return (1);
-
	}
	if (s1.st_size != s2.st_size) {
		lua_pushinteger(L, 1);
		return (1);
modified tests/frontend/lua.sh
@@ -11,6 +11,7 @@ tests_init \
	script_rename \
	script_upgrade \
	script_filecmp \
+
	script_filecmp_symlink \
	script_sample_not_exists \
	script_sample_exists \
	script_stat \
@@ -362,6 +363,91 @@ EOF
		pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy ${TMPDIR}/test-1.txz
}

+
script_filecmp_symlink_body() {
+
	echo "sametext" > a
+
	echo "sametext" > b
+
	ln -s a c
+
	ln -s b d
+
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
+
	cat << EOF >> test.ucl
+
files: {
+
	${TMPDIR}/a: ""
+
	${TMPDIR}/b: ""
+
	${TMPDIR}/c: ""
+
	${TMPDIR}/d: ""
+
}
+
lua_scripts: {
+
  post-install: [ <<EOS
+
  if pkg.filecmp("${TMPDIR}/c", "${TMPDIR}/d") == 0 then
+
     pkg.print_msg("same")
+
  else
+
     pkg.print_msg("different")
+
  end
+
EOS
+
, ]
+
}
+
EOF
+

+
	atf_check \
+
		-o empty \
+
		-e empty \
+
		-s exit:0 \
+
		pkg create -M test.ucl
+

+
	mkdir ${TMPDIR}/target
+
	atf_check \
+
		-o inline:"same\n" \
+
		-e empty \
+
		-s exit:0 \
+
		pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy ${TMPDIR}/test-1.txz
+

+
	# Cleanup
+
	atf_check \
+
		-o empty \
+
		-e empty \
+
		-s exit:0 \
+
		pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target delete -qfy test-1
+
	rm -rf ${TMPDIR}/target
+
	rm a b c d
+

+
	echo "sametext" > a
+
	echo "differenttext" > b
+
	ln -s a c
+
	ln -s b d
+
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
+
	cat << EOF >> test.ucl
+
files: {
+
	${TMPDIR}/a: ""
+
	${TMPDIR}/b: ""
+
	${TMPDIR}/c: ""
+
	${TMPDIR}/d: ""
+
}
+
lua_scripts: {
+
  post-install: [ <<EOS
+
  if pkg.filecmp("${TMPDIR}/c", "${TMPDIR}/d") == 0 then
+
     pkg.print_msg("same")
+
  else
+
     pkg.print_msg("different")
+
  end
+
EOS
+
, ]
+
}
+
EOF
+

+
	atf_check \
+
		-o empty \
+
		-e empty \
+
		-s exit:0 \
+
		pkg create -M test.ucl
+

+
	mkdir ${TMPDIR}/target
+
	atf_check \
+
		-o inline:"different\n" \
+
		-e empty \
+
		-s exit:0 \
+
		pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy ${TMPDIR}/test-1.txz
+
}
+

script_sample_not_exists_body() {
	echo "sample text" > a.sample
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"