summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdbx
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-11-08 21:15:12 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-11-08 21:15:12 +0300
commit4fbd8461b0d058b253dc7d9d39264651769aced8 (patch)
tree4cb5515585324160a31b2025b3ca52c376265af7 /plugins/Dbx_mdbx
parentaed3dc19be76f442e543cecba755abd52d2ced76 (diff)
Dbx_mdbx: added control for disk overflow during backup
Diffstat (limited to 'plugins/Dbx_mdbx')
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.cpp45
1 files changed, 23 insertions, 22 deletions
diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp
index 17005a3cbb..991fd6686c 100644
--- a/plugins/Dbx_mdbx/src/dbintf.cpp
+++ b/plugins/Dbx_mdbx/src/dbintf.cpp
@@ -156,27 +156,18 @@ BOOL CDbxMDBX::Compact()
{
CMStringW wszTmpFile(FORMAT, L"%s.tmp", m_tszProfileName);
- HANDLE pFile = ::CreateFile(wszTmpFile, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
- if (pFile == nullptr) {
- Netlib_Logf(0, "Temporary file <%S> cannot be created", wszTmpFile.c_str());
- return 1;
- }
-
mir_cslock lck(m_csDbAccess);
- int res = mdbx_env_copy2fd(m_env, pFile, MDBX_CP_COMPACT);
- CloseHandle(pFile);
+ int res = Backup(wszTmpFile);
+ if (res)
+ return res;
- if (res == MDBX_SUCCESS) {
- mdbx_env_close(m_env);
+ mdbx_env_close(m_env);
- DeleteFileW(m_tszProfileName);
- MoveFileW(wszTmpFile, m_tszProfileName);
-
- Map();
- Load();
- }
- else DeleteFileW(wszTmpFile);
+ DeleteFileW(m_tszProfileName);
+ MoveFileW(wszTmpFile, m_tszProfileName);
+ Map();
+ Load();
return 0;
}
@@ -189,12 +180,22 @@ BOOL CDbxMDBX::Backup(const wchar_t *pwszPath)
}
int res = mdbx_env_copy2fd(m_env, pFile, MDBX_CP_COMPACT);
- CloseHandle(pFile);
- if (res == MDBX_SUCCESS)
- return 0;
+ if (res != MDBX_SUCCESS) {
+ Netlib_Logf(0, "CDbxMDBX::Backup: mdbx_env_copy2fd failed with error code %d", res);
+LBL_Fail:
+ CloseHandle(pFile);
+ DeleteFileW(pwszPath);
+ return res;
+ }
- DeleteFileW(pwszPath);
- return res;
+ res = FlushFileBuffers(pFile);
+ if (res == 0) {
+ Netlib_Logf(0, "CDbxMDBX::Backup: FlushFileBuffers failed with error code %d (%d)", GetLastError());
+ goto LBL_Fail;
+ }
+
+ CloseHandle(pFile);
+ return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////