sync() after write to avoid losing file data on power off.
This commit is contained in:
@@ -40,6 +40,8 @@
|
||||
#include "WifiChannelSelectors.hpp"
|
||||
#include "PiPedalConfiguration.hpp"
|
||||
#include <grp.h>
|
||||
#include "ofstream_synced.hpp"
|
||||
|
||||
|
||||
#if JACK_HOST
|
||||
#define INSTALL_JACK_SERVICE 1
|
||||
@@ -1346,10 +1348,12 @@ int main(int argc, char **argv)
|
||||
portOption = "0.0.0.0:" + portOption;
|
||||
}
|
||||
Install(prefix, portOption);
|
||||
FileSystemSync();
|
||||
}
|
||||
else if (uninstall)
|
||||
{
|
||||
Uninstall();
|
||||
FileSystemSync();
|
||||
}
|
||||
else if (stop)
|
||||
{
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <string.h>
|
||||
#include <stdexcept>
|
||||
#include "util.hpp"
|
||||
#include "ofstream_synced.hpp"
|
||||
|
||||
using namespace pipedal;
|
||||
using namespace pipedal::implementation;
|
||||
@@ -101,7 +102,7 @@ FileBrowserFilesFeature::FileBrowserFilesFeature()
|
||||
}
|
||||
void BrowserFilesVersionInfo::Save(std::filesystem::path &path)
|
||||
{
|
||||
std::ofstream f{path};
|
||||
pipedal::ofstream_synced f{path};
|
||||
if (!f.is_open())
|
||||
return;
|
||||
f << version << std::endl;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "SystemConfigFile.hpp"
|
||||
#include "SysExec.hpp"
|
||||
#include "WriteTemplateFile.hpp"
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace pipedal;
|
||||
using namespace std;
|
||||
@@ -473,6 +474,7 @@ void pipedal::SetWifiConfig(const WifiConfigSettings &settings)
|
||||
sysExec(SYSTEMCTL_BIN " restart dnsmasq");
|
||||
sysExec(SYSTEMCTL_BIN " enable dnsmasq");
|
||||
}
|
||||
::sync();
|
||||
}
|
||||
|
||||
/*********************************************************************************
|
||||
@@ -563,6 +565,7 @@ void UninstallP2p()
|
||||
SetWifiDirectConfig(wifiDirectConfigSettings);
|
||||
|
||||
}
|
||||
::sync();
|
||||
}
|
||||
|
||||
static void RemoveDhcpcdConfig()
|
||||
@@ -679,6 +682,7 @@ void pipedal::SetWifiDirectConfig(const WifiDirectConfigSettings &settings)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
::sync();
|
||||
}
|
||||
void pipedal::OnWifiReinstall() {
|
||||
WifiDirectConfigSettings settings;
|
||||
@@ -686,6 +690,7 @@ void pipedal::OnWifiReinstall() {
|
||||
if (settings.enable_)
|
||||
{
|
||||
SetWifiDirectConfig(settings);
|
||||
::sync();
|
||||
}
|
||||
}
|
||||
void pipedal::OnWifiUninstall(bool preserveState)
|
||||
@@ -707,6 +712,7 @@ void pipedal::OnWifiUninstall(bool preserveState)
|
||||
settings.Save();
|
||||
}
|
||||
}
|
||||
::sync();
|
||||
}
|
||||
void pipedal::OnWifiInstallComplete()
|
||||
{
|
||||
|
||||
+14
-13
@@ -31,6 +31,7 @@
|
||||
#include "PiPedalUI.hpp"
|
||||
#include "PluginHost.hpp"
|
||||
#include "ss.hpp"
|
||||
#include "ofstream_synced.hpp"
|
||||
|
||||
using namespace pipedal;
|
||||
|
||||
@@ -344,7 +345,7 @@ void Storage::SavePluginPresetIndex()
|
||||
if (pluginPresetIndexChanged)
|
||||
{
|
||||
pluginPresetIndexChanged = false;
|
||||
std::ofstream os;
|
||||
pipedal::ofstream_synced os;
|
||||
auto path = GetPluginPresetsDirectory() / "index.json";
|
||||
os.open(path, std::ios_base::trunc);
|
||||
if (os.fail())
|
||||
@@ -359,7 +360,7 @@ void Storage::SavePluginPresetIndex()
|
||||
|
||||
void Storage::SaveBankIndex()
|
||||
{
|
||||
std::ofstream os;
|
||||
pipedal::ofstream_synced os;
|
||||
os.open(GetIndexFileName(), std::ios_base::trunc);
|
||||
json_writer writer(os, false);
|
||||
writer.write(this->bankIndex);
|
||||
@@ -434,7 +435,7 @@ void Storage::SaveBankFile(const std::string &name, const BankFile &bankFile)
|
||||
}
|
||||
try
|
||||
{
|
||||
std::ofstream s;
|
||||
pipedal::ofstream_synced s;
|
||||
s.open(fileName, std::ios_base::trunc);
|
||||
json_writer writer(s, false);
|
||||
writer.write(bankFile);
|
||||
@@ -721,7 +722,7 @@ void Storage::SaveChannelSelection()
|
||||
auto fileName = this->GetChannelSelectionFileName();
|
||||
try
|
||||
{
|
||||
std::ofstream s(fileName);
|
||||
pipedal::ofstream_synced s(fileName);
|
||||
json_writer writer(s, false);
|
||||
writer.write(this->jackChannelSelection);
|
||||
}
|
||||
@@ -906,7 +907,7 @@ int64_t Storage::UploadBank(BankFile &bankFile, int64_t uploadAfter)
|
||||
bankFile.name(s.str());
|
||||
}
|
||||
std::filesystem::path path = this->GetBankFileName(bankFile.name());
|
||||
std::ofstream f(path);
|
||||
pipedal::ofstream_synced f(path);
|
||||
if (!f.is_open())
|
||||
{
|
||||
throw PiPedalException("Can't write to bank file.");
|
||||
@@ -928,7 +929,7 @@ void Storage::SaveUserSettings()
|
||||
{
|
||||
std::filesystem::path path = this->dataRoot / USER_SETTINGS_FILENAME;
|
||||
{
|
||||
std::ofstream f(path);
|
||||
pipedal::ofstream_synced f(path);
|
||||
if (!f.is_open())
|
||||
{
|
||||
throw PiPedalException("Unable to write to " + ((std::string)path));
|
||||
@@ -964,7 +965,7 @@ void Storage::SetWifiConfigSettings(const WifiConfigSettings &wifiConfigSettings
|
||||
|
||||
std::filesystem::path path = this->dataRoot / WIFI_CONFIG_SETTINGS_FILENAME;
|
||||
{
|
||||
std::ofstream f(path);
|
||||
pipedal::ofstream_synced f(path);
|
||||
if (!f.is_open())
|
||||
{
|
||||
throw PiPedalException("Unable to write to " + ((std::string)path));
|
||||
@@ -1077,7 +1078,7 @@ void Storage::SaveCurrentPreset(const CurrentPreset ¤tPreset)
|
||||
{
|
||||
std::filesystem::path path = GetCurrentPresetPath();
|
||||
|
||||
std::ofstream f(path);
|
||||
pipedal::ofstream_synced f(path);
|
||||
json_writer writer(f, false);
|
||||
writer.write(currentPreset);
|
||||
}
|
||||
@@ -1152,7 +1153,7 @@ void Storage::SavePluginPresets(const std::string &pluginUri, const PluginPreset
|
||||
}
|
||||
auto tempPath = path.string() + ".$$$";
|
||||
{
|
||||
std::ofstream os;
|
||||
pipedal::ofstream_synced os;
|
||||
os.open(tempPath, std::ios_base::trunc);
|
||||
if (os.fail())
|
||||
{
|
||||
@@ -1396,7 +1397,7 @@ std::map<std::string, bool> Storage::GetFavorites() const
|
||||
void Storage::SetFavorites(const std::map<std::string, bool> &favorites)
|
||||
{
|
||||
std::filesystem::path fileName = this->dataRoot / "favorites.json";
|
||||
std::ofstream f;
|
||||
pipedal::ofstream_synced f;
|
||||
f.open(fileName);
|
||||
if (f.is_open())
|
||||
{
|
||||
@@ -1425,7 +1426,7 @@ pipedal::JackServerSettings Storage::GetJackServerSettings()
|
||||
void Storage::SetJackServerSettings(const pipedal::JackServerSettings &jackConfiguration)
|
||||
{
|
||||
std::filesystem::path fileName = this->dataRoot / "AudioConfig.json";
|
||||
std::ofstream f;
|
||||
pipedal::ofstream_synced f;
|
||||
f.open(fileName);
|
||||
if (f.is_open())
|
||||
{
|
||||
@@ -1440,7 +1441,7 @@ void Storage::SetJackServerSettings(const pipedal::JackServerSettings &jackConfi
|
||||
void Storage::SetSystemMidiBindings(const std::vector<MidiBinding> &bindings)
|
||||
{
|
||||
std::filesystem::path fileName = this->dataRoot / "SystemMidiBindings.json";
|
||||
std::ofstream f;
|
||||
pipedal::ofstream_synced f;
|
||||
f.open(fileName);
|
||||
if (f.is_open())
|
||||
{
|
||||
@@ -1714,7 +1715,7 @@ std::string Storage::UploadUserFile(const std::string &directory, const std::str
|
||||
try {
|
||||
std::filesystem::create_directories(path.parent_path());
|
||||
|
||||
std::ofstream f(path, std::ios_base::trunc | std::ios_base::binary);
|
||||
pipedal::ofstream_synced f(path, std::ios_base::trunc | std::ios_base::binary);
|
||||
if (!f.is_open())
|
||||
{
|
||||
throw std::logic_error(SS("Can't create file " << path << "."));
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <fstream>
|
||||
#include "Lv2Log.hpp"
|
||||
#include "ss.hpp"
|
||||
#include "ofstream_synced.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +41,7 @@ void UpdateResults::Load()
|
||||
}
|
||||
void UpdateResults::Save()
|
||||
{
|
||||
std::ofstream f {UPDATE_RESULT_PATH};
|
||||
pipedal::ofstream_synced f {UPDATE_RESULT_PATH};
|
||||
if (f.is_open())
|
||||
{
|
||||
json_writer writer(f);
|
||||
|
||||
+2
-1
@@ -34,6 +34,7 @@
|
||||
#include <algorithm>
|
||||
#include "UpdaterSecurity.hpp"
|
||||
#include "SysExec.hpp"
|
||||
#include "ofstream_synced.hpp"
|
||||
|
||||
using namespace pipedal;
|
||||
namespace fs = std::filesystem;
|
||||
@@ -88,7 +89,7 @@ static void SetCachedUpdateStatus(UpdateStatus &updateStatus)
|
||||
updateStatus.LastUpdateTime(std::chrono::system_clock::now());
|
||||
try
|
||||
{
|
||||
std::ofstream f{UPDATE_STATUS_CACHE_FILE};
|
||||
pipedal::ofstream_synced f{UPDATE_STATUS_CACHE_FILE};
|
||||
json_writer writer{f};
|
||||
writer.write(updateStatus);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <strings.h>
|
||||
#include "Ipv6Helpers.hpp"
|
||||
#include "util.hpp"
|
||||
#include "ofstream_synced.hpp"
|
||||
|
||||
#include "WebServer.hpp"
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <memory>
|
||||
#include "ZipFile.hpp"
|
||||
#include "PiPedalUI.hpp"
|
||||
#include "ofstream_synced.hpp"
|
||||
|
||||
|
||||
#define PRESET_EXTENSION ".piPreset"
|
||||
@@ -439,6 +440,7 @@ public:
|
||||
Lv2Log::error(SS("Unzip failed. " << e.what()));
|
||||
throw;
|
||||
}
|
||||
FileSystemSync();
|
||||
|
||||
} else {
|
||||
outputFileName = this->model->UploadUserFile(directory,patchProperty,filename,req.get_body_input_stream(), req.content_length());
|
||||
|
||||
Reference in New Issue
Block a user