summaryrefslogtreecommitdiff
path: root/Userland/Utilities
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-05-18 01:15:29 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-18 08:11:42 +0200
commitf5c4d865923b5bab70830d7752e6cf7825872563 (patch)
tree0cce0448f198809d4fb0be16a25ed8706123bd6a /Userland/Utilities
parentc99fd217e230fbeef07e8bbda2c0a21fb3b0169d (diff)
downloadserenity-f5c4d865923b5bab70830d7752e6cf7825872563.zip
Utilites: Make find respect lack of -L when iterating over directories
Previously find would follow symlinks when iterating over directories even though the -L argument was not specified.
Diffstat (limited to 'Userland/Utilities')
-rw-r--r--Userland/Utilities/find.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/Userland/Utilities/find.cpp b/Userland/Utilities/find.cpp
index 524a5575a3..5da5f23962 100644
--- a/Userland/Utilities/find.cpp
+++ b/Userland/Utilities/find.cpp
@@ -457,8 +457,14 @@ static void walk_tree(const char* root_path, Command& command)
if (dir_iterator.has_error() && dir_iterator.error() == ENOTDIR)
return;
- while (dir_iterator.has_next())
- walk_tree(dir_iterator.next_full_path().characters(), command);
+ while (dir_iterator.has_next()) {
+ auto path = dir_iterator.next_full_path();
+ struct stat stat;
+ if (g_follow_symlinks || ::lstat(path.characters(), &stat) < 0 || !S_ISLNK(stat.st_mode))
+ walk_tree(path.characters(), command);
+ else
+ command.evaluate(path.characters());
+ }
if (dir_iterator.has_error()) {
fprintf(stderr, "%s: %s\n", root_path, dir_iterator.error_string());