Fixed issue with lost downloads when RetroShare exits (or crashes) during the load of the file transfer items. The pending list was not saved.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5153 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-05-07 14:54:46 +00:00
parent e23f7e1055
commit ec501c6d6a
2 changed files with 52 additions and 8 deletions

View File

@ -1987,14 +1987,7 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
rft->state = fit->second->mState;
fit->second->mTransfer->getFileSources(rft->allPeerIds.ids);
// just avoid uninitialised memory reads
rft->in = 0 ;
rft->cPeerId = "" ;
rft->transferred = fit->second->mCreator->getRecvd();
rft->crate = 0 ;
rft->lrate = 0 ;
rft->trate = 0 ;
rft->ltransfer = 0 ;
// Remove turtle peers from sources, as they are not supposed to survive a reboot of RS, since they are dynamic sources.
// Otherwize, such sources are unknown from the turtle router, at restart, and never get removed.
@ -2016,6 +2009,49 @@ bool ftController::saveList(bool &cleanup, std::list<RsItem *>& saveData)
saveData.push_back(rft);
}
{
/* Save pending list of downloads */
RsStackMutex stack(ctrlMutex); /******* LOCKED ********/
std::list<ftPendingRequest>::iterator pit;
for (pit = mPendingRequests.begin(); pit != mPendingRequests.end(); ++pit)
{
/* make RsFileTransfer item for save list */
RsFileTransfer *rft = NULL;
std::map<std::string,RsFileTransfer*>::iterator rit = mPendingChunkMaps.find(pit->mHash);
if (rit != mPendingChunkMaps.end()) {
/* use item from the not loaded pending list */
rft = new RsFileTransfer(*(rit->second));
} else {
rft = new RsFileTransfer();
/* what data is important? */
rft->file.name = pit->mName;
rft->file.hash = pit->mHash;
rft->file.filesize = pit->mSize;
rft->file.path = RsDirUtil::removeTopDir(pit->mDest); /* remove fname */
rft->flags = pit->mFlags;
rft->allPeerIds.ids = pit->mSrcIds;
}
// Remove turtle peers from sources, as they are not supposed to survive a reboot of RS, since they are dynamic sources.
// Otherwize, such sources are unknown from the turtle router, at restart, and never get removed.
//
for(std::list<std::string>::iterator sit(rft->allPeerIds.ids.begin());sit!=rft->allPeerIds.ids.end();)
if(mTurtle->isTurtlePeer(*sit))
{
std::list<std::string>::iterator sittmp(sit) ;
sit = rft->allPeerIds.ids.erase(sit) ;
}
else
++sit ;
saveData.push_back(rft);
}
}
/* list completed! */
return true;
}

View File

@ -246,7 +246,15 @@ class RsFileTransfer: public RsItem
public:
RsFileTransfer() :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FILE_CONFIG, RS_PKT_SUBTYPE_FILE_TRANSFER)
{
return;
state = 0;
in = 0;
transferred = 0;
crate = 0;
trate = 0;
lrate = 0;
ltransfer = 0;
flags = 0;
chunk_strategy = 0;
}
virtual ~RsFileTransfer();
virtual void clear();