Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit adb8f8d

Browse files
committed
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.
1 parent e874f3c commit adb8f8d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/core/filebuf.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,30 @@ void test_core_filebuf__umask(void)
124124
cl_must_pass(p_unlink(test));
125125
}
126126

127+
void test_core_filebuf__rename_error(void)
128+
{
129+
git_filebuf file = GIT_FILEBUF_INIT;
130+
char *dir = "subdir", *test = "subdir/test", *test_lock = "subdir/test.lock";
131+
int fd;
132+
133+
#ifndef GIT_WIN32
134+
cl_skip();
135+
#endif
136+
137+
cl_git_pass(p_mkdir(dir, 0666));
138+
cl_git_mkfile(test, "dummy content");
139+
fd = p_open(test, O_RDONLY);
140+
cl_assert(fd > 0);
141+
cl_git_pass(git_filebuf_open(&file, test, 0, 0666));
142+
143+
cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
144+
145+
cl_assert_equal_i(true, git_path_exists(test_lock));
146+
147+
cl_git_fail(git_filebuf_commit(&file));
148+
p_close(fd);
149+
150+
git_filebuf_cleanup(&file);
151+
cl_assert_equal_i(false, git_path_exists(test_lock));
152+
153+
}

0 commit comments

Comments
 (0)