mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-26 23:13:13 +02:00
libconfigfile: update config file atomically when saving
Signed-off-by: Jacek Jendrzej <crashdvb@googlemail.com>
This commit is contained in:
committed by
Jacek Jendrzej
parent
b6df7de7f7
commit
2afc06a793
@@ -91,7 +91,9 @@ bool CConfigFile::loadConfig(const std::string & filename)
|
|||||||
|
|
||||||
bool CConfigFile::saveConfig(const char * const filename)
|
bool CConfigFile::saveConfig(const char * const filename)
|
||||||
{
|
{
|
||||||
std::fstream configFile(filename);
|
const char *tmpname = (std::string(filename) + ".tmp").c_str();
|
||||||
|
unlink(tmpname);
|
||||||
|
std::fstream configFile(tmpname, std::ios::out);
|
||||||
|
|
||||||
if (configFile != NULL)
|
if (configFile != NULL)
|
||||||
{
|
{
|
||||||
@@ -104,7 +106,9 @@ bool CConfigFile::saveConfig(const char * const filename)
|
|||||||
configFile.sync();
|
configFile.sync();
|
||||||
configFile.close();
|
configFile.close();
|
||||||
|
|
||||||
chmod(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
chmod(tmpname, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||||
|
/* TODO: check available space? */
|
||||||
|
rename(tmpname, filename);
|
||||||
|
|
||||||
modifiedFlag = false;
|
modifiedFlag = false;
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user