Skip to content

Commit 4cc9d2f

Browse files
committed
[Linux/BSD] Fix cross-device rename.
1 parent f4af820 commit 4cc9d2f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

drivers/unix/dir_access_unix.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,17 @@ Error DirAccessUnix::rename(String p_path, String p_new_path) {
410410
p_new_path = p_new_path.left(-1);
411411
}
412412

413-
return ::rename(p_path.utf8().get_data(), p_new_path.utf8().get_data()) == 0 ? OK : FAILED;
413+
int res = ::rename(p_path.utf8().get_data(), p_new_path.utf8().get_data());
414+
if (res != 0 && errno == EXDEV) { // Cross-device move, use copy and remove.
415+
Error err = OK;
416+
err = copy(p_path, p_new_path);
417+
if (err != OK) {
418+
return err;
419+
}
420+
return remove(p_path);
421+
} else {
422+
return (res == 0) ? OK : FAILED;
423+
}
414424
}
415425

416426
Error DirAccessUnix::remove(String p_path) {

0 commit comments

Comments
 (0)