From 6e4ef8920d74180acd173561d5d2497fd92df5b3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 27 Dec 2006 22:47:46 +0000 Subject: [PATCH] add FileDelete function to spidermonkey takes 1 param, the path of the file to delete, using / as the path seperator, regardless of unix vs. windows. returns true is it was successfull, otherwise false git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3854 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_apr.h | 10 ++++++++++ .../languages/mod_spidermonkey/mod_spidermonkey.c | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/include/switch_apr.h b/src/include/switch_apr.h index 774f228bb4..98e8f2d820 100644 --- a/src/include/switch_apr.h +++ b/src/include/switch_apr.h @@ -192,6 +192,16 @@ DoxyDefine(apr_status_t switch_file_open(switch_file_t **newf, const char *fname DoxyDefine(apr_status_t switch_file_close(switch_file_t *file);) #define switch_file_close apr_file_close +/** + * Delete the specified file. + * @param path The full path to the file (using / on all systems) + * @param pool The pool to use. + * @remark If the file is open, it won't be removed until all + * instances are closed. + */ +DoxyDefine(apr_status_t apr_file_remove(const char *path, apr_pool_t *pool);) +#define switch_file_remove apr_file_remove + /** * Read data from the specified file. * @param thefile The file descriptor to read from. diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c index 1cf1c2f422..5b93ca170a 100644 --- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c +++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c @@ -2239,6 +2239,20 @@ static JSBool js_bridge(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j return JS_TRUE; } +static JSBool js_file_unlink(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + const char *path; + *rval = BOOLEAN_TO_JSVAL( JS_FALSE ); + if ( argc > 0 && (path = (const char *)JS_GetStringBytes(JS_ValueToString(cx, argv[0])))) { + if ((switch_file_remove(path, NULL)) == SWITCH_STATUS_SUCCESS) { + *rval = BOOLEAN_TO_JSVAL( JS_TRUE ); + } + return JS_TRUE; + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Arguements\n"); + return JS_FALSE; +} + static JSFunctionSpec fs_functions[] = { {"console_log", js_log, 2}, {"exit", js_exit, 0}, @@ -2246,6 +2260,7 @@ static JSFunctionSpec fs_functions[] = { {"bridge", js_bridge, 2}, {"apiExecute", js_api_execute, 2}, {"use", js_api_use, 1}, + {"FileDelete", js_file_unlink, 1}, #ifdef HAVE_CURL {"fetchURLHash", js_fetchurl_hash, 1}, {"fetchURLFile", js_fetchurl_file, 1},