diff --git a/dir-iterator.c b/dir-iterator.c index 3764dd81a18..cedd3047599 100644 --- a/dir-iterator.c +++ b/dir-iterator.c @@ -112,10 +112,7 @@ static int prepare_next_entry_data(struct dir_iterator_int *iter, iter->base.basename = iter->base.path.buf + iter->levels[iter->levels_nr - 1].prefix_len; - if (iter->flags & DIR_ITERATOR_FOLLOW_SYMLINKS) - err = stat(iter->base.path.buf, &iter->base.st); - else - err = lstat(iter->base.path.buf, &iter->base.st); + err = lstat(iter->base.path.buf, &iter->base.st); saved_errno = errno; if (err && errno != ENOENT) @@ -213,13 +210,10 @@ struct dir_iterator *dir_iterator_begin(const char *path, unsigned int flags) iter->flags = flags; /* - * Note: stat/lstat already checks for NULL or empty strings and + * Note: lstat already checks for NULL or empty strings and * nonexistent paths. */ - if (iter->flags & DIR_ITERATOR_FOLLOW_SYMLINKS) - err = stat(iter->base.path.buf, &iter->base.st); - else - err = lstat(iter->base.path.buf, &iter->base.st); + err = lstat(iter->base.path.buf, &iter->base.st); if (err < 0) { saved_errno = errno; diff --git a/dir-iterator.h b/dir-iterator.h index e3b6ff28007..479e1ec784d 100644 --- a/dir-iterator.h +++ b/dir-iterator.h @@ -54,24 +54,8 @@ * and ITER_ERROR is returned immediately. In both cases, a meaningful * warning is emitted. Note: ENOENT errors are always ignored so that * the API users may remove files during iteration. - * - * - DIR_ITERATOR_FOLLOW_SYMLINKS: make dir-iterator follow symlinks. - * i.e., linked directories' contents will be iterated over and - * iter->base.st will contain information on the referred files, - * not the symlinks themselves, which is the default behavior. Broken - * symlinks are ignored. - * - * Note: setting DIR_ITERATOR_FOLLOW_SYMLINKS affects resolving the - * starting path as well (e.g., attempting to iterate starting at a - * symbolic link pointing to a directory without FOLLOW_SYMLINKS will - * result in an error). - * - * Warning: circular symlinks are also followed when - * DIR_ITERATOR_FOLLOW_SYMLINKS is set. The iteration may end up with - * an ELOOP if they happen and DIR_ITERATOR_PEDANTIC is set. */ #define DIR_ITERATOR_PEDANTIC (1 << 0) -#define DIR_ITERATOR_FOLLOW_SYMLINKS (1 << 1) struct dir_iterator { /* The current path: */ @@ -88,9 +72,7 @@ struct dir_iterator { const char *basename; /* - * The result of calling lstat() on path; or stat(), if the - * DIR_ITERATOR_FOLLOW_SYMLINKS flag was set at - * dir_iterator's initialization. + * The result of calling lstat() on path. */ struct stat st; }; diff --git a/t/helper/test-dir-iterator.c b/t/helper/test-dir-iterator.c index 659b6bfa81d..6b297bd7536 100644 --- a/t/helper/test-dir-iterator.c +++ b/t/helper/test-dir-iterator.c @@ -15,7 +15,7 @@ static const char *error_name(int error_number) /* * usage: - * tool-test dir-iterator [--follow-symlinks] [--pedantic] directory_path + * tool-test dir-iterator [--pedantic] directory_path */ int cmd__dir_iterator(int argc, const char **argv) { @@ -24,9 +24,7 @@ int cmd__dir_iterator(int argc, const char **argv) int iter_status; for (++argv, --argc; *argv && starts_with(*argv, "--"); ++argv, --argc) { - if (strcmp(*argv, "--follow-symlinks") == 0) - flags |= DIR_ITERATOR_FOLLOW_SYMLINKS; - else if (strcmp(*argv, "--pedantic") == 0) + if (strcmp(*argv, "--pedantic") == 0) flags |= DIR_ITERATOR_PEDANTIC; else die("invalid option '%s'", *argv); diff --git a/t/t0066-dir-iterator.sh b/t/t0066-dir-iterator.sh index 04b811622bc..4ed3136b00b 100755 --- a/t/t0066-dir-iterator.sh +++ b/t/t0066-dir-iterator.sh @@ -131,44 +131,10 @@ test_expect_success SYMLINKS 'dir-iterator should not follow symlinks by default test_cmp expected-no-follow-sorted-output actual-no-follow-sorted-output ' -test_expect_success SYMLINKS 'dir-iterator should follow symlinks w/ follow flag' ' - cat >expected-follow-sorted-output <<-EOF && - [d] (a) [a] ./dir4/a - [d] (a/f) [f] ./dir4/a/f - [d] (a/f/c) [c] ./dir4/a/f/c - [d] (b) [b] ./dir4/b - [d] (b/c) [c] ./dir4/b/c - [f] (a/d) [d] ./dir4/a/d - [f] (a/e) [e] ./dir4/a/e - EOF - - test-tool dir-iterator --follow-symlinks ./dir4 >out && - sort out >actual-follow-sorted-output && - - test_cmp expected-follow-sorted-output actual-follow-sorted-output -' - test_expect_success SYMLINKS 'dir-iterator does not resolve top-level symlinks' ' test_must_fail test-tool dir-iterator ./dir6 >out && grep "ENOTDIR" out ' -test_expect_success SYMLINKS 'dir-iterator resolves top-level symlinks w/ follow flag' ' - cat >expected-follow-sorted-output <<-EOF && - [d] (a) [a] ./dir6/a - [d] (a/f) [f] ./dir6/a/f - [d] (a/f/c) [c] ./dir6/a/f/c - [d] (b) [b] ./dir6/b - [d] (b/c) [c] ./dir6/b/c - [f] (a/d) [d] ./dir6/a/d - [f] (a/e) [e] ./dir6/a/e - EOF - - test-tool dir-iterator --follow-symlinks ./dir6 >out && - sort out >actual-follow-sorted-output && - - test_cmp expected-follow-sorted-output actual-follow-sorted-output -' - test_done