From af6aa30c7c754324b526e68b0791b998dc841a3e Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Fri, 15 Nov 2019 11:09:15 +0300 Subject: [PATCH] mdbx: don't sync-on-close deleted files. Change-Id: Ie9358dfd79c9c5b26777e690079b3f081f0a7158 --- src/elements/core.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/elements/core.c b/src/elements/core.c index cf8b4996..ce8376bf 100644 --- a/src/elements/core.c +++ b/src/elements/core.c @@ -9012,11 +9012,16 @@ int __cold mdbx_env_close_ex(MDBX_env *env, int dont_sync) { rc = mdbx_env_sync_ex(env, true, false); rc = (rc == MDBX_RESULT_TRUE) ? MDBX_SUCCESS : rc; #else - rc = mdbx_env_sync_ex(env, true, true); - rc = (rc == MDBX_BUSY || rc == EAGAIN || rc == EACCES || rc == EBUSY || - rc == EWOULDBLOCK || rc == MDBX_RESULT_TRUE) - ? MDBX_SUCCESS - : rc; + struct stat st; + if (unlikely(fstat(env->me_fd, &st))) + rc = errno; + else if (st.st_nlink > 0 /* don't sync deleted files */) { + rc = mdbx_env_sync_ex(env, true, true); + rc = (rc == MDBX_BUSY || rc == EAGAIN || rc == EACCES || rc == EBUSY || + rc == EWOULDBLOCK || rc == MDBX_RESULT_TRUE) + ? MDBX_SUCCESS + : rc; + } #endif } }