diff --git a/src/mod_cml_funcs.c b/src/mod_cml_funcs.c index 34c74d1d..c3e251bb 100644 --- a/src/mod_cml_funcs.c +++ b/src/mod_cml_funcs.c @@ -162,6 +162,31 @@ int f_file_isreg(lua_State *L) { return 1; } +int f_file_isdir(lua_State *L) { + struct stat st; + int n = lua_gettop(L); + + if (n != 1) { + lua_pushstring(L, "file_isreg: expected one argument"); + lua_error(L); + } + + if (!lua_isstring(L, 1)) { + lua_pushstring(L, "file_isreg: argument has to be a string"); + lua_error(L); + } + + if (-1 == stat(lua_tostring(L, 1), &st)) { + lua_pushnil(L); + return 1; + } + + lua_pushnumber(L, S_ISDIR(st.st_mode)); + + return 1; +} + + #ifdef HAVE_MEMCACHE_H int f_memcache_exists(lua_State *L) { diff --git a/src/mod_cml_funcs.h b/src/mod_cml_funcs.h index f53557c0..fafe70d0 100644 --- a/src/mod_cml_funcs.h +++ b/src/mod_cml_funcs.h @@ -9,6 +9,7 @@ int f_crypto_md5(lua_State *L); int f_file_mtime(lua_State *L); int f_file_isreg(lua_State *L); +int f_file_isdir(lua_State *L); int f_dir_files(lua_State *L); int f_memcache_exists(lua_State *L); diff --git a/src/mod_cml_lua.c b/src/mod_cml_lua.c index fe6cbeff..b0cbeb6c 100644 --- a/src/mod_cml_lua.c +++ b/src/mod_cml_lua.c @@ -166,6 +166,7 @@ int cache_parse_lua(server *srv, connection *con, plugin_data *p, buffer *fn) { lua_register(L, "md5", f_crypto_md5); lua_register(L, "file_mtime", f_file_mtime); lua_register(L, "file_isreg", f_file_isreg); + lua_register(L, "file_isdir", f_file_isreg); lua_register(L, "dir_files", f_dir_files); #ifdef HAVE_MEMCACHE_H