mirror of
https://github.com/isar/libmdbx.git
synced 2024-12-30 02:14:12 +08:00
mdbx++: add env::remove()
method.
Change-Id: If0396d38738df88d054eb8fb752c7bd3afbd8487
This commit is contained in:
parent
6e82dd5d0c
commit
1d71c677f6
21
mdbx.h++
21
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;
|
||||
|
||||
|
@ -1119,6 +1119,12 @@ path env::get_path() const {
|
||||
return pchar_to_path<path>(c_str);
|
||||
}
|
||||
|
||||
bool env::remove(const path &pathname, const remove_mode mode) {
|
||||
const path_to_pchar<path> utf8(pathname);
|
||||
return error::boolean_or_throw(
|
||||
::mdbx_env_delete(utf8, MDBX_env_delete_mode_t(mode)));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
static inline MDBX_env *create_env() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user