From 4507e28404466c7925afccf31d502436908292c3 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 10 Dec 2010 17:39:31 +0200 Subject: [PATCH] =?utf8?q?=D0=92=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20CONFIG?= =?utf8?q?FILE=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20?= =?utf8?q?=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B0=20=D0=BE?= =?utf8?q?=D1=82=D0=BA=D0=B0=D0=B7=D0=B0=20=D0=BE=D1=82=20=D0=B7=D0=B0?= =?utf8?q?=D0=BF=D0=B8=D1=81=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- stglibs/conffiles.lib/conffiles.cpp | 11 ++++++++++- stglibs/conffiles.lib/conffiles.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/stglibs/conffiles.lib/conffiles.cpp b/stglibs/conffiles.lib/conffiles.cpp index cf7dffee..6b462ee0 100644 --- a/stglibs/conffiles.lib/conffiles.cpp +++ b/stglibs/conffiles.lib/conffiles.cpp @@ -53,7 +53,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 +142,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 +346,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 +376,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 +401,9 @@ return 0; //--------------------------------------------------------------------------- int CONFIGFILE::Flush() const { +if (!changed) + return 0; + std::string pid; x2str(getpid(), pid); @@ -406,6 +413,8 @@ if (Flush(fileName + "." + pid)) if (rename((fileName + "." + pid).c_str(), fileName.c_str())) return -1; +changed = false; + return 0; } //--------------------------------------------------------------------------- diff --git a/stglibs/conffiles.lib/conffiles.h b/stglibs/conffiles.lib/conffiles.h index 77a696d0..ae2c8fd0 100644 --- a/stglibs/conffiles.lib/conffiles.h +++ b/stglibs/conffiles.lib/conffiles.h @@ -76,6 +76,7 @@ private: map param_val; string fileName; mutable int error; + mutable bool changed; int Flush(const std::string & path) const; }; -- 2.44.2