mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix #179: dvr support custom filepath by variables. 2.0.87
This commit is contained in:
parent
f89941254a
commit
f881bc43b5
10 changed files with 215 additions and 27 deletions
|
@ -32,10 +32,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include <srs_kernel_log.hpp>
|
||||
#include <srs_kernel_error.hpp>
|
||||
|
||||
// this value must:
|
||||
// equals to (SRS_SYS_CYCLE_INTERVAL*SRS_SYS_TIME_RESOLUTION_MS_TIMES)*1000
|
||||
|
@ -222,3 +225,56 @@ bool srs_string_ends_with(string str, string flag)
|
|||
return str.rfind(flag) == str.length() - flag.length();
|
||||
}
|
||||
|
||||
int __srs_create_dir_recursively(string dir)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
struct stat st;
|
||||
|
||||
// stat current dir, if exists, return error.
|
||||
if (stat(dir.c_str(), &st) == 0) {
|
||||
return ERROR_SYSTEM_DIR_EXISTS;
|
||||
}
|
||||
|
||||
// create parent first.
|
||||
size_t pos;
|
||||
if ((pos = dir.rfind("/")) != std::string::npos) {
|
||||
std::string parent = dir.substr(0, pos);
|
||||
ret = __srs_create_dir_recursively(parent);
|
||||
// return for error.
|
||||
if (ret != ERROR_SUCCESS && ret != ERROR_SYSTEM_DIR_EXISTS) {
|
||||
return ret;
|
||||
}
|
||||
// parent exists, set to ok.
|
||||
ret = ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
// create curren dir.
|
||||
mode_t mode = S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IXOTH;
|
||||
if (::mkdir(dir.c_str(), mode) < 0) {
|
||||
if (errno == EEXIST) {
|
||||
return ERROR_SYSTEM_DIR_EXISTS;
|
||||
}
|
||||
|
||||
ret = ERROR_SYSTEM_CREATE_DIR;
|
||||
srs_error("create dir %s failed. ret=%d", dir.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
srs_info("create dir %s success.", dir.c_str());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int srs_create_dir_recursively(string dir)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
ret = __srs_create_dir_recursively(dir);
|
||||
|
||||
if (ret == ERROR_SYSTEM_DIR_EXISTS) {
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue