mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 20:29:27 +00:00
index::racy: force racy entry
Instead of hoping that we can get a racy entry by going real fast and praying real hard, just create a racy entry.
This commit is contained in:
parent
565c419972
commit
53fb823bcc
@ -105,8 +105,8 @@ static void setup_race(void)
|
|||||||
{
|
{
|
||||||
git_buf path = GIT_BUF_INIT;
|
git_buf path = GIT_BUF_INIT;
|
||||||
git_index *index;
|
git_index *index;
|
||||||
const git_index_entry *entry;
|
git_index_entry *entry;
|
||||||
int i, found_race = 0;
|
struct stat st;
|
||||||
|
|
||||||
/* Make sure we do have a timestamp */
|
/* Make sure we do have a timestamp */
|
||||||
cl_git_pass(git_repository_index__weakptr(&index, g_repo));
|
cl_git_pass(git_repository_index__weakptr(&index, g_repo));
|
||||||
@ -114,27 +114,20 @@ static void setup_race(void)
|
|||||||
|
|
||||||
cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A"));
|
cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A"));
|
||||||
|
|
||||||
/* Make sure writing the file, adding and rewriting happen in the same second */
|
|
||||||
for (i = 0; i < 10; i++) {
|
|
||||||
struct stat st;
|
|
||||||
cl_git_mkfile(path.ptr, "A");
|
cl_git_mkfile(path.ptr, "A");
|
||||||
|
|
||||||
cl_git_pass(git_index_add_bypath(index, "A"));
|
cl_git_pass(git_index_add_bypath(index, "A"));
|
||||||
|
|
||||||
cl_git_mkfile(path.ptr, "B");
|
cl_git_mkfile(path.ptr, "B");
|
||||||
cl_git_pass(git_index_write(index));
|
cl_git_pass(git_index_write(index));
|
||||||
|
|
||||||
cl_git_mkfile(path.ptr, "");
|
cl_git_mkfile(path.ptr, "");
|
||||||
|
|
||||||
cl_git_pass(p_stat(path.ptr, &st));
|
cl_git_pass(p_stat(path.ptr, &st));
|
||||||
cl_assert(entry = git_index_get_bypath(index, "A", 0));
|
cl_assert(entry = (git_index_entry *)git_index_get_bypath(index, "A", 0));
|
||||||
if (entry->mtime.seconds == (int32_t) st.st_mtime) {
|
|
||||||
found_race = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found_race)
|
/* force a race */
|
||||||
cl_fail("failed to find race after 10 attempts");
|
entry->mtime.seconds = st.st_mtime;
|
||||||
|
entry->mtime.nanoseconds = st.st_mtime_nsec;
|
||||||
|
|
||||||
git_buf_free(&path);
|
git_buf_free(&path);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user