diff --git a/src/cache_manager.cc b/src/cache_manager.cc index a276f765..cf21a545 100644 --- a/src/cache_manager.cc +++ b/src/cache_manager.cc @@ -136,9 +136,5 @@ void WriteToCache(Config* config, IndexFile& file) { } std::string indexed_content = Serialize(file); - std::ofstream cache; - cache.open(cache_basename + ".json"); - assert(cache.good()); - cache << indexed_content; - cache.close(); + WriteToFile(cache_basename + ".json", indexed_content); } diff --git a/src/utils.cc b/src/utils.cc index f165a572..c98658ac 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -462,7 +462,9 @@ void Fail(const std::string& message) { } void WriteToFile(const std::string& filename, const std::string& content) { - std::ofstream file(filename); + std::ofstream file(filename, + std::ios::out | std::ios::trunc | std::ios::binary); + assert(file.good()); file << content; }