From f5c4d865923b5bab70830d7752e6cf7825872563 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 18 May 2021 01:15:29 +0200 Subject: [PATCH] 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. --- Userland/Utilities/find.cpp | 10 ++++++++-- 1 file 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());