From f7edad7cbf4560902083df5ecc912b2d3f91ba28 Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Wed, 22 Aug 2012 12:53:00 +0800 Subject: [PATCH] recursive_action: add ACTION_FOLLOWLINKS support this is need to support symlink in envfs Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD --- include/libbb.h | 2 +- lib/recursive_action.c | 7 ++++++- scripts/bareboxenv.c | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 110e8ec39..47b2e0829 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -14,7 +14,7 @@ char* last_char_is(const char *s, int c); enum { ACTION_RECURSE = (1 << 0), - /* ACTION_FOLLOWLINKS = (1 << 1), - unused */ + ACTION_FOLLOWLINKS = (1 << 1), ACTION_DEPTHFIRST = (1 << 2), /*ACTION_REVERSE = (1 << 3), - unused */ }; diff --git a/lib/recursive_action.c b/lib/recursive_action.c index 1ef758df6..5bc2595db 100644 --- a/lib/recursive_action.c +++ b/lib/recursive_action.c @@ -54,14 +54,19 @@ int recursive_action(const char *fileName, const unsigned depth) { struct stat statbuf; + unsigned follow; int status; DIR *dir; struct dirent *next; if (!fileAction) fileAction = true_action; if (!dirAction) dirAction = true_action; - status = stat(fileName, &statbuf); + follow = ACTION_FOLLOWLINKS; + if (depth == 0) + follow = ACTION_FOLLOWLINKS; + follow &= flags; + status = (follow ? stat : lstat)(fileName, &statbuf); if (status < 0) { #ifdef DEBUG_RECURS_ACTION bb_error_msg("status=%d followLinks=%d TRUE=%d", diff --git a/scripts/bareboxenv.c b/scripts/bareboxenv.c index 866e345b9..f7f5351ca 100644 --- a/scripts/bareboxenv.c +++ b/scripts/bareboxenv.c @@ -73,7 +73,7 @@ char* last_char_is(const char *s, int c) enum { ACTION_RECURSE = (1 << 0), - /* ACTION_FOLLOWLINKS = (1 << 1), - unused */ + ACTION_FOLLOWLINKS = (1 << 1), ACTION_DEPTHFIRST = (1 << 2), /*ACTION_REVERSE = (1 << 3), - unused */ };