summaryrefslogtreecommitdiff
path: root/src/core/db_plain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/db_plain.cpp')
-rw-r--r--src/core/db_plain.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/core/db_plain.cpp b/src/core/db_plain.cpp
index 0499b4fd4..2f20c3fe2 100644
--- a/src/core/db_plain.cpp
+++ b/src/core/db_plain.cpp
@@ -539,6 +539,13 @@ class DBPlain : public Module
void BackupDatabase()
{
+ /* Do not backup a database that doesn't exist */
+ struct stat DBInfo;
+ if (stat(DatabaseFile.c_str(), &DBInfo))
+ {
+ return;
+ }
+
time_t now = time(NULL);
tm *tm = localtime(&now);
@@ -887,6 +894,8 @@ class DBPlain : public Module
EventReturn OnSaveDatabase()
{
+ BackupDatabase();
+
db.open(DatabaseFile.c_str(), std::ios_base::out | std::ios_base::trunc);
if (!db.is_open())
@@ -1172,8 +1181,6 @@ class DBPlain : public Module
db.close();
- BackupDatabase();
-
return EVENT_CONTINUE;
}