1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-05 16:55:50 +03:00

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
This commit is contained in:
Guenter Knauf
2013-06-01 07:47:29 +00:00
parent 49082c9492
commit 069bd372bc

View File

@@ -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 {