summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openrecoveryscript.cpp4
-rw-r--r--twrp-functions.cpp23
2 files changed, 10 insertions, 17 deletions
diff --git a/openrecoveryscript.cpp b/openrecoveryscript.cpp
index 30c03b160..eee64ff89 100644
--- a/openrecoveryscript.cpp
+++ b/openrecoveryscript.cpp
@@ -323,8 +323,8 @@ int OpenRecoveryScript::run_script_file(void) {
// Make directory (recursive)
DataManager::SetValue("tw_action_text2", gui_parse_text("{@making_dir1}"));
gui_msg(Msg("making_dir2=Making directory: '{1}'")(value));
- if (TWFunc::Recursive_Mkdir(value)) {
- gui_msg(Msg(msg::kError, "create_folder_strerr=Can not create '{1}' folder ({2}).")(value)(strerror(errno)));
+ if (!TWFunc::Recursive_Mkdir(value)) {
+ // error message already displayed by Recursive_Mkdir
ret_val = 1;
}
} else if (strcmp(command, "reboot") == 0) {
diff --git a/twrp-functions.cpp b/twrp-functions.cpp
index a7a8e8d63..6eb6cd59d 100644
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -403,26 +403,19 @@ void TWFunc::htc_dumlock_reflash_recovery_to_boot(void) {
}
int TWFunc::Recursive_Mkdir(string Path) {
- string pathCpy = Path;
- string wholePath;
- size_t pos = pathCpy.find("/", 2);
-
- while (pos != string::npos)
- {
- wholePath = pathCpy.substr(0, pos);
- if (!TWFunc::Path_Exists(wholePath)) {
- if (mkdir(wholePath.c_str(), 0777)) {
- gui_msg(Msg(msg::kError, "create_folder_strerr=Can not create '{1}' folder ({2})")(wholePath)(strerror(errno)));
+ std::vector<std::string> parts = Split_String(Path, "/", true);
+ std::string cur_path;
+ for (size_t i = 0; i < parts.size(); ++i) {
+ cur_path += "/" + parts[i];
+ if (!TWFunc::Path_Exists(cur_path)) {
+ if (mkdir(cur_path.c_str(), 0777)) {
+ gui_msg(Msg(msg::kError, "create_folder_strerr=Can not create '{1}' folder ({2})")(cur_path)(strerror(errno)));
return false;
} else {
- tw_set_default_metadata(wholePath.c_str());
+ tw_set_default_metadata(cur_path.c_str());
}
}
-
- pos = pathCpy.find("/", pos + 1);
}
- if (mkdir(wholePath.c_str(), 0777) && errno != EEXIST)
- return false;
return true;
}