mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-26 15:02:50 +02:00
libconfigfile: update config file atomically when saving
Signed-off-by: Jacek Jendrzej <crashdvb@googlemail.com>
Origin commit data
------------------
Branch: ni/coolstream
Commit: 2afc06a793
Author: Stefan Seyfried <seife@tuxbox-git.slipkontur.de>
Date: 2013-03-03 (Sun, 03 Mar 2013)
------------------
This commit was generated by Migit
This commit is contained in:
committed by
Jacek Jendrzej
parent
d86a178605
commit
f6846b1062
@@ -91,7 +91,9 @@ bool CConfigFile::loadConfig(const std::string & 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)
|
||||
{
|
||||
@@ -104,7 +106,9 @@ bool CConfigFile::saveConfig(const char * const filename)
|
||||
configFile.sync();
|
||||
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;
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user