httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fua...@apache.org
Subject svn commit: r1488480 - /httpd/httpd/trunk/modules/lua/lua_request.c
Date Sat, 01 Jun 2013 07:47:29 GMT
Author: fuankg
Date: Sat Jun  1 07:47:29 2013
New Revision: 1488480

URL: http://svn.apache.org/r1488480
Log:
Added optional parameter wanted to r:stat().

Modified:
    httpd/httpd/trunk/modules/lua/lua_request.c

Modified: httpd/httpd/trunk/modules/lua/lua_request.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_request.c?rev=1488480&r1=1488479&r2=1488480&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_request.c (original)
+++ httpd/httpd/trunk/modules/lua/lua_request.c Sat Jun  1 07:47:29 2013
@@ -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 {



Mime
View raw message