From b25a7770f80b7d3bcfd16cd389cc2964055dbb8e Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Tue, 25 Jul 2023 19:14:50 -0700 Subject: [PATCH] Update redbean ProgramDirectory to raise Lua error for easier handling --- tool/net/redbean.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tool/net/redbean.c b/tool/net/redbean.c index d30d6c35b..49f9e3a22 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -4584,6 +4584,12 @@ static int LuaProgramBrand(lua_State *L) { } static int LuaProgramDirectory(lua_State *L) { + struct stat st; + char *path = luaL_checkstring(L, 1); + // check to raise a Lua error, to allow it to be handled + if (stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) { + return luaL_argerror(L, 1, "not a directory"); + } return LuaProgramString(L, ProgramDirectory); }