From b9d3eac12eb3cf678f2d85fbe8630a502fe65cff Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Fri, 29 Jun 2018 23:54:59 +0300 Subject: [PATCH] mdbx: minor refine mdbx_env_copy(). Change-Id: I007add822bc4d30b7a8a838981ada6d2812f669a --- mdbx.h | 3 ++- src/mdbx.c | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/mdbx.h b/mdbx.h index c1e60afc..f18f6cef 100644 --- a/mdbx.h +++ b/mdbx.h @@ -695,7 +695,8 @@ LIBMDBX_API int mdbx_env_open(MDBX_env *env, const char *path, unsigned flags, * NOTE: Currently it fails if the environment has suffered a page leak. * * Returns A non-zero error value on failure and 0 on success. */ -LIBMDBX_API int mdbx_env_copy(MDBX_env *env, const char *path, unsigned flags); +LIBMDBX_API int mdbx_env_copy(MDBX_env *env, const char *dest_path, + unsigned flags); /* Copy an MDBX environment to the specified file descriptor, * with options. diff --git a/src/mdbx.c b/src/mdbx.c index e6534c82..0dd53b30 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -10488,25 +10488,25 @@ int __cold mdbx_env_copy2fd(MDBX_env *env, mdbx_filehandle_t fd, return mdbx_env_copy_asis(env, fd); } -int __cold mdbx_env_copy(MDBX_env *env, const char *path, unsigned flags) { - char *lck_pathname; +int __cold mdbx_env_copy(MDBX_env *env, const char *dest_path, unsigned flags) { + char *dxb_pathname; mdbx_filehandle_t newfd = INVALID_HANDLE_VALUE; if (env->me_flags & MDBX_NOSUBDIR) { - lck_pathname = (char *)path; + dxb_pathname = (char *)dest_path; } else { - size_t len = strlen(path); + size_t len = strlen(dest_path); len += sizeof(MDBX_DATANAME); - lck_pathname = malloc(len); - if (!lck_pathname) + dxb_pathname = malloc(len); + if (!dxb_pathname) return MDBX_ENOMEM; - sprintf(lck_pathname, "%s" MDBX_DATANAME, path); + sprintf(dxb_pathname, "%s" MDBX_DATANAME, dest_path); } /* The destination path must exist, but the destination file must not. * We don't want the OS to cache the writes, since the source data is * already in the OS cache. */ - int rc = mdbx_openfile(lck_pathname, O_WRONLY | O_CREAT | O_EXCL, 0666, + int rc = mdbx_openfile(dxb_pathname, O_WRONLY | O_CREAT | O_EXCL, 0666, &newfd, true); if (rc == MDBX_SUCCESS) { if (env->me_psize >= env->me_os_psize) { @@ -10521,8 +10521,8 @@ int __cold mdbx_env_copy(MDBX_env *env, const char *path, unsigned flags) { rc = mdbx_env_copy2fd(env, newfd, flags); } - if (!(env->me_flags & MDBX_NOSUBDIR)) - free(lck_pathname); + if (dxb_pathname != dest_path) + free(dxb_pathname); if (newfd != INVALID_HANDLE_VALUE) { int err = mdbx_closefile(newfd);