`ConfigObjectUtility`: Use `AtomicFile` to store object config files

This commit is contained in:
Yonas Habteab 2024-03-01 10:11:17 +01:00
parent c5c7925d8a
commit 2218ebd6b0
1 changed files with 3 additions and 3 deletions

View File

@ -5,6 +5,7 @@
#include "remote/apilistener.hpp"
#include "config/configcompiler.hpp"
#include "config/configitem.hpp"
#include "base/atomic-file.hpp"
#include "base/configwriter.hpp"
#include "base/exception.hpp"
#include "base/dependencygraph.hpp"
@ -198,11 +199,10 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full
return false;
}
// AtomicFile doesn't create not yet existing directories, so we have to do it by ourselves.
Utility::MkDirP(Utility::DirName(path), 0700);
std::ofstream fp(path.CStr(), std::ofstream::out | std::ostream::trunc);
fp << config;
fp.close();
AtomicFile::Write(path, 0644, config);
std::unique_ptr<Expression> expr = ConfigCompiler::CompileFile(path, String(), "_api");