From 597f12c44a000add479c6a0b416e8c0847b59b20 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Sat, 19 Nov 2016 00:31:21 +0800 Subject: Use atomic key generation in all cases --- dbutil.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'dbutil.c') diff --git a/dbutil.c b/dbutil.c index ef06802..69e43bb 100644 --- a/dbutil.c +++ b/dbutil.c @@ -681,4 +681,21 @@ time_t monotonic_now() { return time(NULL); } +void fsync_parent_dir(const char* fn) { +#ifdef HAVE_LIBGEN_H + char *fn_dir = m_strdup(fn); + char *dir = dirname(fn_dir); + int dirfd = open(dir, O_RDONLY); + + if (dirfd != -1) { + if (fsync(dirfd) != 0) { + TRACE(("fsync of directory %s failed: %s", dir, strerror(errno))) + } + m_close(dirfd); + } else { + TRACE(("error opening directory %s for fsync: %s", dir, strerror(errno))) + } + free(fn_dir); +#endif +} -- cgit v1.2.3