dir-iterator: drop unused `DIR_ITERATOR_FOLLOW_SYMLINKS`

The `FOLLOW_SYMLINKS` flag was added to the dir-iterator API in fa1da7d2ee (dir-iterator: add flags parameter to dir_iterator_begin, 2019-07-10) in order to follow symbolic links while traversing through a directory. `FOLLOW_SYMLINKS` gained its first caller in ff7ccc8c9a (clone: use dir-iterator to avoid explicit dir traversal, 2019-07-10), but it was subsequently removed in 6f054f9fb3 (builtin/clone.c: disallow `--local` clones with symlinks, 2022-07-28). Since then, we've held on to the code for `DIR_ITERATOR_FOLLOW_SYMLINKS` in the name of making minimally invasive changes during a security embargo. In fact, we even changed the dir-iterator API in bffc762f87 (dir-iterator: prevent top-level symlinks without FOLLOW_SYMLINKS, 2023-01-24) without having any non-test callers of that flag. Now that we're past those security embargo(s), let's finalize our cleanup of the `DIR_ITERATOR_FOLLOW_SYMLINKS` code and remove its implementation since there are no remaining callers. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Feb 16, 2023 at 13:27 UTC e00e56a7df616659c90d107c3d31d362b5dff103
4 files changed +6 -66
dir-iterator.c
+3 -9
@@ -112,10 +112,7 @@ static int prepare_next_entry_data(struct dir_iterator_int *iter,
112 iter->base.basename = iter->base.path.buf +
113 iter->levels[iter->levels_nr - 1].prefix_len;
114
115 - if (iter->flags & DIR_ITERATOR_FOLLOW_SYMLINKS)
116 - err = stat(iter->base.path.buf, &iter->base.st);
117 - else
118 - err = lstat(iter->base.path.buf, &iter->base.st);
115 + err = lstat(iter->base.path.buf, &iter->base.st);
116
117 saved_errno = errno;
118 if (err && errno != ENOENT)
@@ -213,13 +210,10 @@ struct dir_iterator *dir_iterator_begin(const char *path, unsigned int flags)
210 iter->flags = flags;
211
212 /*
216 - * Note: stat/lstat already checks for NULL or empty strings and
213 + * Note: lstat already checks for NULL or empty strings and
214 * nonexistent paths.
215 */
219 - if (iter->flags & DIR_ITERATOR_FOLLOW_SYMLINKS)
220 - err = stat(iter->base.path.buf, &iter->base.st);
221 - else
222 - err = lstat(iter->base.path.buf, &iter->base.st);
216 + err = lstat(iter->base.path.buf, &iter->base.st);
217
218 if (err < 0) {
219 saved_errno = errno;
dir-iterator.h
+1 -19
@@ -54,24 +54,8 @@
54 * and ITER_ERROR is returned immediately. In both cases, a meaningful
55 * warning is emitted. Note: ENOENT errors are always ignored so that
56 * the API users may remove files during iteration.
57 - *
58 - * - DIR_ITERATOR_FOLLOW_SYMLINKS: make dir-iterator follow symlinks.
59 - * i.e., linked directories' contents will be iterated over and
60 - * iter->base.st will contain information on the referred files,
61 - * not the symlinks themselves, which is the default behavior. Broken
62 - * symlinks are ignored.
63 - *
64 - * Note: setting DIR_ITERATOR_FOLLOW_SYMLINKS affects resolving the
65 - * starting path as well (e.g., attempting to iterate starting at a
66 - * symbolic link pointing to a directory without FOLLOW_SYMLINKS will
67 - * result in an error).
68 - *
69 - * Warning: circular symlinks are also followed when
70 - * DIR_ITERATOR_FOLLOW_SYMLINKS is set. The iteration may end up with
71 - * an ELOOP if they happen and DIR_ITERATOR_PEDANTIC is set.
57 */
58 #define DIR_ITERATOR_PEDANTIC (1 << 0)
74 -#define DIR_ITERATOR_FOLLOW_SYMLINKS (1 << 1)
59
60 struct dir_iterator {
61 /* The current path: */
@@ -88,9 +72,7 @@ struct dir_iterator {
72 const char *basename;
73
74 /*
91 - * The result of calling lstat() on path; or stat(), if the
92 - * DIR_ITERATOR_FOLLOW_SYMLINKS flag was set at
93 - * dir_iterator's initialization.
75 + * The result of calling lstat() on path.
76 */
77 struct stat st;
78 };
t/helper/test-dir-iterator.c
+2 -4
@@ -15,7 +15,7 @@ static const char *error_name(int error_number)
15
16 /*
17 * usage:
18 - * tool-test dir-iterator [--follow-symlinks] [--pedantic] directory_path
18 + * tool-test dir-iterator [--pedantic] directory_path
19 */
20 int cmd__dir_iterator(int argc, const char **argv)
21 {
@@ -24,9 +24,7 @@ int cmd__dir_iterator(int argc, const char **argv)
24 int iter_status;
25
26 for (++argv, --argc; *argv && starts_with(*argv, "--"); ++argv, --argc) {
27 - if (strcmp(*argv, "--follow-symlinks") == 0)
28 - flags |= DIR_ITERATOR_FOLLOW_SYMLINKS;
29 - else if (strcmp(*argv, "--pedantic") == 0)
27 + if (strcmp(*argv, "--pedantic") == 0)
28 flags |= DIR_ITERATOR_PEDANTIC;
29 else
30 die("invalid option '%s'", *argv);
t/t0066-dir-iterator.sh
-34
@@ -131,44 +131,10 @@ test_expect_success SYMLINKS 'dir-iterator should not follow symlinks by default
131 test_cmp expected-no-follow-sorted-output actual-no-follow-sorted-output
132 '
133
134 -test_expect_success SYMLINKS 'dir-iterator should follow symlinks w/ follow flag' '
135 - cat >expected-follow-sorted-output <<-EOF &&
136 - [d] (a) [a] ./dir4/a
137 - [d] (a/f) [f] ./dir4/a/f
138 - [d] (a/f/c) [c] ./dir4/a/f/c
139 - [d] (b) [b] ./dir4/b
140 - [d] (b/c) [c] ./dir4/b/c
141 - [f] (a/d) [d] ./dir4/a/d
142 - [f] (a/e) [e] ./dir4/a/e
143 - EOF
144 -
145 - test-tool dir-iterator --follow-symlinks ./dir4 >out &&
146 - sort out >actual-follow-sorted-output &&
147 -
148 - test_cmp expected-follow-sorted-output actual-follow-sorted-output
149 -'
150 -
134 test_expect_success SYMLINKS 'dir-iterator does not resolve top-level symlinks' '
135 test_must_fail test-tool dir-iterator ./dir6 >out &&
136
137 grep "ENOTDIR" out
138 '
139
157 -test_expect_success SYMLINKS 'dir-iterator resolves top-level symlinks w/ follow flag' '
158 - cat >expected-follow-sorted-output <<-EOF &&
159 - [d] (a) [a] ./dir6/a
160 - [d] (a/f) [f] ./dir6/a/f
161 - [d] (a/f/c) [c] ./dir6/a/f/c
162 - [d] (b) [b] ./dir6/b
163 - [d] (b/c) [c] ./dir6/b/c
164 - [f] (a/d) [d] ./dir6/a/d
165 - [f] (a/e) [e] ./dir6/a/e
166 - EOF
167 -
168 - test-tool dir-iterator --follow-symlinks ./dir6 >out &&
169 - sort out >actual-follow-sorted-output &&
170 -
171 - test_cmp expected-follow-sorted-output actual-follow-sorted-output
172 -'
173 -
140 test_done