From 12786e0f7c0e6ea23b1483f8732ca23b367bfd8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sun, 26 Jul 2015 17:19:22 +0200 Subject: [PATCH 1/2] iterator: skip over errors in diriter init An error here will typically mean that the directory was removed between the time we iterated the parent and the time we wanted to visit it in which case we should ignore it. Other kinds of errors such as permissions (or transient errors) also better dealt with by pretending we didn't see it. --- src/iterator.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/iterator.c b/src/iterator.c index a312afb3a..cf51a340d 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -1027,8 +1027,11 @@ static int dirload_with_stat( strncomp = (flags & GIT_PATH_DIR_IGNORE_CASE) != 0 ? git__strncasecmp : git__strncmp; - if ((error = git_path_diriter_init(&diriter, dirpath, flags)) < 0) + /* Any error here is equivalent to the dir not existing, skip over it */ + if ((error = git_path_diriter_init(&diriter, dirpath, flags)) < 0) { + error = GIT_ENOTFOUND; goto done; + } while ((error = git_path_diriter_next(&diriter)) == 0) { if ((error = git_path_diriter_fullpath(&path, &path_len, &diriter)) < 0) From 0e391d8526032008a53fd3e8f7c6795d59ebdb5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 27 Jul 2015 13:31:06 +0200 Subject: [PATCH 2/2] iterator: adjust unreadable-dir test to new behaviour We don't want the iterator to make us stop whenever we hit an unreadable dir. We should instead move over to the next item. --- tests/repo/iterator.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/repo/iterator.c b/tests/repo/iterator.c index 26e8954fe..bb2d3a186 100644 --- a/tests/repo/iterator.c +++ b/tests/repo/iterator.c @@ -928,7 +928,7 @@ void test_repo_iterator__fs2(void) git_iterator_free(i); } -void test_repo_iterator__fs_preserves_error(void) +void test_repo_iterator__unreadable_dir(void) { git_iterator *i; const git_index_entry *e; @@ -951,10 +951,6 @@ void test_repo_iterator__fs_preserves_error(void) cl_git_pass(git_iterator_advance(&e, i)); /* a */ cl_git_fail(git_iterator_advance(&e, i)); /* b */ - cl_assert(giterr_last()); - cl_assert(giterr_last()->message != NULL); - /* skip 'c/' empty directory */ - cl_git_pass(git_iterator_advance(&e, i)); /* d */ cl_assert_equal_i(GIT_ITEROVER, git_iterator_advance(&e, i)); cl_must_pass(p_chmod("empty_standard_repo/r/b", 0777));