sync() after write to avoid losing file data on power off.

This commit is contained in:
Robin Davies
2024-09-01 09:53:32 -04:00
parent abb8a1a53c
commit b8c4fafd3a
21 changed files with 102 additions and 34 deletions
+2 -1
View File
@@ -6,6 +6,7 @@
#include <stdexcept>
#include "ss.hpp"
#include <chrono>
#include "ofstream_synced.hpp"
namespace impl {
@@ -72,7 +73,7 @@ public:
f << "trace: " << message << std::endl;
}
private:
std::ofstream f;
pipedal::ofstream_synced f;
};
class SystemdDBusLogger : public IDBusLogger {
+3 -2
View File
@@ -10,6 +10,7 @@
#include "ChannelInfo.hpp"
#include "DBusLog.hpp"
#include <sys/stat.h>
#include "ofstream_synced.hpp"
using namespace pipedal;
P2pSettings::P2pSettings(const std::filesystem::path&configDirectoryPath, const std::filesystem::path&varDirectoryPath)
@@ -193,7 +194,7 @@ void P2pSettings::Load()
}
static void openWithPerms(
std::ofstream &f,
pipedal::ofstream_synced &f,
const std::filesystem::path &path,
std::filesystem::perms perms =
std::filesystem::perms::owner_read | std::filesystem::perms::owner_write |
@@ -221,7 +222,7 @@ void P2pSettings::Save()
{
auto filename = config_filename();
try {
std::ofstream f;
pipedal::ofstream_synced f;
openWithPerms(f,filename);
if (!f.is_open())