Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add the type to the stat object
Baptiste Daroussin committed 5 years ago
commit 71d00f7371ba34703d1ae5638f8aa1654382edbf
parent cd353a5
2 files changed +21 -3
modified libpkg/lua_scripts.c
@@ -346,6 +346,7 @@ lua_stat(lua_State *L)
	lua_getglobal(L, "package");
	struct pkg *pkg = lua_touserdata(L, -1);
	struct stat s;
+
	const char *type = "unknown";

	if (fstatat(pkg->rootfd, path, &s, AT_SYMLINK_NOFOLLOW) == -1) {
		return lua_pushnil(L), 1;
@@ -361,6 +362,22 @@ lua_stat(lua_State *L)
	lua_setfield(L, -2, "uid");
	lua_pushinteger(L, s.st_gid);
	lua_setfield(L, -2, "gid");
+
	if (S_ISREG(s.st_mode))
+
		type = "reg";
+
	else if (S_ISDIR(s.st_mode))
+
		type = "dir";
+
	else if (S_ISCHR(s.st_mode))
+
		type = "chr";
+
	else if (S_ISLNK(s.st_mode))
+
		type = "lnk";
+
	else if (S_ISSOCK(s.st_mode))
+
		type = "sock";
+
	else if (S_ISBLK(s.st_mode))
+
		type = "blk";
+
	else if (S_ISFIFO(s.st_mode))
+
		type = "fifo";
+
	lua_pushstring(L, type);
+
	lua_setfield(L, -2, "type");

	return (1);
}
modified tests/frontend/lua.sh
@@ -348,9 +348,10 @@ files: {
lua_scripts: {
  post-install: [ <<EOS
  local st = pkg.stat("${TMPDIR}/plop")
-
  if st["size"] == 0 then
-
     pkg.print_msg "zero"
+
  if st.size == 0 then
+
     pkg.print_msg("zero")
  end
+
  pkg.print_msg(st.type)
EOS
, ]
}
@@ -362,7 +363,7 @@ EOF
		pkg create -M test.ucl
	mkdir ${TMPDIR}/target
	atf_check \
-
		-o inline:"zero\n" \
+
		-o inline:"zero\nreg\n" \
		-e empty \
		-s exit:0 \
		pkg -o REPOS_DIR=/dev/null -r ${TMPDIR}/target install -qfy ${TMPDIR}/test-1.txz