mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
implemented a short circuit to local cache transfers. This saves a large number of file descriptors, and improves reactivity of the software
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2876 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
20908b2c48
commit
c87844277a
@ -609,7 +609,24 @@ bool ftController::moveFile(const std::string& source,const std::string& dest)
|
||||
#endif
|
||||
// We could not rename, probably because we're dealing with different file systems.
|
||||
// Let's copy then.
|
||||
|
||||
if(!copyFile(source,dest))
|
||||
return false ;
|
||||
|
||||
// copy was successfull, let's delete the original
|
||||
std::cerr << "deleting original file " << source << std::endl ;
|
||||
|
||||
if(0 == remove(source.c_str()))
|
||||
return true ;
|
||||
else
|
||||
{
|
||||
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "File erase error", "Error while removing hash file " + dest + "\nRead-only file system ?");
|
||||
return false ;
|
||||
}
|
||||
}
|
||||
|
||||
bool ftController::copyFile(const std::string& source,const std::string& dest)
|
||||
{
|
||||
std::string error ;
|
||||
|
||||
static const int BUFF_SIZE = 10485760 ; // 10 MB buffer to speed things up.
|
||||
@ -648,21 +665,13 @@ bool ftController::moveFile(const std::string& source,const std::string& dest)
|
||||
fclose(in) ;
|
||||
fclose(out) ;
|
||||
|
||||
// copy was successfull, let's delete the original
|
||||
std::cerr << "deleting original file " << source << std::endl ;
|
||||
|
||||
free(buffer) ;
|
||||
|
||||
if(0 == remove(source.c_str()))
|
||||
return true ;
|
||||
else
|
||||
{
|
||||
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "File erase error", "Error while removing hash file " + dest + "\nRead-only file system ?");
|
||||
return false ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ftController::completeFile(std::string hash)
|
||||
{
|
||||
/* variables... so we can drop mutex later */
|
||||
@ -1709,15 +1718,34 @@ void ftController::statusChange(const std::list<pqipeer> &plist)
|
||||
bool ftController::RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size)
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "ftController::RequestCacheFile(" << id << ",";
|
||||
std::cerr << path << "," << hash << "," << size << ")";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "ftController::RequestCacheFile(" << id << ",";
|
||||
std::cerr << path << "," << hash << "," << size << ")";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* Request File */
|
||||
std::list<std::string> ids;
|
||||
ids.push_back(id);
|
||||
|
||||
FileInfo info ;
|
||||
if(mSearch->search(hash, RS_FILE_HINTS_CACHE, info))
|
||||
{
|
||||
#ifdef CONTROL_DEBUG
|
||||
std::cerr << "I already have this file:" << std::endl ;
|
||||
std::cerr << " path: " << info.path << std::endl ;
|
||||
std::cerr << " fname: " << info.fname << std::endl ;
|
||||
std::cerr << " hash: " << info.hash << std::endl ;
|
||||
|
||||
std::cerr << "Copying it !!" << std::endl ;
|
||||
#endif
|
||||
|
||||
if(copyFile(info.path,path+"/"+hash))
|
||||
{
|
||||
CompletedCache(hash);
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
|
||||
FileRequest(hash, hash, size, path, RS_FILE_HINTS_CACHE | RS_FILE_HINTS_NO_SEARCH, ids);
|
||||
|
||||
return true;
|
||||
|
@ -175,6 +175,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiMonitor, pu
|
||||
bool FileDetails(std::string hash, FileInfo &info);
|
||||
|
||||
bool moveFile(const std::string& source,const std::string& dest) ;
|
||||
bool copyFile(const std::string& source,const std::string& dest) ;
|
||||
|
||||
/***************************************************************/
|
||||
/********************** Cache Transfer *************************/
|
||||
|
Loading…
Reference in New Issue
Block a user