filebuf: failing test for leaving the lockfile when failing to rename

When we fail to rename, we currently leave the lockfile laying
around. This shows that behaviour.
This commit is contained in:
Carlos Martín Nieto 2015-07-24 18:44:29 +02:00
parent e874f3c1c0
commit adb8f8d0bc

View File

@ -124,3 +124,30 @@ void test_core_filebuf__umask(void)
cl_must_pass(p_unlink(test));
}
void test_core_filebuf__rename_error(void)
{
git_filebuf file = GIT_FILEBUF_INIT;
char *dir = "subdir", *test = "subdir/test", *test_lock = "subdir/test.lock";
int fd;
#ifndef GIT_WIN32
cl_skip();
#endif
cl_git_pass(p_mkdir(dir, 0666));
cl_git_mkfile(test, "dummy content");
fd = p_open(test, O_RDONLY);
cl_assert(fd > 0);
cl_git_pass(git_filebuf_open(&file, test, 0, 0666));
cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
cl_assert_equal_i(true, git_path_exists(test_lock));
cl_git_fail(git_filebuf_commit(&file));
p_close(fd);
git_filebuf_cleanup(&file);
cl_assert_equal_i(false, git_path_exists(test_lock));
}