diff options
author | Chris Bradfield <chris@kidscancode.org> | 2017-09-09 20:10:28 -0700 |
---|---|---|
committer | Chris Bradfield <chris@kidscancode.org> | 2017-09-09 20:10:28 -0700 |
commit | 134e24408a3ae6273da5998ee257495eff79eb1a (patch) | |
tree | 566c3d82ed1925a3d6dcd34c6cb1687328af7f6e /drivers/unix/dir_access_unix.cpp | |
parent | f66e9158a8a49d1fb88cd31975a2a492b3aa1d6e (diff) | |
parent | d1cb73b47a17de830d9474026ffa7b3587cfbc68 (diff) |
Merge branch 'master' of git://github.com/godotengine/godot into kcc_lightoccluder2d_doc
Diffstat (limited to 'drivers/unix/dir_access_unix.cpp')
-rw-r--r-- | drivers/unix/dir_access_unix.cpp | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index ddc3b2ed33..b85a63a44a 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -211,36 +211,48 @@ Error DirAccessUnix::make_dir(String p_dir) { Error DirAccessUnix::change_dir(String p_dir) { GLOBAL_LOCK_FUNCTION + p_dir = fix_path(p_dir); + // prev_dir is the directory we are changing out of + String prev_dir; char real_current_dir_name[2048]; getcwd(real_current_dir_name, 2048); - String prev_dir; if (prev_dir.parse_utf8(real_current_dir_name)) prev_dir = real_current_dir_name; //no utf8, maybe latin? - chdir(current_dir.utf8().get_data()); //ascii since this may be unicode or wathever the host os wants - bool worked = (chdir(p_dir.utf8().get_data()) == 0); // we can only give this utf8 + //print_line("directory we are changing out of (prev_dir): " + prev_dir); - String base = _get_root_path(); - if (base != "") { + // try_dir is the directory we are trying to change into + String try_dir = ""; + if (p_dir.is_rel_path()) { + String next_dir = current_dir + "/" + p_dir; + //print_line("p_dir is relative: " + p_dir + " about to simplfy: " + next_dir); + next_dir = next_dir.simplify_path(); + try_dir = next_dir; + } else { + try_dir = p_dir; + //print_line("p_dir is absolute: " + p_dir); + } - getcwd(real_current_dir_name, 2048); - String new_dir; - new_dir.parse_utf8(real_current_dir_name); - if (!new_dir.begins_with(base)) - worked = false; + // if try_dir is nothing, it is not changing directory so change it to a "." otherwise chdir will fail + if (try_dir == "") { + try_dir = "."; } - if (worked) { + //print_line("directory we are changing in to (try_dir): " + try_dir); - getcwd(real_current_dir_name, 2048); - if (current_dir.parse_utf8(real_current_dir_name)) - current_dir = real_current_dir_name; //no utf8, maybe latin? + bool worked = (chdir(try_dir.utf8().get_data()) == 0); // we can only give this utf8 + if (!worked) { + //print_line("directory does not exist"); + return ERR_INVALID_PARAMETER; } + // the directory exists, so set current_dir to try_dir + current_dir = try_dir; chdir(prev_dir.utf8().get_data()); - return worked ? OK : ERR_INVALID_PARAMETER; + //print_line("directory exists, setting current_dir to: " + current_dir); + return OK; } String DirAccessUnix::get_current_dir() { |