src/utils.cpp
/**
 * Creates a list of directories as specified in the path.
 */
Creates a list of directories as specified in the path.
Creates a list of directories as specified in the path .
bool make_path(const std::string& path) {
    mode_t mode = 0755;
    int ret = mkdir(path.c_str(), mode);
    if (ret == 0) {
        return true;
    }
    switch (errno) {
    case ENOENT:
        {
            const auto pos = path.find_last_of('/');
            if (pos == std::string::npos) {
                return false;
            }
            if (!make_path( path.substr(0, pos) )) {
                return false;
            }
        }
        return 0 == mkdir(path.c_str(), mode);
    case EEXIST:
        return dir_exists(path);
    default:
        return false;
    }
    return true;
}
bool make_path ( const std :: string & path ) { mode_t mode = 0755 ; int ret = mkdir ( path . c_str ( ) , mode ) ; if ( ret == 0 ) { return true ; } switch ( errno ) { case ENOENT : { const auto pos = path . find_last_of ( ' ' ) ; if ( pos == std :: string :: npos ) { return false ; } if ( ! make_path ( path . substr ( 0 , pos ) ) ) { return false ; } } return 0 == mkdir ( path . c_str ( ) , mode ) ; case EEXIST : return dir_exists ( path ) ; default : return false ; } return true ; }
Creates a list of directories as specified in the path.
Creates a list of directories as specified in the path .
// parent didn't exist, try to create it // now, try to create again // done!