From 4cc9d2f4376adc6e07129ff133f7665c0f5e749a Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Wed, 2 Oct 2024 08:57:37 +0300 Subject: [PATCH] [Linux/BSD] Fix cross-device rename. --- drivers/unix/dir_access_unix.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index e4bad880837..816ffd7a322 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -410,7 +410,17 @@ Error DirAccessUnix::rename(String p_path, String p_new_path) { 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) {