summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdbx/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-06-29 14:31:56 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-06-29 14:31:56 +0300
commit0d6ff4d0ed05a2a35cd7ade12e2c924704211bc8 (patch)
tree72cc7e24988aa9f35691b1d0bdccbc172208db70 /plugins/Dbx_mdbx/src
parent6233a4777edce1b30af96035e31ae3df074b15cb (diff)
safer method of backing up databases instead of trying to read them manually
Diffstat (limited to 'plugins/Dbx_mdbx/src')
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.cpp17
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.h1
2 files changed, 18 insertions, 0 deletions
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;