*/
SWITCH_DECLARE(switch_status_t) switch_file_write(switch_file_t * thefile, const void *buf, switch_size_t *nbytes);
-SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename);
+SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename, switch_memory_pool_t *pool);
/** @} */
path = switch_mprintf("%s%smwi.js", SWITCH_GLOBAL_dirs.script_dir, SWITCH_PATH_SEPARATOR);
assert(path != NULL);
- if (switch_file_exists(path) == SWITCH_STATUS_SUCCESS) {
+ if (switch_file_exists(path, NULL) == SWITCH_STATUS_SUCCESS) {
cmd = switch_mprintf("%s %s", path, account);
assert(cmd != NULL);
js_thread_launch(cmd);
script_name = path;
}
if (script_name) {
- if (switch_file_exists(script_name) == SWITCH_STATUS_SUCCESS) {
+ if (switch_file_exists(script_name, NULL) == SWITCH_STATUS_SUCCESS) {
script = JS_CompileFile(cx, obj, script_name);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Open File: %s\n", script_name);
return apr_file_write(thefile, buf, nbytes);
}
-SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename)
+SWITCH_DECLARE(switch_status_t) switch_file_exists(const char *filename, switch_memory_pool_t *pool)
{
int32_t wanted = APR_FINFO_TYPE;
+ switch_memory_pool_t *our_pool = NULL;
+ switch_status_t status = SWITCH_STATUS_FALSE;
apr_finfo_t info = { 0 };
+
+ if (!pool) {
+ if ((apr_pool_create(&our_pool, NULL)) != SWITCH_STATUS_SUCCESS) {
+ return SWITCH_STATUS_MEMERR;
+ }
+ }
+
if (filename) {
- apr_stat(&info, filename, wanted, NULL);
+ apr_stat(&info, filename, wanted, pool ? pool : our_pool);
if (info.filetype != APR_NOFILE) {
- return SWITCH_STATUS_SUCCESS;
+ status = SWITCH_STATUS_SUCCESS;
}
}
- return SWITCH_STATUS_FALSE;
+
+ if (our_pool) {
+ apr_pool_destroy(our_pool);
+ }
+
+ return status;
}
/* thread stubs */