Added file gards for saving which I forgot in last commit.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1092 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2009-03-21 19:41:46 +00:00
parent a311814714
commit 418478877a

View File

@ -202,6 +202,8 @@ void p3GroupDistrib::loadFileGroups(std::string filename, std::string src, bool
BinInterface *bio = new BinFileInterface(filename.c_str(), BIN_FLAGS_READABLE); BinInterface *bio = new BinFileInterface(filename.c_str(), BIN_FLAGS_READABLE);
pqistreamer *streamer = createStreamer(bio, src, 0); pqistreamer *streamer = createStreamer(bio, src, 0);
std::cerr << "loading file " << filename << std::endl ;
RsItem *item; RsItem *item;
RsDistribGrp *newGrp; RsDistribGrp *newGrp;
RsDistribGrpKey *newKey; RsDistribGrpKey *newKey;
@ -267,6 +269,8 @@ void p3GroupDistrib::loadFileMsgs(std::string filename, uint16_t cacheSubId, std
BinInterface *bio = new BinFileInterface(filename.c_str(), BIN_FLAGS_READABLE); BinInterface *bio = new BinFileInterface(filename.c_str(), BIN_FLAGS_READABLE);
pqistreamer *streamer = createStreamer(bio, src, 0); pqistreamer *streamer = createStreamer(bio, src, 0);
std::cerr << "loading file " << filename << std::endl ;
RsItem *item; RsItem *item;
RsDistribSignedMsg *newMsg; RsDistribSignedMsg *newMsg;
@ -741,9 +745,9 @@ void p3GroupDistrib::locked_publishPendingMsgs()
std::string tmpname = out.str(); std::string tmpname = out.str();
std::string filename = path + "/" + tmpname ; std::string filename = path + "/" + tmpname ;
std::string filenametmp = path + "/" + tmpname + ".tmp";
BinInterface *bio = new BinFileInterface(filename.c_str(), BinInterface *bio = new BinFileInterface(filenametmp.c_str(), BIN_FLAGS_WRITEABLE | BIN_FLAGS_HASH_DATA);
BIN_FLAGS_WRITEABLE | BIN_FLAGS_HASH_DATA);
pqistreamer *streamer = createStreamer(bio, mOwnId, 0); /* messages are deleted! */ pqistreamer *streamer = createStreamer(bio, mOwnId, 0); /* messages are deleted! */
bool resave = false; bool resave = false;
@ -768,7 +772,6 @@ void p3GroupDistrib::locked_publishPendingMsgs()
streamer->SendItem(*it); /* deletes it */ streamer->SendItem(*it); /* deletes it */
streamer->tick(); streamer->tick();
} }
streamer->tick(); /* once more for good luck! */ streamer->tick(); /* once more for good luck! */
@ -785,6 +788,11 @@ void p3GroupDistrib::locked_publishPendingMsgs()
mPendingPublish.clear(); mPendingPublish.clear();
delete streamer; delete streamer;
if(0 != rename(filenametmp.c_str(),filename.c_str()))
std::cerr << "Could not rename file " << filenametmp << " into " << filename << std::endl ;
else
std::cerr << "Successfull wrote file " << filename << std::endl ;
/* indicate not to save for a while */ /* indicate not to save for a while */
mLastPublishTime = now; mLastPublishTime = now;
@ -824,9 +832,9 @@ void p3GroupDistrib::publishDistribGroups()
std::string tmpname = out.str(); std::string tmpname = out.str();
std::string filename = path + "/" + tmpname; std::string filename = path + "/" + tmpname;
std::string filenametmp = path + "/" + tmpname + ".tmp";
BinInterface *bio = new BinFileInterface(filename.c_str(), BinInterface *bio = new BinFileInterface(filenametmp.c_str(), BIN_FLAGS_WRITEABLE | BIN_FLAGS_HASH_DATA);
BIN_FLAGS_WRITEABLE | BIN_FLAGS_HASH_DATA);
pqistreamer *streamer = createStreamer(bio, mOwnId, BIN_FLAGS_NO_DELETE); pqistreamer *streamer = createStreamer(bio, mOwnId, BIN_FLAGS_NO_DELETE);
RsStackMutex stack(distribMtx); /****** STACK MUTEX LOCKED *******/ RsStackMutex stack(distribMtx); /****** STACK MUTEX LOCKED *******/
@ -917,6 +925,11 @@ void p3GroupDistrib::publishDistribGroups()
/* cleanup */ /* cleanup */
delete streamer; delete streamer;
if(0 != rename(filenametmp.c_str(),filename.c_str()))
std::cerr << "Could not rename file " << filenametmp << " into " << filename << std::endl ;
else
std::cerr << "Successfull wrote file " << filename << std::endl ;
/* push file to CacheSource */ /* push file to CacheSource */
refreshCache(newCache); refreshCache(newCache);
} }