| 12 | constexpr const char* kHostSettingsFile = "host_settings.json"; |
| 13 | |
| 14 | bool WriteFileAtomic(const fs::path& target, const std::string& contents) { |
| 15 | fs::path tmp = target; |
| 16 | tmp += ".tmp"; |
| 17 | std::error_code ec; |
| 18 | fs::create_directories(target.parent_path(), ec); |
| 19 | { |
| 20 | std::ofstream out(tmp, std::ios::binary | std::ios::trunc); |
| 21 | if (!out) return false; |
| 22 | out.write(contents.data(), static_cast<std::streamsize>(contents.size())); |
| 23 | if (!out) return false; |
| 24 | } |
| 25 | fs::rename(tmp, target, ec); |
| 26 | if (ec) { |
| 27 | fs::remove(tmp, ec); |
| 28 | return false; |
| 29 | } |
| 30 | return true; |
| 31 | } |
| 32 | } // namespace |
| 33 | |
| 34 | nlohmann::json ToJson(const LlmModelMapping& mapping) { |
no test coverage detected