summaryrefslogtreecommitdiff
path: root/core/os/dir_access.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/os/dir_access.cpp')
-rw-r--r--core/os/dir_access.cpp45
1 files changed, 28 insertions, 17 deletions
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index 496ebdfa27..3ab4d4bb7f 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -130,35 +130,46 @@ Error DirAccess::make_dir_recursive(String p_dir) {
if (p_dir.length() < 1) {
return OK;
};
+
+ String full_dir;
Globals* g = Globals::get_singleton();
- String cur = normalize_path(g->globalize_path(get_current_dir()));
- if (cur[cur.length()-1] != '/') {
- cur = cur + "/";
- };
- String dir = normalize_path(g->globalize_path(p_dir));
- if (dir.length() < 1) {
- return OK;
- };
- if (dir[dir.length()-1] != '/') {
- dir = dir + "/";
- };
+ if (!p_dir.is_abs_path()) {
+ //append current
- ERR_FAIL_COND_V(dir.find(cur) != 0, FAILED);
+ String cur = normalize_path(g->globalize_path(get_current_dir()));
+ if (cur[cur.length()-1] != '/') {
+ cur = cur + "/";
+ };
+
+ full_dir=(cur+"/"+p_dir).simplify_path();
+ } else {
+ //validate and use given
+ String dir = normalize_path(g->globalize_path(p_dir));
+ if (dir.length() < 1) {
+ return OK;
+ };
+ if (dir[dir.length()-1] != '/') {
+ dir = dir + "/";
+ };
+ full_dir=dir;
+ }
- String rel = dir.substr(cur.length(), (dir.length() - cur.length()));
+ int slices = full_dir.get_slice_count("/");
int pos = 0;
- while (pos < rel.length()) {
+ while (pos < full_dir.length()) {
- int n = rel.find("/", pos);
+ int n = full_dir.find("/", pos);
if (n < 0) {
- n = rel.length();
+ n = full_dir.length();
};
pos = n + 1;
if (pos > 1) {
- Error err = make_dir(rel.substr(0, pos -1));
+ String to_create = full_dir.substr(0, pos -1);
+ //print_line("MKDIR: "+to_create);
+ Error err = make_dir(to_create);
if (err != OK && err != ERR_ALREADY_EXISTS) {
ERR_FAIL_V(err);