summaryrefslogtreecommitdiff
path: root/modules/database/db_flatfile.cpp
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2022-09-15 18:39:37 +0100
committerSadie Powell <sadie@witchery.services>2022-09-15 18:46:51 +0100
commit1664689eb7a99ee71b03c3a4aaa80fda19933dc2 (patch)
tree7577e0228ce79bfc9fcbcb619a205e40189aeccd /modules/database/db_flatfile.cpp
parentb96519d85c703c9c53b3ddf765235400930c21fb (diff)
parentbc101d10de7c2a8cfd8f8ec2b283bf475caa63b8 (diff)
Merge branch '2.0' into 2.1.
Diffstat (limited to 'modules/database/db_flatfile.cpp')
-rw-r--r--modules/database/db_flatfile.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp
index f00694735..de7a5b951 100644
--- a/modules/database/db_flatfile.cpp
+++ b/modules/database/db_flatfile.cpp
@@ -308,10 +308,7 @@ class DBFlatFile : public Module, public Pipe
else
db_name = Anope::DataDir + "/" + Config->GetModule(this)->Get<const Anope::string>("database", "anope.db");
- if (Anope::IsFile(db_name))
- rename(db_name.c_str(), (db_name + ".tmp").c_str());
-
- std::fstream *fs = databases[s_type->GetOwner()] = new std::fstream(db_name.c_str(), std::ios_base::out | std::ios_base::trunc | std::ios_base::binary);
+ std::fstream *fs = databases[s_type->GetOwner()] = new std::fstream((db_name + ".tmp").c_str(), std::ios_base::out | std::ios_base::trunc | std::ios_base::binary);
if (!fs->is_open())
Log(this) << "Unable to open " << db_name << " for writing";
@@ -345,14 +342,15 @@ class DBFlatFile : public Module, public Pipe
this->Write("Unable to write database " + db_name);
f->close();
-
- if (Anope::IsFile((db_name + ".tmp").c_str()))
- rename((db_name + ".tmp").c_str(), db_name.c_str());
}
else
{
f->close();
- unlink((db_name + ".tmp").c_str());
+#ifdef _WIN32
+ /* Windows rename() fails if the file already exists. */
+ remove(db_name.c_str());
+#endif
+ rename((db_name + ".tmp").c_str(), db_name.c_str());
}
delete f;