Update redbean ProgramDirectory to raise Lua error for easier handling

This commit is contained in:
Paul Kulchenko 2023-07-25 19:14:50 -07:00
parent 3359af9fc9
commit b25a7770f8

View file

@ -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);
}