Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Unix / DirAccess] Fix removing directory symlinks with remove, ensure erase_contents_recursive is not following directory symlinks. #90562

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/io/dir_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static Error _erase_recursive(DirAccess *da) {
String n = da->get_next();
while (!n.is_empty()) {
if (n != "." && n != "..") {
if (da->current_is_dir()) {
if (da->current_is_dir() && !da->is_link(n)) {
dirs.push_back(n);
} else {
files.push_back(n);
Expand Down
4 changes: 2 additions & 2 deletions drivers/unix/dir_access_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ Error DirAccessUnix::remove(String p_path) {
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;
Expand All @@ -435,7 +435,7 @@ bool DirAccessUnix::is_link(String p_file) {

struct stat flags = {};
if ((lstat(p_file.utf8().get_data(), &flags) != 0)) {
return FAILED;
return false;
}

return S_ISLNK(flags.st_mode);
Expand Down
Loading