Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Fix the lua stat function and add regression test for it
Baptiste Daroussin committed 5 years ago
commit 734ba6be543c2ffa93d014f32a7469dfc784922a
parent 2a0b876
2 files changed +36 -3
modified libpkg/lua_scripts.c
@@ -336,14 +336,16 @@ lua_stat(lua_State *L)
		return lua_pushnil(L), 1;
	}

-
	lua_createtable(L, 0, 3);
+
	lua_settop(L, 2);
+
	if (!lua_istable(L, 2))
+
		lua_newtable(L);
+

	lua_pushinteger(L, s.st_size);
	lua_setfield(L, -2, "size");
	lua_pushinteger(L, s.st_uid);
	lua_setfield(L, -2, "uid");
	lua_pushinteger(L, s.st_gid);
	lua_setfield(L, -2, "gid");
-
	lua_pushinteger(L, s.st_nlink);

	return (1);
}
modified tests/frontend/lua.sh
@@ -11,7 +11,8 @@ tests_init \
	script_rename \
	script_upgrade \
	script_sample_not_exists \
-
	script_sample_exists
+
	script_sample_exists \
+
	script_stat

script_basic_body() {
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
@@ -336,3 +337,33 @@ EOF
		-s exit:1 \
		cmp -s ${TMPDIR}/target${TMPDIR}/a.sample ${TMPDIR}/target${TMPDIR}/a
}
+

+
script_stat_body() {
+
	touch plop
+
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
+
	cat << EOF >> test.ucl
+
files: {
+
	${TMPDIR}/plop: ""
+
}
+
lua_scripts: {
+
  post-install: [ <<EOS
+
  local st = pkg.stat("${TMPDIR}/plop")
+
  if st["size"] == 0 then
+
     pkg.print_msg "zero"
+
  end
+
EOS
+
, ]
+
}
+
EOF
+
	atf_check \
+
		-o empty \
+
		-e empty \
+
		-s exit:0 \
+
		pkg create -M test.ucl
+
	mkdir ${TMPDIR}/target
+
	atf_check \
+
		-o inline:"zero\n" \
+
		-e empty \
+
		-s exit:0 \
+
		pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy ${TMPDIR}/test-1.txz
+
}