summaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-25 12:25:06 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-25 12:25:06 +0100
commit9fbd7d24781c4286b34c1d640e5cd93020e70d28 (patch)
tree2c36967a9b2b7a31f2b71eb5fcbe449cd02635a6 /src/lua
parenteedb359726e0d99265969451261fdb8494e462f2 (diff)
downloadrspamd-9fbd7d24781c4286b34c1d640e5cd93020e70d28.tar.gz
rspamd-9fbd7d24781c4286b34c1d640e5cd93020e70d28.zip
[Feature] Add util.unlink function
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_util.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index 3837e423a..52edb714f 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -252,6 +252,15 @@ LUA_FUNCTION_DEF (util, get_ticks);
*/
LUA_FUNCTION_DEF (util, stat);
+/***
+ * @function util.unlink(fname)
+ * Removes the specified file from the filesystem
+ *
+ * @param {string} fname filename to remove
+ * @return {boolean,[string]} true if file has been deleted or false,'error string'
+ */
+LUA_FUNCTION_DEF (util, unlink);
+
static const struct luaL_reg utillib_f[] = {
LUA_INTERFACE_DEF (util, create_event_base),
LUA_INTERFACE_DEF (util, load_rspamd_config),
@@ -278,6 +287,7 @@ static const struct luaL_reg utillib_f[] = {
LUA_INTERFACE_DEF (util, strequal_caseless),
LUA_INTERFACE_DEF (util, get_ticks),
LUA_INTERFACE_DEF (util, stat),
+ LUA_INTERFACE_DEF (util, unlink),
{NULL, NULL}
};
@@ -1143,6 +1153,33 @@ lua_util_stat (lua_State *L)
}
static gint
+lua_util_unlink (lua_State *L)
+{
+ const gchar *fpath;
+ gint ret;
+
+ fpath = luaL_checkstring (L, 1);
+
+ if (fpath) {
+ ret = unlink (fpath);
+
+ if (ret == -1) {
+ lua_pushboolean (L, false);
+ lua_pushstring (L, strerror (errno));
+
+ return 2;
+ }
+
+ lua_pushboolean (L, true);
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 1;
+}
+
+static gint
lua_load_util (lua_State * L)
{
lua_newtable (L);