summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-12-13 11:31:38 -0500
committerEdward Thomson <ethomson@github.com>2017-02-28 13:27:49 +0000
commite6ed0d2f03625f5d6b60db54fc894902d7ddbc32 (patch)
tree6a40c9e2a5873dac410b1294dfca7fdd2790d938 /src
parent6d3ad7e09ee4b101e8e68f38783e3e4139bc2691 (diff)
downloadlibgit2-e6ed0d2f03625f5d6b60db54fc894902d7ddbc32.tar.gz
odb_loose: fsync tests
Introduce a simple counter that `p_fsync` implements. This is useful for ensuring that `p_fsync` is called when we expect it to be, for example when we have enabled an odb backend to perform `fsync`s when writing objects.
Diffstat (limited to 'src')
-rw-r--r--src/posix.c2
-rw-r--r--src/posix.h6
-rw-r--r--src/unix/posix.h7
-rw-r--r--src/win32/posix_w32.c2
4 files changed, 16 insertions, 1 deletions
diff --git a/src/posix.c b/src/posix.c
index e68f324f6..94deb6ab0 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -10,6 +10,8 @@
#include <stdio.h>
#include <ctype.h>
+size_t p_fsync__cnt = 0;
+
#ifndef GIT_WIN32
#ifdef NO_ADDRINFO
diff --git a/src/posix.h b/src/posix.h
index f204751cf..bd5a98e26 100644
--- a/src/posix.h
+++ b/src/posix.h
@@ -111,6 +111,12 @@ extern int p_rename(const char *from, const char *to);
extern int git__page_size(size_t *page_size);
extern int git__mmap_alignment(size_t *page_size);
+/* The number of times `p_fsync` has been called. Note that this is for
+ * test code only; it it not necessarily thread-safe and should not be
+ * relied upon in production.
+ */
+extern size_t p_fsync__cnt;
+
/**
* Platform-dependent methods
*/
diff --git a/src/unix/posix.h b/src/unix/posix.h
index b4786403f..52985fd8a 100644
--- a/src/unix/posix.h
+++ b/src/unix/posix.h
@@ -40,9 +40,14 @@ typedef int GIT_SOCKET;
#define p_link(o,n) link(o, n)
#define p_unlink(p) unlink(p)
#define p_mkdir(p,m) mkdir(p, m)
-#define p_fsync(fd) fsync(fd)
extern char *p_realpath(const char *, char *);
+GIT_INLINE(int) p_fsync(int fd)
+{
+ p_fsync__cnt++;
+ return fsync(fd);
+}
+
#define p_recv(s,b,l,f) recv(s,b,l,f)
#define p_send(s,b,l,f) send(s,b,l,f)
#define p_inet_pton(a, b, c) inet_pton(a, b, c)
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index fea634b00..5172627b0 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -113,6 +113,8 @@ int p_fsync(int fd)
{
HANDLE fh = (HANDLE)_get_osfhandle(fd);
+ p_fsync__cnt++;
+
if (fh == INVALID_HANDLE_VALUE) {
errno = EBADF;
return -1;