MCPcopy Create free account
hub / github.com/Icinga/icinga2 / CreateBackupFile

Method CreateBackupFile

lib/cli/nodeutility.cpp:188–212  ·  view source on GitHub ↗

* We generally don't overwrite files without backup before */

Source from the content-addressed store, hash-verified

186 * We generally don't overwrite files without backup before
187 */
188bool NodeUtility::CreateBackupFile(const String& target, bool isPrivate)
189{
190 if (!Utility::PathExists(target))
191 return false;
192
193 String backup = target + ".orig";
194
195 if (Utility::PathExists(backup)) {
196 Log(LogInformation, "cli")
197 << "Backup file '" << backup << "' already exists. Skipping backup.";
198 return false;
199 }
200
201 Utility::CopyFile(target, backup);
202
203#ifndef _WIN32
204 if (isPrivate)
205 chmod(backup.CStr(), 0600);
206#endif /* _WIN32 */
207
208 Log(LogInformation, "cli")
209 << "Created backup file '" << backup << "'.";
210
211 return true;
212}
213
214void NodeUtility::SerializeObject(std::ostream& fp, const Dictionary::Ptr& object)
215{

Callers

nothing calls this directly

Calls 3

PathExistsFunction · 0.85
LogClass · 0.85
CStrMethod · 0.80

Tested by

no test coverage detected