Commit 53fb823b by Edward Thomson

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.
parent 565c4199
......@@ -105,8 +105,8 @@ static void setup_race(void)
{
git_buf path = GIT_BUF_INIT;
git_index *index;
const git_index_entry *entry;
int i, found_race = 0;
git_index_entry *entry;
struct stat st;
/* Make sure we do have a timestamp */
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"));
/* 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_pass(git_index_write(index));
cl_git_mkfile(path.ptr, "B");
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_assert(entry = git_index_get_bypath(index, "A", 0));
if (entry->mtime.seconds == (int32_t) st.st_mtime) {
found_race = 1;
break;
}
}
cl_git_pass(p_stat(path.ptr, &st));
cl_assert(entry = (git_index_entry *)git_index_get_bypath(index, "A", 0));
if (!found_race)
cl_fail("failed to find race after 10 attempts");
/* force a race */
entry->mtime.seconds = st.st_mtime;
entry->mtime.nanoseconds = st.st_mtime_nsec;
git_buf_free(&path);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment