Permalink
Browse files

Backup znc.conf once when updating to networks

This copies znc.conf to znc.conf.backup, if that file doesn't exist yet.

Signed-off-by: Uli Schlachter <psychon@znc.in>
  • Loading branch information...
psychon committed Sep 16, 2011
1 parent f97a6a8 commit b07f37b23dc9ed5934d7a8a51e9ec44a16348c38
Showing with 18 additions and 0 deletions.
  1. +1 −0 User.cpp
  2. +16 −0 znc.cpp
  3. +1 −0 znc.h
View
@@ -338,6 +338,7 @@ 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
16 znc.cpp
@@ -984,6 +984,22 @@ size_t CZNC::FilterUncommonModules(set<CModInfo>& ssModules) {
return uNrRemoved;
}
+void CZNC::BackupConfigOnce()
+{
+ static bool didBackup = false;
+ if (didBackup)
+ return;
+ didBackup = true;
+
+ CUtils::PrintAction("Creating a config backup");
+
+ CString sBackup = CDir::ChangeDir(m_sConfigFile, "../znc.conf.backup");
+ if (CFile::Copy(m_sConfigFile, sBackup))
+ CUtils::PrintStatus(true, sBackup);
+ else
+ CUtils::PrintStatus(false, strerror(errno));
+}
+
bool CZNC::ParseConfig(const CString& sConfig)
{
CString s;
View
1 znc.h
@@ -51,6 +51,7 @@ class CZNC {
bool WriteConfig();
bool ParseConfig(const CString& sConfig);
bool RehashConfig(CString& sError);
+ void BackupConfigOnce();
static CString GetVersion();
static CString GetTag(bool bIncludeVersion = true);
CString GetUptime() const;

0 comments on commit b07f37b

Please sign in to comment.