aboutsummaryrefslogtreecommitdiffstats
path: root/src/db/plugins/simple/SimpleDatabasePlugin.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/db/plugins/simple/SimpleDatabasePlugin.cxx')
-rw-r--r--src/db/plugins/simple/SimpleDatabasePlugin.cxx20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.cxx b/src/db/plugins/simple/SimpleDatabasePlugin.cxx
index 97d3e52df..fe712b90b 100644
--- a/src/db/plugins/simple/SimpleDatabasePlugin.cxx
+++ b/src/db/plugins/simple/SimpleDatabasePlugin.cxx
@@ -32,6 +32,8 @@
#include "db/DatabaseLock.hxx"
#include "db/DatabaseError.hxx"
#include "fs/TextFile.hxx"
+#include "fs/output/BufferedOutputStream.hxx"
+#include "fs/output/FileOutputStream.hxx"
#include "config/ConfigData.hxx"
#include "fs/FileSystem.hxx"
#include "util/CharUtil.hxx"
@@ -366,22 +368,16 @@ SimpleDatabase::Save(Error &error)
LogDebug(simple_db_domain, "writing DB");
- FILE *fp = FOpen(path, FOpenMode::WriteText);
- if (!fp) {
- error.FormatErrno("unable to write to db file \"%s\"",
- path_utf8.c_str());
+ FileOutputStream fos(path, error);
+ if (!fos.IsDefined())
return false;
- }
- db_save_internal(fp, *root);
+ BufferedOutputStream bos(fos);
- if (ferror(fp)) {
- error.SetErrno("Failed to write to database file");
- fclose(fp);
- return false;
- }
+ db_save_internal(bos, *root);
- fclose(fp);
+ if (!bos.Flush(error) || !fos.Commit(error))
+ return false;
struct stat st;
if (StatFile(path, st))