Skip to content

Commit b8840a7

Browse files
committed
Merge branch 'tb/drop-dir-iterator-follow-symlink-bit'
Remove leftover and unused code. * tb/drop-dir-iterator-follow-symlink-bit: t0066: drop setup of "dir5" dir-iterator: drop unused `DIR_ITERATOR_FOLLOW_SYMLINKS`
2 parents 63f74cf + 3b0ebb7 commit b8840a7

File tree

4 files changed

+8
-74
lines changed

4 files changed

+8
-74
lines changed

dir-iterator.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,7 @@ static int prepare_next_entry_data(struct dir_iterator_int *iter,
112112
iter->base.basename = iter->base.path.buf +
113113
iter->levels[iter->levels_nr - 1].prefix_len;
114114

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);
119116

120117
saved_errno = errno;
121118
if (err && errno != ENOENT)
@@ -213,13 +210,10 @@ struct dir_iterator *dir_iterator_begin(const char *path, unsigned int flags)
213210
iter->flags = flags;
214211

215212
/*
216-
* Note: stat/lstat already checks for NULL or empty strings and
213+
* Note: lstat already checks for NULL or empty strings and
217214
* nonexistent paths.
218215
*/
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);
223217

224218
if (err < 0) {
225219
saved_errno = errno;

dir-iterator.h

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,8 @@
5454
* and ITER_ERROR is returned immediately. In both cases, a meaningful
5555
* warning is emitted. Note: ENOENT errors are always ignored so that
5656
* 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.
7257
*/
7358
#define DIR_ITERATOR_PEDANTIC (1 << 0)
74-
#define DIR_ITERATOR_FOLLOW_SYMLINKS (1 << 1)
7559

7660
struct dir_iterator {
7761
/* The current path: */
@@ -88,9 +72,7 @@ struct dir_iterator {
8872
const char *basename;
8973

9074
/*
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.
9476
*/
9577
struct stat st;
9678
};

t/helper/test-dir-iterator.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static const char *error_name(int error_number)
1515

1616
/*
1717
* usage:
18-
* tool-test dir-iterator [--follow-symlinks] [--pedantic] directory_path
18+
* tool-test dir-iterator [--pedantic] directory_path
1919
*/
2020
int cmd__dir_iterator(int argc, const char **argv)
2121
{
@@ -24,9 +24,7 @@ int cmd__dir_iterator(int argc, const char **argv)
2424
int iter_status;
2525

2626
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)
3028
flags |= DIR_ITERATOR_PEDANTIC;
3129
else
3230
die("invalid option '%s'", *argv);

t/t0066-dir-iterator.sh

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,7 @@ test_expect_success SYMLINKS 'setup dirs with symlinks' '
106106
ln -s d dir4/a/e &&
107107
ln -s ../b dir4/a/f &&
108108
109-
mkdir -p dir5/a/b &&
110-
mkdir -p dir5/a/c &&
111-
ln -s ../c dir5/a/b/d &&
112-
ln -s ../ dir5/a/b/e &&
113-
ln -s ../../ dir5/a/b/f &&
114-
115-
ln -s dir4 dir6
109+
ln -s dir4 dir5
116110
'
117111

118112
test_expect_success SYMLINKS 'dir-iterator should not follow symlinks by default' '
@@ -131,44 +125,10 @@ test_expect_success SYMLINKS 'dir-iterator should not follow symlinks by default
131125
test_cmp expected-no-follow-sorted-output actual-no-follow-sorted-output
132126
'
133127

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-
151128
test_expect_success SYMLINKS 'dir-iterator does not resolve top-level symlinks' '
152-
test_must_fail test-tool dir-iterator ./dir6 >out &&
129+
test_must_fail test-tool dir-iterator ./dir5 >out &&
153130
154131
grep "ENOTDIR" out
155132
'
156133

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-
174134
test_done

0 commit comments

Comments
 (0)