From c4b78a49c764ee7941cba3be6986ec6e461d764a Mon Sep 17 00:00:00 2001 From: Marc Olivier Chouinard Date: Tue, 3 May 2011 17:27:21 -0400 Subject: [PATCH] record_session: Will auto create recursive destination folder if it doesn't already exist (Doesn't create folder when used with local cache feature) --- src/switch_ivr_async.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 016fee7246..ed69799d26 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -1443,6 +1443,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t struct record_helper *rh = NULL; int file_flags = SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT; switch_bool_t hangup_on_error = SWITCH_FALSE; + char *file_path = NULL; if ((p = switch_channel_get_variable(channel, "RECORD_HANGUP_ON_ERROR"))) { hangup_on_error = switch_true(p); @@ -1534,9 +1535,30 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t } else { tfile = NULL; } + } else { + file_path = switch_core_session_sprintf(session, "%s%s%s", prefix, SWITCH_PATH_SEPARATOR, file); } file = switch_core_session_sprintf(session, "%s%s%s%s%s", switch_str_nil(tfile), tfile ? "]" : "", prefix, SWITCH_PATH_SEPARATOR, file); + } else { + file_path = switch_core_session_strdup(session, file); + } + + if (file_path) { + char *p; + char *path = switch_core_session_strdup(session, file_path); + + if ((p = strrchr(path, *SWITCH_PATH_SEPARATOR))) { + *p = '\0'; + if (switch_dir_make_recursive(path, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error creating %s\n", path); + return SWITCH_STATUS_GENERR; + } + + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error finding the folder path section in '%s'\n", path); + path = NULL; + } } if (switch_core_file_open(fh, file, channels, read_impl.actual_samples_per_second, file_flags, NULL) != SWITCH_STATUS_SUCCESS) {