From: Guenter Knauf Date: Sat, 1 Jun 2013 07:47:29 +0000 (+0000) Subject: Added optional parameter wanted to r:stat(). X-Git-Tag: 2.5.0-alpha~5392 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=069bd372bc3f3eaba1afff6f23fc341db33b9855;p=apache Added optional parameter wanted to r:stat(). git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1488480 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/lua/lua_request.c b/modules/lua/lua_request.c index ad87d6526c..a52888b406 100644 --- a/modules/lua/lua_request.c +++ b/modules/lua/lua_request.c @@ -1243,42 +1243,53 @@ static int lua_ap_getdir(lua_State *L) } /* - * lua_ap_stat; r:stat(filename) - Runs stat on a file and returns the file - * info as a table + * lua_ap_stat; r:stat(filename [, wanted]) - Runs stat on a file and + * returns the file info as a table */ static int lua_ap_stat(lua_State *L) { request_rec *r; const char *filename; apr_finfo_t file_info; + apr_int32_t wanted; luaL_checktype(L, 1, LUA_TUSERDATA); luaL_checktype(L, 2, LUA_TSTRING); r = ap_lua_check_request_rec(L, 1); filename = lua_tostring(L, 2); - if (apr_stat(&file_info, filename, APR_FINFO_MIN, r->pool) == OK) { + wanted = luaL_optinteger(L, 3, APR_FINFO_MIN); + if (apr_stat(&file_info, filename, wanted, r->pool) == OK) { lua_newtable(L); - - lua_pushstring(L, "mtime"); - lua_pushnumber(L, (lua_Number) file_info.mtime); - lua_settable(L, -3); - - lua_pushstring(L, "atime"); - lua_pushnumber(L, (lua_Number) file_info.atime); - lua_settable(L, -3); - - lua_pushstring(L, "ctime"); - lua_pushnumber(L, (lua_Number) file_info.ctime); - lua_settable(L, -3); - - lua_pushstring(L, "size"); - lua_pushnumber(L, (lua_Number) file_info.size); - lua_settable(L, -3); - - lua_pushstring(L, "filetype"); - lua_pushinteger(L, file_info.filetype); - lua_settable(L, -3); - + if (wanted & APR_FINFO_MTIME) { + lua_pushstring(L, "mtime"); + lua_pushnumber(L, (lua_Number) file_info.mtime); + lua_settable(L, -3); + } + if (wanted & APR_FINFO_ATIME) { + lua_pushstring(L, "atime"); + lua_pushnumber(L, (lua_Number) file_info.atime); + lua_settable(L, -3); + } + if (wanted & APR_FINFO_CTIME) { + lua_pushstring(L, "ctime"); + lua_pushnumber(L, (lua_Number) file_info.ctime); + lua_settable(L, -3); + } + if (wanted & APR_FINFO_SIZE) { + lua_pushstring(L, "size"); + lua_pushnumber(L, (lua_Number) file_info.size); + lua_settable(L, -3); + } + if (wanted & APR_FINFO_TYPE) { + lua_pushstring(L, "filetype"); + lua_pushinteger(L, file_info.filetype); + lua_settable(L, -3); + } + if (wanted & APR_FINFO_PROT) { + lua_pushstring(L, "protection"); + lua_pushinteger(L, file_info.protection); + lua_settable(L, -3); + } return 1; } else {