diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-02-06 22:49:35 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-02-06 22:49:35 -0500 |
commit | b46da967104df09edcad706e5e8ef31326a113dd (patch) | |
tree | 2f5e10dff126bf590f552a5bd73410f1db8844cf /bftw.c | |
parent | 0f91c5861cacaeb17729b7727d07260273345393 (diff) | |
download | bfs-b46da967104df09edcad706e5e8ef31326a113dd.tar.xz |
bftw: Don't give up when following a broken symlink.
Diffstat (limited to 'bftw.c')
-rw-r--r-- | bftw.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -631,7 +631,15 @@ static void bftw_init_buffers(struct bftw_state *state, const struct dirent *de) || ftwbuf->typeflag == BFTW_UNKNOWN || (ftwbuf->typeflag == BFTW_LNK && follow)) { int flags = follow ? 0 : AT_SYMLINK_NOFOLLOW; - if (ftwbuf_stat(ftwbuf, &state->statbuf, flags) != 0) { + + int ret = ftwbuf_stat(ftwbuf, &state->statbuf, 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); + } + + if (ret != 0) { state->error = errno; ftwbuf_set_error(ftwbuf, state->error); } |