sync() after write to avoid losing file data on power off.
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include "autoptr_vector.h"
|
||||
#include <unordered_map>
|
||||
#include <fstream>
|
||||
#include "ofstream_synced.hpp"
|
||||
|
||||
namespace config_serializer
|
||||
{
|
||||
@@ -256,7 +257,7 @@ namespace config_serializer
|
||||
}
|
||||
void Save(const std::string &path)
|
||||
{
|
||||
std::ofstream f;
|
||||
pipedal::ofstream_synced f;
|
||||
f.open(path);
|
||||
if (!f.is_open())
|
||||
{
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace pipedal
|
||||
{
|
||||
void FileSystemSync();
|
||||
|
||||
class ofstream_synced : public std::ofstream
|
||||
{
|
||||
public:
|
||||
ofstream_synced() {}
|
||||
|
||||
explicit ofstream_synced(const std::string &filename, ios_base::openmode mode = ios_base::out)
|
||||
: std::ofstream(filename, mode)
|
||||
{
|
||||
}
|
||||
explicit ofstream_synced(const char *filename, ios_base::openmode mode = ios_base::out)
|
||||
: std::ofstream(filename, mode)
|
||||
{
|
||||
}
|
||||
~ofstream_synced();
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user