@@ -2002,24 +2002,19 @@ CAddrDB::CAddrDB()
20022002
20032003bool CAddrDB::Write (const CAddrMan& addr)
20042004{
2005- // Generate random temporary filename
2006- unsigned short randv = 0 ;
2007- RAND_bytes ((unsigned char *)&randv, sizeof (randv));
2008- std::string tmpfn = strprintf (" peers.dat.%04x" , randv);
2009-
20102005 // serialize addresses, checksum data up to that point, then append csum
20112006 CDataStream ssPeers (SER_DISK, CLIENT_VERSION);
20122007 ssPeers << FLATDATA (Params ().MessageStart ());
20132008 ssPeers << addr;
20142009 uint256 hash = Hash (ssPeers.begin (), ssPeers.end ());
20152010 ssPeers << hash;
20162011
2017- // open temp output file, and associate with CAutoFile
2018- boost::filesystem::path pathTmp = GetDataDir () / tmpfn ;
2019- FILE *file = fopen (pathTmp .string ().c_str (), " wb" );
2012+ // open output file, and associate with CAutoFile
2013+ boost::filesystem::path pathAddr = GetDataDir () / " peers.dat " ;
2014+ FILE *file = fopen (pathAddr .string ().c_str (), " wb" );
20202015 CAutoFile fileout = CAutoFile (file, SER_DISK, CLIENT_VERSION);
20212016 if (!fileout)
2022- return error (" %s : Failed to open file %s" , __func__, pathTmp .string ());
2017+ return error (" %s : Failed to open file %s" , __func__, pathAddr .string ());
20232018
20242019 // Write and commit header, data
20252020 try {
@@ -2031,10 +2026,6 @@ bool CAddrDB::Write(const CAddrMan& addr)
20312026 FileCommit (fileout);
20322027 fileout.fclose ();
20332028
2034- // replace existing peers.dat, if any, with new peers.dat.XXXX
2035- if (!RenameOver (pathTmp, pathAddr))
2036- return error (" %s : Rename-into-place failed" , __func__);
2037-
20382029 return true ;
20392030}
20402031
0 commit comments