summaryrefslogtreecommitdiff
path: root/t/helper/test-dir-iterator.c
diff options
context:
space:
mode:
authorLibravatar Matheus Tavares <matheus.bernardino@usp.br>2019-07-10 20:58:59 -0300
committerLibravatar Junio C Hamano <gitster@pobox.com>2019-07-11 13:52:15 -0700
commit3012397e0327f5e4dfd1d1183a792268429744ae (patch)
tree79faf55ec5f3ce158864c809e309cc3fa5a0da17 /t/helper/test-dir-iterator.c
parentdir-iterator: use warning_errno when possible (diff)
downloadtgif-3012397e0327f5e4dfd1d1183a792268429744ae.tar.xz
dir-iterator: refactor state machine model
dir_iterator_advance() is a large function with two nested loops. Let's improve its readability factoring out three functions and simplifying its mechanics. The refactored model will no longer depend on level.initialized and level.dir_state to keep track of the iteration state and will perform on a single loop. Also, dir_iterator_begin() currently does not check if the given string represents a valid directory path. Since the refactored model will have to stat() the given path at initialization, let's also check for this kind of error and make dir_iterator_begin() return NULL, on failures, with errno appropriately set. And add tests for this new behavior. Improve documentation at dir-iteration.h and code comments at dir-iterator.c to reflect the changes and eliminate possible ambiguities. Finally, adjust refs/files-backend.c to check for now possible dir_iterator_begin() failures. Original-patch-by: Daniel Ferreira <bnmvco@gmail.com> Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/helper/test-dir-iterator.c')
-rw-r--r--t/helper/test-dir-iterator.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/t/helper/test-dir-iterator.c b/t/helper/test-dir-iterator.c
index 84f50bed8c..fab1ff6237 100644
--- a/t/helper/test-dir-iterator.c
+++ b/t/helper/test-dir-iterator.c
@@ -17,6 +17,11 @@ int cmd__dir_iterator(int argc, const char **argv)
diter = dir_iterator_begin(path.buf);
+ if (!diter) {
+ printf("dir_iterator_begin failure: %d\n", errno);
+ exit(EXIT_FAILURE);
+ }
+
while (dir_iterator_advance(diter) == ITER_OK) {
if (S_ISDIR(diter->st.st_mode))
printf("[d] ");