Merge pull request #269 from schu/infinite-append gitfo_read: fix read-loop
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
diff --git a/src/fileops.c b/src/fileops.c
index c2a3ff0..2a5eb74 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -90,10 +90,8 @@ int gitfo_read(git_file fd, void *buf, size_t cnt)
continue;
return git__throw(GIT_EOSERR, "Failed to read from file");
}
- if (!r) {
- errno = EPIPE;
- return git__throw(GIT_EOSERR, "Failed to read from file");
- }
+ if (!r)
+ break;
cnt -= r;
b += r;
}
diff --git a/tests/t00-core.c b/tests/t00-core.c
index 1358cc6..aa00085 100644
--- a/tests/t00-core.c
+++ b/tests/t00-core.c
@@ -675,6 +675,23 @@ BEGIN_TEST(filebuf0, "make sure git_filebuf_open doesn't delete an existing lock
must_pass(gitfo_unlink(testlock));
END_TEST
+BEGIN_TEST(filebuf1, "make sure GIT_FILEBUF_APPEND works as expected")
+ git_filebuf file;
+ int fd;
+ char test[] = "test";
+
+ fd = gitfo_creat(test, 0644);
+ must_pass(fd);
+ must_pass(gitfo_write(fd, "libgit2 rocks\n", 14));
+ must_pass(gitfo_close(fd));
+
+ must_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND));
+ must_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
+ must_pass(git_filebuf_commit(&file));
+
+ must_pass(gitfo_unlink(test));
+END_TEST
+
BEGIN_SUITE(core)
ADD_TEST(string0);
ADD_TEST(string1);
@@ -698,4 +715,5 @@ BEGIN_SUITE(core)
ADD_TEST(dirent4);
ADD_TEST(filebuf0);
+ ADD_TEST(filebuf1);
END_SUITE