added writing of public keyring to a tmp file + rename, to avoid corrupting it when RS stops during the whole operation

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5496 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-09-01 14:09:20 +00:00
parent 32f918c213
commit f85adfce72

View File

@ -1398,15 +1398,23 @@ bool PGPHandler::locked_syncPublicKeyring()
// Now check if the pubring was locally modified, which needs saving it again
if(_pubring_changed)
{
std::string tmp_keyring_file = _pubring_path + ".tmp" ;
std::cerr << "Local changes in public keyring. Writing to disk..." << std::endl;
if(!ops_write_keyring_to_file(_pubring,ops_false,_pubring_path.c_str(),ops_true))
std::cerr << "Cannot write public keyring. Disk full? Disk quota exceeded?" << std::endl;
else
if(!ops_write_keyring_to_file(_pubring,ops_false,tmp_keyring_file.c_str(),ops_true))
{
std::cerr << "Done." << std::endl;
_pubring_last_update_time = time(NULL) ; // should we get this value from the disk instead??
_pubring_changed = false ;
std::cerr << "Cannot write public keyring tmp file. Disk full? Disk quota exceeded?" << std::endl;
return false ;
}
if(!RsDirUtil::renameFile(tmp_keyring_file,_pubring_path))
{
std::cerr << "Cannot rename tmp pubring file " << tmp_keyring_file << " into actual pubring file " << _pubring_path << ". Check writing permissions?!?" << std::endl;
return false ;
}
std::cerr << "Done." << std::endl;
_pubring_last_update_time = time(NULL) ; // should we get this value from the disk instead??
_pubring_changed = false ;
}
return true ;
}