diff options
-rw-r--r-- | bftw.c | 8 | ||||
-rw-r--r-- | bftw.h | 2 | ||||
-rw-r--r-- | eval.c | 4 |
3 files changed, 7 insertions, 7 deletions
@@ -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) { @@ -75,6 +75,8 @@ struct BFTW { int at_fd; /** The path relative to atfd for the *at() family of calls. */ const char *at_path; + /** Appropriate flags (such as AT_SYMLINK_NOFOLLOW) for the *at() family of calls. */ + int at_flags; }; enum bftw_action { @@ -49,7 +49,7 @@ static void eval_error(struct eval_state *state) { static const struct stat *fill_statbuf(struct eval_state *state) { struct BFTW *ftwbuf = state->ftwbuf; if (!ftwbuf->statbuf) { - if (fstatat(ftwbuf->at_fd, ftwbuf->at_path, &state->statbuf, AT_SYMLINK_NOFOLLOW) == 0) { + if (fstatat(ftwbuf->at_fd, ftwbuf->at_path, &state->statbuf, ftwbuf->at_flags) == 0) { ftwbuf->statbuf = &state->statbuf; } else { eval_error(state); @@ -104,7 +104,7 @@ bool eval_false(const struct expr *expr, struct eval_state *state) { */ bool eval_access(const struct expr *expr, struct eval_state *state) { struct BFTW *ftwbuf = state->ftwbuf; - return faccessat(ftwbuf->at_fd, ftwbuf->at_path, expr->idata, AT_SYMLINK_NOFOLLOW) == 0; + return faccessat(ftwbuf->at_fd, ftwbuf->at_path, expr->idata, ftwbuf->at_flags) == 0; } /** |