summaryrefslogtreecommitdiff
path: root/drivers/unix
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-08-17 11:50:21 +0200
committerGitHub <noreply@github.com>2017-08-17 11:50:21 +0200
commit22d21ebef0b28ee519f5806c092ca5cfcd0cea4e (patch)
tree6b8d484518cc15af26e1045275e18bc14990c393 /drivers/unix
parente2c1792d06ab751a033a1e83802875dd4a2f95de (diff)
parentd3b7d42784a3dcefe4dd09f4fd771cbf710af9c6 (diff)
Merge pull request #8144 from supagu/symlink
Reworked change_dir to support symlinks
Diffstat (limited to 'drivers/unix')
-rw-r--r--drivers/unix/dir_access_unix.cpp45
1 files changed, 23 insertions, 22 deletions
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp
index cf54f3fea0..a183a37446 100644
--- a/drivers/unix/dir_access_unix.cpp
+++ b/drivers/unix/dir_access_unix.cpp
@@ -223,36 +223,37 @@ Error DirAccessUnix::make_dir(String p_dir) {
Error DirAccessUnix::change_dir(String p_dir) {
GLOBAL_LOCK_FUNCTION
- p_dir = fix_path(p_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?
+ // make sure current_dir is valid absolute path
+ if (current_dir == "." || current_dir == "") {
+ char real_current_dir_name[2048];
+ getcwd(real_current_dir_name, 2048);
+ current_dir.parse_utf8(real_current_dir_name);
+ }
- 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
+ if (p_dir == ".") {
+ return OK;
+ }
- String base = _get_root_path();
- if (base != "") {
+ p_dir = fix_path(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;
- }
+ String prev_dir = current_dir;
- if (worked) {
+ if (p_dir.is_rel_path()) {
+ String next_dir = current_dir + "/" + p_dir;
+ next_dir = next_dir.simplify_path();
+ current_dir = next_dir;
+ } else {
+ current_dir = p_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(current_dir.utf8().get_data()) == 0); // we can only give this utf8
+ if (!worked) {
+ current_dir = prev_dir;
+ return ERR_INVALID_PARAMETER;
}
- chdir(prev_dir.utf8().get_data());
- return worked ? OK : ERR_INVALID_PARAMETER;
+ return OK;
}
String DirAccessUnix::get_current_dir() {