mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-18 05:50:39 -04:00
Secured the output of .cfg files and cache files. Now closing RS or serializing errors while saving these files cannot corrupt them anymore.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1090 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
207983a9e5
commit
631e3b303e
4 changed files with 50 additions and 32 deletions
|
@ -265,38 +265,33 @@ bool p3MsgService::saveConfiguration()
|
|||
*/
|
||||
|
||||
std::string msgfile = Filename();
|
||||
std::string msgfiletmp = Filename()+".tmp";
|
||||
|
||||
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
RsSerialiser *rss = new RsSerialiser();
|
||||
rss->addSerialType(new RsMsgSerialiser());
|
||||
|
||||
BinFileInterface *out = new BinFileInterface(msgfile.c_str(), BIN_FLAGS_WRITEABLE | BIN_FLAGS_HASH_DATA);
|
||||
pqiarchive *pa_out = new pqiarchive(rss, out, BIN_FLAGS_WRITEABLE | BIN_FLAGS_NO_DELETE);
|
||||
bool written = false;
|
||||
BinFileInterface *out = new BinFileInterface(msgfiletmp.c_str(), BIN_FLAGS_WRITEABLE | BIN_FLAGS_HASH_DATA);
|
||||
pqiarchive *pa_out = new pqiarchive(rss, out, BIN_FLAGS_WRITEABLE | BIN_FLAGS_NO_DELETE);
|
||||
bool written = true;
|
||||
|
||||
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
||||
for(mit = imsg.begin(); mit != imsg.end(); mit++)
|
||||
{
|
||||
if (pa_out -> SendItem(mit->second))
|
||||
{
|
||||
written = true;
|
||||
}
|
||||
|
||||
}
|
||||
written = written && pa_out -> SendItem(mit->second) ;
|
||||
|
||||
for(mit = msgOutgoing.begin(); mit != msgOutgoing.end(); mit++)
|
||||
{
|
||||
if (pa_out -> SendItem(mit->second))
|
||||
{
|
||||
written = true;
|
||||
}
|
||||
|
||||
}
|
||||
written = written && pa_out -> SendItem(mit->second) ;
|
||||
|
||||
setHash(out->gethash());
|
||||
|
||||
delete pa_out;
|
||||
|
||||
if(!written)
|
||||
return false ;
|
||||
|
||||
if(0 != rename(msgfiletmp.c_str(),msgfile.c_str()))
|
||||
return false ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue