X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/e7c6f85eecb6863620be677106173e1824c9a578..e470c81abda3653a5ef2e3cff7b610aa823fe9b4:/stglibs/conffiles.lib/conffiles.cpp diff --git a/stglibs/conffiles.lib/conffiles.cpp b/stglibs/conffiles.lib/conffiles.cpp index cf7dffee..ea51939a 100644 --- a/stglibs/conffiles.lib/conffiles.cpp +++ b/stglibs/conffiles.lib/conffiles.cpp @@ -36,11 +36,12 @@ #include // E* #include #include +#include #include #include "conffiles.h" -#include "common.h" +#include "stg/common.h" using namespace std; @@ -53,7 +54,8 @@ return (strcasecmp(str1.c_str(), str2.c_str()) < 0); CONFIGFILE::CONFIGFILE(const string & fn, bool nook) : param_val(StringCaseCmp), fileName(fn), - error(0) + error(0), + changed(false) { ifstream f(fileName.c_str()); @@ -141,6 +143,7 @@ return -1; void CONFIGFILE::WriteString(const string & param, const string &val) { param_val[param] = val; +changed = true; } //--------------------------------------------------------------------------- int CONFIGFILE::ReadTime(const string & param, time_t * val, time_t defaultVal) const @@ -344,6 +347,7 @@ void CONFIGFILE::WriteInt(const string & param, int64_t val) string s; x2str(val, s); param_val[param] = s; +changed = true; } //--------------------------------------------------------------------------- int CONFIGFILE::ReadDouble(const string & param, double * val, double defaultVal) const @@ -373,6 +377,7 @@ void CONFIGFILE::WriteDouble(const string & param, double val) char s[30]; snprintf(s, 30, "%f", val); param_val[param] = s; +changed = true; } //--------------------------------------------------------------------------- int CONFIGFILE::Flush(const std::string & path) const @@ -397,6 +402,9 @@ return 0; //--------------------------------------------------------------------------- int CONFIGFILE::Flush() const { +if (!changed) + return 0; + std::string pid; x2str(getpid(), pid); @@ -406,6 +414,8 @@ if (Flush(fileName + "." + pid)) if (rename((fileName + "." + pid).c_str(), fileName.c_str())) return -1; +changed = false; + return 0; } //---------------------------------------------------------------------------