From 1d71c677f6b8d68a3ae6f4d542a611d3b948d741 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sat, 10 Oct 2020 18:31:15 +0300 Subject: [PATCH] mdbx++: add `env::remove()` method. Change-Id: If0396d38738df88d054eb8fb752c7bd3afbd8487 --- mdbx.h++ | 21 +++++++++++++++++++++ src/mdbx.c++ | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/mdbx.h++ b/mdbx.h++ index 2050f4b9..572ec604 100644 --- a/mdbx.h++ +++ b/mdbx.h++ @@ -1922,6 +1922,27 @@ public: /// \brief Copy an environment to the specified file descriptor. env ©(filehandle fd, bool compactify, bool force_dynamic_size = false); + /// \brief Deletion modes for \ref remove(). + enum remove_mode { + /// \brief Just delete the environment's files and directory if any. + /// \note On POSIX systems, processes already working with the database will + /// continue to work without interference until it close the environment. + /// \note On Windows, the behavior of `just_remove` is different + /// because the system does not support deleting files that are currently + /// memory mapped. + just_remove = MDBX_ENV_JUST_DELETE, + /// \brief Make sure that the environment is not being used by other + /// processes, or return an error otherwise. + ensure_unused = MDBX_ENV_ENSURE_UNUSED, + /// \brief Wait until other processes closes the environment before + /// deletion. + wait_for_unused = MDBX_ENV_WAIT_FOR_UNUSED + }; + + /// \brief Removes the environment's files in a proper and multiprocess-safe + /// way. + static bool remove(const path &, const remove_mode mode = just_remove); + /// \brief Statistics for a database in the MDBX environment. using stat = ::MDBX_stat; diff --git a/src/mdbx.c++ b/src/mdbx.c++ index 9f7d7571..18db236f 100644 --- a/src/mdbx.c++ +++ b/src/mdbx.c++ @@ -1119,6 +1119,12 @@ path env::get_path() const { return pchar_to_path(c_str); } +bool env::remove(const path &pathname, const remove_mode mode) { + const path_to_pchar utf8(pathname); + return error::boolean_or_throw( + ::mdbx_env_delete(utf8, MDBX_env_delete_mode_t(mode))); +} + //------------------------------------------------------------------------------ static inline MDBX_env *create_env() {