diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-06-18 11:12:08 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-06-18 11:13:03 -0300 |
commit | 61655d6dc2912424de937e2870b6a5ad346c3daf (patch) | |
tree | ebc5b80714281978ad071d2c288ac488d29f76a2 /core | |
parent | a7fc04626af238bf9a80c4f3b569e1c5d70465c9 (diff) |
Fixed make_dir and make_dir_recursive erros, closes #1680 closes #1872
Diffstat (limited to 'core')
-rw-r--r-- | core/io/file_access_memory.cpp | 6 | ||||
-rw-r--r-- | core/os/dir_access.cpp | 134 | ||||
-rw-r--r-- | core/os/dir_access.h | 2 |
3 files changed, 37 insertions, 105 deletions
diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index 7db3499505..11a425001e 100644 --- a/core/io/file_access_memory.cpp +++ b/core/io/file_access_memory.cpp @@ -46,7 +46,7 @@ void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) { name = Globals::get_singleton()->globalize_path(p_name); else name = p_name; - name = DirAccess::normalize_path(name); + //name = DirAccess::normalize_path(name); (*files)[name] = p_data; } @@ -68,7 +68,7 @@ FileAccess* FileAccessMemory::create() { bool FileAccessMemory::file_exists(const String& p_name) { String name = fix_path(p_name); - name = DirAccess::normalize_path(name); +// name = DirAccess::normalize_path(name); return files && (files->find(name) != NULL); } @@ -87,7 +87,7 @@ Error FileAccessMemory::_open(const String& p_path, int p_mode_flags) { ERR_FAIL_COND_V(!files, ERR_FILE_NOT_FOUND); String name = fix_path(p_path); - name = DirAccess::normalize_path(name); +// name = DirAccess::normalize_path(name); Map<String, Vector<uint8_t> >::Element* E = files->find(name); ERR_FAIL_COND_V(!E, ERR_FILE_NOT_FOUND); diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 9a7135913a..c2402183fd 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -143,118 +143,52 @@ Error DirAccess::make_dir_recursive(String p_dir) { }; String full_dir; - Globals* g = Globals::get_singleton(); - if (!p_dir.is_abs_path()) { - //append current + if (p_dir.is_rel_path()) { + //append current + full_dir=get_current_dir().plus_file(p_dir); - 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; + full_dir=p_dir; } - //int slices = full_dir.get_slice_count("/"); - - int pos = 0; - while (pos < full_dir.length()) { - - int n = full_dir.find("/", pos); - if (n < 0) { - n = full_dir.length(); - }; - pos = n + 1; - - if (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); - }; - }; - }; - - return OK; -}; - - -String DirAccess::normalize_path(const String &p_path) { - - static const int max_depth = 64; - int pos_stack[max_depth]; - int curr = 0; - - int pos = 0; - String cur_dir; - - do { + full_dir=full_dir.replace("\\","/"); - if (curr >= max_depth) { - - ERR_PRINT("Directory depth too deep."); - return ""; - }; - - int start = pos; - - int next = p_path.find("/", pos); - if (next < 0) { - next = p_path.length() - 1; - }; - - pos = next + 1; + //int slices = full_dir.get_slice_count("/"); - cur_dir = p_path.substr(start, next - start); + String base; - if (cur_dir == "" || cur_dir == ".") { - continue; - }; - if (cur_dir == "..") { + if (full_dir.begins_with("res://")) + base="res://"; + else if (full_dir.begins_with("user://")) + base="user://"; + else if (full_dir.begins_with("/")) + base="/"; + else if (full_dir.find(":/")!=-1) { + base=full_dir.substr(0,full_dir.find(":/")+2); + } else { + ERR_FAIL_V(ERR_INVALID_PARAMETER); + } - if (curr > 0) { // pop a dir - curr -= 2; - }; - continue; - }; + full_dir=full_dir.replace_first(base,"").simplify_path(); - pos_stack[curr++] = start; - pos_stack[curr++] = next; + Vector<String> subdirs=full_dir.split("/"); - } while (pos < p_path.length()); + String curpath=base; + for(int i=0;i<subdirs.size();i++) { - String path; - if (p_path[0] == '/') { - path = "/"; - }; + curpath=curpath.plus_file(subdirs[i]); + Error err = make_dir(curpath); + if (err != OK && err != ERR_ALREADY_EXISTS) { - int i=0; - while (i < curr) { - - int start = pos_stack[i++]; + ERR_FAIL_V(err); + } + } - while ( ((i+1)<curr) && (pos_stack[i] == pos_stack[i+1]) ) { + return OK; +} - ++i; - }; - path = path + p_path.substr(start, (pos_stack[i++] - start) + 1); - }; - return path; -}; String DirAccess::get_next(bool* p_is_dir) { @@ -276,9 +210,9 @@ String DirAccess::fix_path(String p_path) const { String resource_path = Globals::get_singleton()->get_resource_path(); if (resource_path != "") { - return p_path.replace("res:/",resource_path); + return p_path.replace_first("res:/",resource_path); }; - return p_path.replace("res://", ""); + return p_path.replace_first("res://", ""); } } @@ -292,9 +226,9 @@ String DirAccess::fix_path(String p_path) const { String data_dir=OS::get_singleton()->get_data_dir(); if (data_dir != "") { - return p_path.replace("user:/",data_dir); + return p_path.replace_first("user:/",data_dir); }; - return p_path.replace("user://", ""); + return p_path.replace_first("user://", ""); } } break; diff --git a/core/os/dir_access.h b/core/os/dir_access.h index 7a850ddc6d..83288b7c91 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -72,8 +72,6 @@ protected: public: - static String normalize_path(const String& p_path); - virtual bool list_dir_begin()=0; ///< This starts dir listing virtual String get_next(bool* p_is_dir); // compatibility virtual String get_next()=0; |