summaryrefslogtreecommitdiffstats
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.cpp33
1 files changed, 29 insertions, 4 deletions
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp
index 46efb45934..816ffd7a32 100644
--- a/drivers/unix/dir_access_unix.cpp
+++ b/drivers/unix/dir_access_unix.cpp
@@ -289,7 +289,7 @@ String DirAccessUnix::get_drive(int p_drive) {
ERR_FAIL_INDEX_V(p_drive, list.size(), "");
- return list[p_drive];
+ return list.get(p_drive);
}
int DirAccessUnix::get_current_drive() {
@@ -397,14 +397,30 @@ Error DirAccessUnix::rename(String p_path, String p_new_path) {
}
p_path = fix_path(p_path);
+ if (p_path.ends_with("/")) {
+ p_path = p_path.left(-1);
+ }
if (p_new_path.is_relative_path()) {
p_new_path = get_current_dir().path_join(p_new_path);
}
p_new_path = fix_path(p_new_path);
+ if (p_new_path.ends_with("/")) {
+ p_new_path = p_new_path.left(-1);
+ }
- return ::rename(p_path.utf8().get_data(), p_new_path.utf8().get_data()) == 0 ? OK : FAILED;
+ int res = ::rename(p_path.utf8().get_data(), p_new_path.utf8().get_data());
+ if (res != 0 && errno == EXDEV) { // Cross-device move, use copy and remove.
+ Error err = OK;
+ err = copy(p_path, p_new_path);
+ if (err != OK) {
+ return err;
+ }
+ return remove(p_path);
+ } else {
+ return (res == 0) ? OK : FAILED;
+ }
}
Error DirAccessUnix::remove(String p_path) {
@@ -413,13 +429,16 @@ Error DirAccessUnix::remove(String p_path) {
}
p_path = fix_path(p_path);
+ if (p_path.ends_with("/")) {
+ p_path = p_path.left(-1);
+ }
struct stat flags = {};
if ((stat(p_path.utf8().get_data(), &flags) != 0)) {
return FAILED;
}
- if (S_ISDIR(flags.st_mode)) {
+ if (S_ISDIR(flags.st_mode) && !is_link(p_path)) {
return ::rmdir(p_path.utf8().get_data()) == 0 ? OK : FAILED;
} else {
return ::unlink(p_path.utf8().get_data()) == 0 ? OK : FAILED;
@@ -432,10 +451,13 @@ bool DirAccessUnix::is_link(String p_file) {
}
p_file = fix_path(p_file);
+ if (p_file.ends_with("/")) {
+ p_file = p_file.left(-1);
+ }
struct stat flags = {};
if ((lstat(p_file.utf8().get_data(), &flags) != 0)) {
- return FAILED;
+ return false;
}
return S_ISLNK(flags.st_mode);
@@ -447,6 +469,9 @@ String DirAccessUnix::read_link(String p_file) {
}
p_file = fix_path(p_file);
+ if (p_file.ends_with("/")) {
+ p_file = p_file.left(-1);
+ }
char buf[256];
memset(buf, 0, 256);