Permalink
Browse files

Backup znc.conf when upgrading ZNC.

Now ZNC saves its version to znc.conf.
When ZNC tries to load znc.conf, it compares stored version with running
one. If the stored version is older, make a backup.
  • Loading branch information...
1 parent e029dde commit 689c330d51ecfbc9588c686fc95ad417903f64fb Alexey Sokolov committed Sep 16, 2011
Showing with 15 additions and 5 deletions.
  1. +0 −1 User.cpp
  2. +14 −3 znc.cpp
  3. +1 −1 znc.h
View
@@ -338,7 +338,6 @@ bool CUser::ParseConfig(CConfig* pConfig, CString& sError) {
}
if (pNetwork) {
- CZNC::Get().BackupConfigOnce();
CUtils::PrintMessage("NOTICE: Found deprecated config, upgrading to a network");
if (!pNetwork->ParseConfig(pConfig, sError, true)) {
View
@@ -433,6 +433,7 @@ bool CZNC::WriteConfig() {
config.AddKeyValuePair("MaxBufferSize", CString(m_uiMaxBufferSize));
config.AddKeyValuePair("SSLCertFile", CString(m_sSSLCertFile));
config.AddKeyValuePair("ProtectWebSessions", CString(m_bProtectWebSessions));
+ config.AddKeyValuePair("Version", CString(VERSION, 3));
for (size_t l = 0; l < m_vpListeners.size(); l++) {
CListener* pListener = m_vpListeners[l];
@@ -984,16 +985,15 @@ size_t CZNC::FilterUncommonModules(set<CModInfo>& ssModules) {
return uNrRemoved;
}
-void CZNC::BackupConfigOnce()
-{
+void CZNC::BackupConfigOnce(const CString& sSuffix) {
static bool didBackup = false;
if (didBackup)
return;
didBackup = true;
CUtils::PrintAction("Creating a config backup");
- CString sBackup = CDir::ChangeDir(m_sConfigFile, "../znc.conf.backup");
+ CString sBackup = CDir::ChangeDir(m_sConfigFile, "../znc.conf." + sSuffix);
if (CFile::Copy(m_sConfigFile, sBackup))
CUtils::PrintStatus(true, sBackup);
else
@@ -1085,6 +1085,17 @@ bool CZNC::DoRehash(CString& sError)
}
CUtils::PrintStatus(true);
+ CString sSavedVersion;
+ config.FindStringEntry("version", sSavedVersion);
+ double fSavedVersion = sSavedVersion.ToDouble();
+ if (fSavedVersion < VERSION) {
+ if (sSavedVersion.empty()) {
+ sSavedVersion = "< 0.203";
+ }
+ CUtils::PrintMessage("Found old config from ZNC " + sSavedVersion + ". Saving a backup of it.");
+ BackupConfigOnce("pre-" + CString(VERSION, 3));
+ }
+
m_vsBindHosts.clear();
m_vsMotd.clear();
View
@@ -51,7 +51,7 @@ class CZNC {
bool WriteConfig();
bool ParseConfig(const CString& sConfig);
bool RehashConfig(CString& sError);
- void BackupConfigOnce();
+ void BackupConfigOnce(const CString& sSuffix);
static CString GetVersion();
static CString GetTag(bool bIncludeVersion = true);
CString GetUptime() const;

0 comments on commit 689c330

Please sign in to comment.