From 93e70ca30b074359696947ee0f0bec11d17f89e8 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 25 Sep 2016 21:01:03 +0200 Subject: [PATCH] fixed search on remote files --- libretroshare/src/file_sharing/p3filelists.cc | 120 +++++++++++++++--- 1 file changed, 100 insertions(+), 20 deletions(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index d3785c29d..329928d26 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -861,39 +861,119 @@ uint32_t p3FileDatabase::watchPeriod() int p3FileDatabase::SearchKeywords(const std::list& keywords, std::list& results,FileSearchFlags flags,const RsPeerId& client_peer_id) { - std::list firesults; + if(flags & RS_FILE_HINTS_LOCAL) { - RS_STACK_MUTEX(mFLSMtx) ; - - mLocalSharedDirs->searchTerms(keywords,firesults) ; - - for(std::list::iterator it(firesults.begin());it!=firesults.end();++it) + std::list firesults; { - void *p=NULL; - convertEntryIndexToPointer(*it,0,p); - *it = (intptr_t)p ; + RS_STACK_MUTEX(mFLSMtx) ; + + mLocalSharedDirs->searchTerms(keywords,firesults) ; + + for(std::list::iterator it(firesults.begin());it!=firesults.end();++it) + { + void *p=NULL; + convertEntryIndexToPointer(*it,0,p); + *it = (intptr_t)p ; + } } + + filterResults(firesults,results,flags,client_peer_id) ; } - return filterResults(firesults,results,flags,client_peer_id) ; + if(flags & RS_FILE_HINTS_REMOTE) + { + std::list firesults; + + { + RS_STACK_MUTEX(mFLSMtx) ; + + for(uint32_t i=0;i local_results; + mRemoteDirectories[i]->searchTerms(keywords,local_results) ; + + for(std::list::iterator it(local_results.begin());it!=local_results.end();++it) + { + void *p=NULL; + convertEntryIndexToPointer(*it,i+1,p); + firesults.push_back((intptr_t)p) ; + } + } + } + + for(std::list::const_iterator rit ( firesults.begin()); rit != firesults.end(); ++rit) + { + DirDetails dd; + + if(!RequestDirDetails ((void*)(intptr_t)*rit,dd,RS_FILE_HINTS_REMOTE)) + continue ; + + results.push_back(dd); + } + + } + + return !results.empty() ; } + int p3FileDatabase::SearchBoolExp(RsRegularExpression::Expression *exp, std::list& results,FileSearchFlags flags,const RsPeerId& client_peer_id) const { - std::list firesults; + if(flags & RS_FILE_HINTS_LOCAL) { - RS_STACK_MUTEX(mFLSMtx) ; - - mLocalSharedDirs->searchBoolExp(exp,firesults) ; - - for(std::list::iterator it(firesults.begin());it!=firesults.end();++it) + std::list firesults; { - void *p=NULL; - convertEntryIndexToPointer(*it,0,p); - *it = (intptr_t)p ; + RS_STACK_MUTEX(mFLSMtx) ; + + mLocalSharedDirs->searchBoolExp(exp,firesults) ; + + for(std::list::iterator it(firesults.begin());it!=firesults.end();++it) + { + void *p=NULL; + convertEntryIndexToPointer(*it,0,p); + *it = (intptr_t)p ; + } + } + + filterResults(firesults,results,flags,client_peer_id) ; + } + + if(flags & RS_FILE_HINTS_REMOTE) + { + std::list firesults; + + { + RS_STACK_MUTEX(mFLSMtx) ; + + for(uint32_t i=0;i local_results; + mRemoteDirectories[i]->searchBoolExp(exp,local_results) ; + + for(std::list::iterator it(local_results.begin());it!=local_results.end();++it) + { + void *p=NULL; + convertEntryIndexToPointer(*it,i+1,p); + firesults.push_back((intptr_t)p) ; + } + + } + } + + for(std::list::const_iterator rit ( firesults.begin()); rit != firesults.end(); ++rit) + { + DirDetails dd; + + if(!RequestDirDetails ((void*)(intptr_t)*rit,dd,RS_FILE_HINTS_REMOTE)) + continue ; + + results.push_back(dd); } } - return filterResults(firesults,results,flags,client_peer_id) ; + return !results.empty() ; + } bool p3FileDatabase::search(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) const {