summaryrefslogtreecommitdiffstats
path: root/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-02-13 12:34:08 -0500
committerTavian Barnes <tavianator@tavianator.com>2016-02-13 12:49:38 -0500
commit55fb616348d114a1451ab6cf502a3768d6284e9a (patch)
treeef5f72632be59a2acb903c6ba7ef8f8355474f6d /bftw.c
parent603b9da0a0ef485393e9fb9fa14c139cedbe92d0 (diff)
downloadbfs-55fb616348d114a1451ab6cf502a3768d6284e9a.tar.xz
Follow links if appropriate in predicates.
Diffstat (limited to 'bftw.c')
-rw-r--r--bftw.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/bftw.c b/bftw.c
index d2a73d6..8a55f13 100644
--- a/bftw.c
+++ b/bftw.c
@@ -635,6 +635,7 @@ static void bftw_init_buffers(struct bftw_state *state, const struct dirent *de)
}
bool follow = state->flags & (current ? BFTW_FOLLOW_NONROOT : BFTW_FOLLOW_ROOT);
+ ftwbuf->at_flags = follow ? 0 : AT_SYMLINK_NOFOLLOW;
bool detect_cycles = (state->flags & BFTW_DETECT_CYCLES)
&& state->status == BFTW_CHILD;
@@ -643,13 +644,10 @@ static void bftw_init_buffers(struct bftw_state *state, const struct dirent *de)
|| ftwbuf->typeflag == BFTW_UNKNOWN
|| (ftwbuf->typeflag == BFTW_LNK && follow)
|| (ftwbuf->typeflag == BFTW_DIR && detect_cycles)) {
- int flags = follow ? 0 : AT_SYMLINK_NOFOLLOW;
-
- int ret = ftwbuf_stat(ftwbuf, &state->statbuf, flags);
+ int ret = ftwbuf_stat(ftwbuf, &state->statbuf, ftwbuf->at_flags);
if (ret != 0 && follow && errno == ENOENT) {
// Could be a broken symlink, retry without following
- flags = AT_SYMLINK_NOFOLLOW;
- ret = ftwbuf_stat(ftwbuf, &state->statbuf, flags);
+ ret = ftwbuf_stat(ftwbuf, &state->statbuf, AT_SYMLINK_NOFOLLOW);
}
if (ret != 0) {