diff --git a/znc.cpp b/znc.cpp index d4dc332d..fc782ce6 100644 --- a/znc.cpp +++ b/znc.cpp @@ -412,7 +412,6 @@ void CZNC::InitDirs(const CString& sArgvPath, const CString& sDataDir) { // Other dirs that we use m_sConfPath = m_sZNCPath + "/configs"; - m_sConfBackupPath = m_sConfPath + "/backups"; m_sModPath = m_sZNCPath + "/modules"; m_sUserPath = m_sZNCPath + "/users"; } @@ -436,10 +435,25 @@ CString CZNC::ExpandConfigPath(const CString& sConfigFile) { return sRetPath; } -bool CZNC::WriteConfig() { - CFile File(m_sConfigFile); +bool CZNC::BackupConfig() const { + CString sBackup = GetConfigFile() + "-backup"; - if (!File.Copy(GetConfBackupPath() + "/" + File.GetShortName() + "-" + CString(time(NULL)))) { + // Create a new backup overwriting an old one we might have + if (CFile::Copy(m_sConfigFile, sBackup, true)) + return true; + + // Don't abort if no config file exists + if (!CFile::Exists(m_sConfigFile)) + // No backup because we got nothing to backup + return true; + + return false; +} + +bool CZNC::WriteConfig() { + CFile File(GetConfigFile()); + + if (!BackupConfig()) { return false; } diff --git a/znc.h b/znc.h index ebdc2a6e..9ca3a6ed 100644 --- a/znc.h +++ b/znc.h @@ -142,7 +142,6 @@ public: const CString& GetHomePath() const { if (!CFile::Exists(m_sHomePath)) { CUtils::MakeDir(m_sHomePath); } return m_sHomePath; } const CString& GetZNCPath() const { if (!CFile::Exists(m_sZNCPath)) { CUtils::MakeDir(m_sZNCPath); } return m_sZNCPath; } const CString& GetConfPath() const { if (!CFile::Exists(m_sConfPath)) { CUtils::MakeDir(m_sConfPath); } return m_sConfPath; } - const CString& GetConfBackupPath() const { if (!CFile::Exists(m_sConfBackupPath)) { CUtils::MakeDir(m_sConfBackupPath); } return m_sConfBackupPath; } const CString& GetUserPath() const { if (!CFile::Exists(m_sUserPath)) { CUtils::MakeDir(m_sUserPath); } return m_sUserPath; } CString GetPemLocation() const { return GetZNCPath() + "/znc.pem"; } const CString& GetConfigFile() const { return m_sConfigFile; } @@ -179,6 +178,8 @@ private: bool DoRehash(CString& sError); // Returns true if something was done bool HandleUserDeletion(); + // Backup znc.conf + bool BackupConfig() const; protected: bool m_bNeedRehash; @@ -192,7 +193,6 @@ protected: CString m_sHomePath; CString m_sZNCPath; CString m_sConfPath; - CString m_sConfBackupPath; CString m_sUserPath; CString m_sConfigFile;