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.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp
index a5a9258c4a..bea249d4b6 100644
--- a/drivers/unix/dir_access_unix.cpp
+++ b/drivers/unix/dir_access_unix.cpp
@@ -309,7 +309,7 @@ Error DirAccessUnix::change_dir(String 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);
+ ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == NULL, ERR_BUG);
if (prev_dir.parse_utf8(real_current_dir_name))
prev_dir = real_current_dir_name; //no utf8, maybe latin?
@@ -328,9 +328,20 @@ Error DirAccessUnix::change_dir(String p_dir) {
return ERR_INVALID_PARAMETER;
}
+ String base = _get_root_path();
+ if (base != String() && !try_dir.begins_with(base)) {
+ ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == NULL, ERR_BUG);
+ String new_dir;
+ new_dir.parse_utf8(real_current_dir_name);
+
+ if (!new_dir.begins_with(base)) {
+ try_dir = current_dir; //revert
+ }
+ }
+
// the directory exists, so set current_dir to try_dir
current_dir = try_dir;
- chdir(prev_dir.utf8().get_data());
+ ERR_FAIL_COND_V(chdir(prev_dir.utf8().get_data()) != 0, ERR_BUG);
return OK;
}
@@ -391,7 +402,7 @@ size_t DirAccessUnix::get_space_left() {
return vfs.f_bfree * vfs.f_bsize;
#else
-#warning THIS IS BROKEN
+ // FIXME: Implement this.
return 0;
#endif
};
@@ -405,7 +416,7 @@ DirAccessUnix::DirAccessUnix() {
// set current directory to an absolute path of the current directory
char real_current_dir_name[2048];
- getcwd(real_current_dir_name, 2048);
+ ERR_FAIL_COND(getcwd(real_current_dir_name, 2048) == NULL);
if (current_dir.parse_utf8(real_current_dir_name))
current_dir = real_current_dir_name;