Merge pull request #2506 from libgit2/rb/ignore-pipes-etc Don't report status on named pipes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
diff --git a/src/path.c b/src/path.c
index 4837b01..77f8d88 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1110,28 +1110,29 @@ int git_path_dirload_with_stat(
if ((error = git_buf_joinpath(&full, full.ptr, ps->path)) < 0 ||
(error = git_path_lstat(full.ptr, &ps->st)) < 0) {
+
if (error == GIT_ENOTFOUND) {
- giterr_clear();
- error = 0;
+ /* file was removed between readdir and lstat */
git_vector_remove(contents, i--);
- continue;
- }
- /* Treat the file as unreadable if we get any other error */
- if (error != 0) {
- giterr_clear();
- error = 0;
+ } else {
+ /* Treat the file as unreadable if we get any other error */
memset(&ps->st, 0, sizeof(ps->st));
ps->st.st_mode = GIT_FILEMODE_UNREADABLE;
- continue;
}
-
- break;
+
+ giterr_clear();
+ error = 0;
+ continue;
}
if (S_ISDIR(ps->st.st_mode)) {
ps->path[ps->path_len++] = '/';
ps->path[ps->path_len] = '\0';
}
+ else if (!S_ISREG(ps->st.st_mode) && !S_ISLNK(ps->st.st_mode)) {
+ /* skip everything but dirs, plain files, and symlinks */
+ git_vector_remove(contents, i--);
+ }
}
/* sort now that directory suffix is added */
diff --git a/tests/repo/iterator.c b/tests/repo/iterator.c
index fb70a9e..764c2c6 100644
--- a/tests/repo/iterator.c
+++ b/tests/repo/iterator.c
@@ -960,3 +960,35 @@ void test_repo_iterator__fs_preserves_error(void)
git_iterator_free(i);
}
+
+void test_repo_iterator__skips_fifos_and_such(void)
+{
+#ifndef GIT_WIN32
+ git_iterator *i;
+ const git_index_entry *e;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ cl_must_pass(p_mkdir("empty_standard_repo/dir", 0777));
+ cl_git_mkfile("empty_standard_repo/file", "not me");
+
+ cl_assert(!mkfifo("empty_standard_repo/fifo", 0777));
+ cl_assert(!access("empty_standard_repo/fifo", F_OK));
+
+ cl_git_pass(git_iterator_for_filesystem(
+ &i, "empty_standard_repo", GIT_ITERATOR_INCLUDE_TREES |
+ GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL));
+
+ cl_git_pass(git_iterator_advance(&e, i)); /* .git */
+ cl_assert(S_ISDIR(e->mode));
+ cl_git_pass(git_iterator_advance(&e, i)); /* dir */
+ cl_assert(S_ISDIR(e->mode));
+ /* skips fifo */
+ cl_git_pass(git_iterator_advance(&e, i)); /* file */
+ cl_assert(S_ISREG(e->mode));
+
+ cl_assert_equal_i(GIT_ITEROVER, git_iterator_advance(&e, i));
+
+ git_iterator_free(i);
+#endif
+}