From: Guenter Knauf Date: Tue, 25 Jun 2013 14:19:51 +0000 (+0000) Subject: Added new r:touch() function; updated docs. X-Git-Tag: 2.4.5~71 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f0c944f49a07b027c42ca267d93a6a5b057efcec;p=apache Added new r:touch() function; updated docs. (Backport r1495270, r1495665, r1495666) git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1496483 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index b1d3212c78..4aa95c2627 100644 --- a/CHANGES +++ b/CHANGES @@ -25,8 +25,8 @@ Changes with Apache 2.4.5 *) mod_remoteip: close file in error path. [Christophe Jaillet] - *) mod_lua: Add some new functions: r:htpassword(), r:mkdir(), r:rmdir(), - r:get_direntries(), r.date_parse_rfc(). + *) mod_lua: Add some new functions: r:htpassword(), r:mkdir(), r:mkrdir(), + r:rmdir(), r:touch(), r:get_direntries(), r.date_parse_rfc(). [Guenter Knauf] *) mod_lua: Sync 2.4 branch with trunk. This includes (but is not limited to) diff --git a/docs/manual/mod/mod_lua.xml b/docs/manual/mod/mod_lua.xml index a1f4584d8b..5bbe7a76ba 100644 --- a/docs/manual/mod/mod_lua.xml +++ b/docs/manual/mod/mod_lua.xml @@ -935,10 +935,18 @@ r:htpassword(string [,algorithm [,cost]]) -- Creates a password hash from a stri r:mkdir(dir [,mode]) -- Creates a directory and sets mode to optional mode paramter. + +r:mkrdir(dir [,mode]) -- Creates directories recursive and sets mode to optional mode paramter. + + r:rmdir(dir) -- Removes a directory. + +r:touch([mtime]) -- Sets the file modification time to current time or to optional mtime msec value. + + r:get_direntries(dir) -- Returns a table with all directory entries. diff --git a/modules/lua/lua_request.c b/modules/lua/lua_request.c index 66cbb1ca4e..c2cfb53548 100644 --- a/modules/lua/lua_request.c +++ b/modules/lua/lua_request.c @@ -871,6 +871,25 @@ static int lua_apr_htpassword(lua_State *L) return 1; } +/* + * lua_apr_touch; r:touch(string [, time]) - Sets mtime of a file + */ +static int lua_apr_touch(lua_State *L) +{ + request_rec *r; + const char *path; + apr_status_t status; + apr_time_t mtime; + + r = ap_lua_check_request_rec(L, 1); + luaL_checktype(L, 2, LUA_TSTRING); + path = lua_tostring(L, 2); + mtime = luaL_optnumber(L, 3, apr_time_now()); + status = apr_file_mtime_set(path, mtime, r->pool); + lua_pushboolean(L, (status == 0)); + return 1; +} + /* * lua_apr_mkdir; r:mkdir(string [, permissions]) - Creates a directory */ @@ -2153,6 +2172,8 @@ void ap_lua_load_request_lmodule(lua_State *L, apr_pool_t *p) makefun(&lua_apr_sha1, APL_REQ_FUNTYPE_LUACFUN, p)); apr_hash_set(dispatch, "htpassword", APR_HASH_KEY_STRING, makefun(&lua_apr_htpassword, APL_REQ_FUNTYPE_LUACFUN, p)); + apr_hash_set(dispatch, "touch", APR_HASH_KEY_STRING, + makefun(&lua_apr_touch, APL_REQ_FUNTYPE_LUACFUN, p)); apr_hash_set(dispatch, "mkdir", APR_HASH_KEY_STRING, makefun(&lua_apr_mkdir, APL_REQ_FUNTYPE_LUACFUN, p)); apr_hash_set(dispatch, "mkrdir", APR_HASH_KEY_STRING,