From 0d6ff4d0ed05a2a35cd7ade12e2c924704211bc8 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 29 Jun 2018 14:31:56 +0300 Subject: safer method of backing up databases instead of trying to read them manually --- plugins/Dbx_mdbx/src/dbintf.cpp | 17 +++++++++++++++++ plugins/Dbx_mdbx/src/dbintf.h | 1 + 2 files changed, 18 insertions(+) (limited to 'plugins/Dbx_mdbx/src') diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp index 9fffe8f732..cb663276c6 100644 --- a/plugins/Dbx_mdbx/src/dbintf.cpp +++ b/plugins/Dbx_mdbx/src/dbintf.cpp @@ -200,6 +200,23 @@ BOOL CDbxMDBX::Compact() return 0; } +BOOL CDbxMDBX::Backup(const wchar_t *pwszPath) +{ + HANDLE pFile = ::CreateFile(pwszPath, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + if (pFile == nullptr) { + Netlib_Logf(0, "Backup file <%S> cannot be created", pwszPath); + return 1; + } + + int res = mdbx_env_copy2fd(m_env, pFile, 0); + CloseHandle(pFile); + if (res == MDBX_SUCCESS) + return 0; + + DeleteFileW(pwszPath); + return res; +} + ///////////////////////////////////////////////////////////////////////////////////////// int CDbxMDBX::PrepareCheck() diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h index 1eebe92b2c..73fb14e36b 100644 --- a/plugins/Dbx_mdbx/src/dbintf.h +++ b/plugins/Dbx_mdbx/src/dbintf.h @@ -268,6 +268,7 @@ public: STDMETHODIMP_(BOOL) MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub); STDMETHODIMP_(BOOL) Compact(); + STDMETHODIMP_(BOOL) Backup(LPCWSTR); public: MICryptoEngine *m_crypto; -- cgit v1.2.3