bug fix for directory creation when the input is an empty string

This commit is contained in:
tangxifan 2020-06-25 10:34:34 -06:00
parent e2d3ac78ec
commit b36da17a08
1 changed files with 9 additions and 4 deletions

View File

@ -58,6 +58,11 @@ std::string format_dir_path(const std::string& dir_path_to_format) {
char legal_back_slash = '\\'; char legal_back_slash = '\\';
#endif #endif
/* Return an empty string if the input is empty */
if (true == formatted_dir_path.empty()) {
return formatted_dir_path;
}
/* Replace "\" with "/" */ /* Replace "\" with "/" */
std::replace(formatted_dir_path.begin(), formatted_dir_path.end(), illegal_back_slash, legal_back_slash); std::replace(formatted_dir_path.begin(), formatted_dir_path.end(), illegal_back_slash, legal_back_slash);
@ -123,8 +128,8 @@ bool create_dir_path(const std::string& dir_path,
const bool& verbose) { const bool& verbose) {
/* Give up if the path is empty */ /* Give up if the path is empty */
if (true == dir_path.empty()) { if (true == dir_path.empty()) {
VTR_LOG_ERROR("Directory path is empty and nothing will be created.\n"); VTR_LOG_WARN("Directory path is empty and nothing will be created.\n");
return false; return true;
} }
/* Try to create a directory */ /* Try to create a directory */
@ -170,8 +175,8 @@ static
bool rec_create_dir_path(const std::string& dir_path) { bool rec_create_dir_path(const std::string& dir_path) {
/* Give up if the path is empty */ /* Give up if the path is empty */
if (true == dir_path.empty()) { if (true == dir_path.empty()) {
VTR_LOG_ERROR("Directory path is empty and nothing will be created.\n"); VTR_LOG_WARN("Directory path is empty and nothing will be created.\n");
return false; return true;
} }
/* Try to find the positions of all the slashes /* Try to find the positions of all the slashes