Write out cache file to temporary file + atomic replace
[pingcheck] / src / dns / dnscache.cpp
index c097aea..0e9a270 100644 (file)
@@ -26,6 +26,7 @@
 #include <fstream>
 #include <logfunc.hpp>
 #include <filefunc.hxx>   // I2n::file_exists
+#include <tmpfstream.hpp>
 #include <boost/foreach.hpp>
 #include <boost/bind.hpp>
 #include <boost/asio/placeholders.hpp>
@@ -137,7 +138,7 @@ void DnsCache::save_to_cachefile()
             std::string cache_save_time_str = boost::posix_time::to_iso_string(
                             boost::posix_time::second_clock::universal_time() );
 
-            std::ofstream ofs( CacheFile.c_str() );
+            I2n::tmpofcopystream ofs( CacheFile.c_str() );
             boost::archive::xml_oarchive oa(ofs);
             oa & BOOST_SERIALIZATION_NVP(IpCache);
             oa & BOOST_SERIALIZATION_NVP(CnameCache);