Skip to content

Commit 3ac05d1

Browse files
author
Edward Thomson
committed
win32: don't fsync parent directories on Windows
Windows doesn't support it.
1 parent 2a5ad7d commit 3ac05d1

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/fileops.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,10 @@ void git_futils_filestamp_set_from_stat(
11271127

11281128
int git_futils_fsync_dir(const char *path)
11291129
{
1130+
#ifdef GIT_WIN32
1131+
GIT_UNUSED(path);
1132+
return 0;
1133+
#else
11301134
int fd, error = -1;
11311135

11321136
if ((fd = p_open(path, O_RDONLY)) < 0) {
@@ -1139,6 +1143,7 @@ int git_futils_fsync_dir(const char *path)
11391143

11401144
p_close(fd);
11411145
return error;
1146+
#endif
11421147
}
11431148

11441149
int git_futils_fsync_parent(const char *path)

tests/pack/packbuilder.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,20 @@ void test_pack_packbuilder__does_not_fsync_by_default(void)
200200

201201
void test_pack_packbuilder__fsync_when_asked(void)
202202
{
203+
/* We fsync the packfile and index. On non-Windows, we also fsync
204+
* the parent directories.
205+
*/
206+
#ifdef GIT_WIN32
207+
int expected = 2;
208+
#else
209+
int expected = 4;
210+
#endif
211+
203212
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_SYNCHRONOUS_OBJECT_CREATION, 1));
204213
p_fsync__cnt = 0;
205214
seed_packbuilder();
206215
git_packbuilder_write(_packbuilder, ".", 0666, NULL, NULL);
207-
cl_assert_equal_sz(4, p_fsync__cnt);
216+
cl_assert_equal_sz(expected, p_fsync__cnt);
208217
}
209218

210219
static int foreach_cb(void *buf, size_t len, void *payload)

tests/refs/create.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,19 +323,30 @@ void test_refs_create__fsyncs_when_requested(void)
323323
git_refdb *refdb;
324324
git_oid id;
325325

326+
/* Creating a loose ref involves fsync'ing the reference, the
327+
* reflog and (on non-Windows) the containing directories.
328+
* Creating a packed ref involves fsync'ing the packed ref file
329+
* and (on non-Windows) the containing directory.
330+
*/
331+
#ifdef GIT_WIN32
332+
int expected_create = 2, expected_compress = 1;
333+
#else
334+
int expected_create = 4, expected_compress = 2;
335+
#endif
336+
326337
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_SYNCHRONOUS_OBJECT_CREATION, 1));
327338
p_fsync__cnt = 0;
328339

329340
git_oid_fromstr(&id, current_master_tip);
330341
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/fsync_test", &id, 0, "log message"));
331342
git_reference_free(ref);
332-
cl_assert_equal_i(4, p_fsync__cnt);
343+
cl_assert_equal_i(expected_create, p_fsync__cnt);
333344

334345
p_fsync__cnt = 0;
335346

336347
cl_git_pass(git_repository_refdb(&refdb, g_repo));
337348
cl_git_pass(git_refdb_compress(refdb));
338349
git_refdb_free(refdb);
339350

340-
cl_assert_equal_i(2, p_fsync__cnt);
351+
cl_assert_equal_i(expected_compress, p_fsync__cnt);
341352
}

0 commit comments

Comments
 (0)