git/t/helper/test-dir-iterator.c
Taylor Blau e00e56a7df 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>
2023-02-16 16:21:56 -08:00

63 lines
1.4 KiB
C

#include "test-tool.h"
#include "git-compat-util.h"
#include "strbuf.h"
#include "iterator.h"
#include "dir-iterator.h"
static const char *error_name(int error_number)
{
switch (error_number) {
case ENOENT: return "ENOENT";
case ENOTDIR: return "ENOTDIR";
default: return "ESOMETHINGELSE";
}
}
/*
* usage:
* tool-test dir-iterator [--pedantic] directory_path
*/
int cmd__dir_iterator(int argc, const char **argv)
{
struct dir_iterator *diter;
unsigned int flags = 0;
int iter_status;
for (++argv, --argc; *argv && starts_with(*argv, "--"); ++argv, --argc) {
if (strcmp(*argv, "--pedantic") == 0)
flags |= DIR_ITERATOR_PEDANTIC;
else
die("invalid option '%s'", *argv);
}
if (!*argv || argc != 1)
die("dir-iterator needs exactly one non-option argument");
diter = dir_iterator_begin(*argv, flags);
if (!diter) {
printf("dir_iterator_begin failure: %s\n", error_name(errno));
exit(EXIT_FAILURE);
}
while ((iter_status = dir_iterator_advance(diter)) == ITER_OK) {
if (S_ISDIR(diter->st.st_mode))
printf("[d] ");
else if (S_ISREG(diter->st.st_mode))
printf("[f] ");
else if (S_ISLNK(diter->st.st_mode))
printf("[s] ");
else
printf("[?] ");
printf("(%s) [%s] %s\n", diter->relative_path, diter->basename,
diter->path.buf);
}
if (iter_status != ITER_DONE) {
printf("dir_iterator_advance failure\n");
return 1;
}
return 0;
}