Skip to content

Commit 50fd380

Browse files
committed
Merge pull request godotengine#90562 from bruvzg/fix_links
[Unix / DirAccess] Fix removing directory symlinks with `remove`, ensure `erase_contents_recursive` is not following directory symlinks.
2 parents fac5513 + 57fde36 commit 50fd380

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

core/io/dir_access.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static Error _erase_recursive(DirAccess *da) {
8484
String n = da->get_next();
8585
while (!n.is_empty()) {
8686
if (n != "." && n != "..") {
87-
if (da->current_is_dir()) {
87+
if (da->current_is_dir() && !da->is_link(n)) {
8888
dirs.push_back(n);
8989
} else {
9090
files.push_back(n);

drivers/unix/dir_access_unix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ Error DirAccessUnix::remove(String p_path) {
419419
return FAILED;
420420
}
421421

422-
if (S_ISDIR(flags.st_mode)) {
422+
if (S_ISDIR(flags.st_mode) && !is_link(p_path)) {
423423
return ::rmdir(p_path.utf8().get_data()) == 0 ? OK : FAILED;
424424
} else {
425425
return ::unlink(p_path.utf8().get_data()) == 0 ? OK : FAILED;
@@ -435,7 +435,7 @@ bool DirAccessUnix::is_link(String p_file) {
435435

436436
struct stat flags = {};
437437
if ((lstat(p_file.utf8().get_data(), &flags) != 0)) {
438-
return FAILED;
438+
return false;
439439
}
440440

441441
return S_ISLNK(flags.st_mode);

0 commit comments

Comments
 (0)