summaryrefslogtreecommitdiff
path: root/drivers/unix/dir_access_unix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/unix/dir_access_unix.cpp')
-rw-r--r--drivers/unix/dir_access_unix.cpp42
1 files changed, 23 insertions, 19 deletions
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp
index ddc3b2ed33..6b8038c3ef 100644
--- a/drivers/unix/dir_access_unix.cpp
+++ b/drivers/unix/dir_access_unix.cpp
@@ -211,36 +211,35 @@ 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
-
- String base = _get_root_path();
- if (base != "") {
-
- 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;
+ // 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;
+ next_dir = next_dir.simplify_path();
+ try_dir = next_dir;
+ } else {
+ try_dir = p_dir;
}
- if (worked) {
-
- 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) {
+ 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;
+ return OK;
}
String DirAccessUnix::get_current_dir() {
@@ -307,11 +306,16 @@ size_t DirAccessUnix::get_space_left() {
DirAccessUnix::DirAccessUnix() {
dir_stream = 0;
- current_dir = ".";
_cisdir = false;
/* determine drive count */
+ // set current directory to an absolute path of the current directory
+ char real_current_dir_name[2048];
+ getcwd(real_current_dir_name, 2048);
+ if (current_dir.parse_utf8(real_current_dir_name))
+ current_dir = real_current_dir_name;
+
change_dir(current_dir);
}