-add support for searching and display directories

-downloading directories from search dialog not implemented yet
-needs more code clean and beautify the directory tree

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1566 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
alexandrut 2009-08-25 20:49:50 +00:00
parent 1292a69ccf
commit 10d44a15b8
13 changed files with 564 additions and 431 deletions

View file

@ -1,16 +1,16 @@
/*
* RetroShare FileCache Module: fimonitor.cc
*
*
* Copyright 2004-2007 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
@ -44,8 +44,8 @@
// ***********/
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in,std::string cachedir, std::string pid)
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fi(pid),
pendingDirs(false), pendingForceCacheWrite(false),
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fi(pid),
pendingDirs(false), pendingForceCacheWrite(false),
mForceCheck(false), mInCheck(false),cb(cb_in)
{
@ -59,7 +59,7 @@ FileIndexMonitor::~FileIndexMonitor()
return;
}
int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags)
int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags)
{
results.clear();
std::list<FileEntry *> firesults;
@ -69,7 +69,7 @@ int FileIndexMonitor::SearchKeywords(std::list<std::string> keywords, std::list<
return filterResults(firesults,results,flags) ;
}
int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<FileDetail>& results,uint32_t flags) const
int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<DirDetails>& results,uint32_t flags) const
{
results.clear();
std::list<FileEntry *> firesults;
@ -79,29 +79,22 @@ int FileIndexMonitor::SearchBoolExp(Expression *exp, std::list<FileDetail>& resu
return filterResults(firesults,results,flags) ;
}
int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<FileDetail>& results,uint32_t flags) const
int FileIndexMonitor::filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,uint32_t flags) const
{
time_t now = time(NULL) ;
/* translate/filter results */
for(std::list<FileEntry*>::const_iterator rit(firesults.begin()); rit != firesults.end(); ++rit)
{
DirDetails details ;
RequestDirDetails((*rit)->parent,details,0) ;
DirDetails pdetails ;
RequestDirDetails((*rit)->parent,pdetails,0) ;
DirDetails cdetails ;
RequestDirDetails (*rit,cdetails,0);
if(( details.flags & flags & (DIR_FLAGS_BROWSABLE | DIR_FLAGS_NETWORK_WIDE) ) > 0 )
if ( ((cdetails.type == DIR_TYPE_FILE) && (pdetails.flags & flags & (DIR_FLAGS_BROWSABLE | DIR_FLAGS_NETWORK_WIDE)) > 0) ||
((cdetails.type == DIR_TYPE_DIR) && (cdetails.flags & flags & (DIR_FLAGS_BROWSABLE | DIR_FLAGS_NETWORK_WIDE)) > 0) )
{
FileDetail fd;
fd.id = "Local"; //localId;
fd.name = (*rit)->name;
fd.hash = (*rit)->hash;
fd.path = ""; /* TODO */
fd.size = (*rit)->size;
fd.age = now - (*rit)->modtime;
fd.rank = (*rit)->pop;
results.push_back(fd);
cdetails.id = "Local";
results.push_back(cdetails);
}
}
return !results.empty() ;
@ -198,7 +191,7 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto
//fi.root->name = data.pid;
/* More error checking needed here! */
std::string name = data.name ; // this trick allows to load the complete file. Not the one being shared.
name[name.length()-1] = 'c' ;
@ -218,7 +211,7 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto
std::cerr << std::endl;
#endif
}
} fiMutex.unlock(); /* UNLOCKED DIRS */
if (ok)
@ -306,7 +299,7 @@ void FileIndexMonitor::updateCycle()
/* reset start time */
startstamp = time(NULL);
}
/* Handle a Single out-of-date directory */
time_t stamp = time(NULL);
@ -332,7 +325,7 @@ void FileIndexMonitor::updateCycle()
FileEntry fe;
/* entries that need to be checked properly */
std::list<FileEntry> filesToHash;
std::list<FileEntry> filesToHash;
std::list<FileEntry>::iterator hit;
/* determine the full root path */
@ -347,7 +340,7 @@ void FileIndexMonitor::updateCycle()
{
realpath += "/" + remdir;
}
#ifdef FIM_DEBUG
@ -502,11 +495,11 @@ void FileIndexMonitor::updateCycle()
* next files - hashing them, before adding into the system.
*/
/* for safety - blank out data we cannot use (TODO) */
olddir = NULL;
olddir = NULL;
/* close directory */
closedir(dir);
/* unlock dirs */
fiMutex.unlock();
@ -530,7 +523,7 @@ void FileIndexMonitor::updateCycle()
std::cerr << std::endl;
}
#endif
/* update files */
for(hit = filesToHash.begin(); hit != filesToHash.end(); hit++)
{
@ -564,14 +557,14 @@ void FileIndexMonitor::updateCycle()
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
}
if (filesToHash.size() > 0)
cb->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0);
}
fiMutex.lock(); { /* LOCKED DIRS */
/* finished update cycle - cleanup extra dirs/files that
/* finished update cycle - cleanup extra dirs/files that
* have not had their timestamps updated.
*/
@ -586,7 +579,7 @@ void FileIndexMonitor::updateCycle()
fi.printFileIndex(std::cerr);
#endif
/* now if we have changed things -> restore file/hash it/and
/* now if we have changed things -> restore file/hash it/and
* tell the CacheSource
*/
@ -596,11 +589,11 @@ void FileIndexMonitor::updateCycle()
fiMods = true;
}
}
}
if (fiMods)
locked_saveFileIndexes() ;
fiMutex.unlock(); /* UNLOCKED DIRS */
{
@ -620,12 +613,12 @@ void FileIndexMonitor::locked_saveFileIndexes()
// Two files are saved: one with only browsable dirs, which will be shared by the cache system,
// and one with the complete file collection.
//
std::ostringstream out;
std::ostringstream out;
out << "fc-own-" << time(NULL) << ".rsfb";
std::string tmpname_browsable = out.str();
std::string fname_browsable = path + "/" + tmpname_browsable;
std::ostringstream out2;
std::ostringstream out2;
out2 << "fc-own-" << time(NULL) << ".rsfc";
std::string tmpname_total = out2.str();
std::string fname_total = path + "/" + tmpname_total;
@ -693,7 +686,7 @@ void FileIndexMonitor::updateShareFlags(const SharedDirInfo& dir)
#ifdef FIM_DEBUG
std::cerr << "*** FileIndexMonitor: Updating flags for " << dir.filename << " to " << dir.shareflags << std::endl ;
#endif
{
{
RsStackMutex stack(fiMutex) ; /* LOCKED DIRS */
for(std::list<SharedDirInfo>::iterator it(pendingDirList.begin());it!=pendingDirList.end();++it)
@ -828,14 +821,14 @@ bool FileIndexMonitor::internal_setSharedDirectories()
fiMutex.unlock(); /* UNLOCKED DIRS */
return false;
}
mForceCheck = false;
pendingDirs = false;
pendingForceCacheWrite = true;
/* clear old directories */
directoryMap.clear();
/* iterate through the directories */
std::list<SharedDirInfo>::iterator it;
std::map<std::string, SharedDirInfo>::const_iterator cit;
@ -844,7 +837,7 @@ bool FileIndexMonitor::internal_setSharedDirectories()
/* get the head directory */
std::string root_dir = (*it).filename;
std::string top_dir = RsDirUtil::getTopDir(root_dir);
/* if unique -> add, else add modifier */
bool unique = false;
for(i = 0; !unique; i++)
@ -878,20 +871,20 @@ bool FileIndexMonitor::internal_setSharedDirectories()
}
fi.setRootDirectories(topdirs, 0);
locked_saveFileIndexes() ;
fiMutex.unlock(); /* UNLOCKED DIRS */
return true;
}
/* lookup directory function */
std::string FileIndexMonitor::locked_findRealRoot(std::string rootdir) const
{
/**** MUST ALREADY BE LOCKED ****/
/**** MUST ALREADY BE LOCKED ****/
std::string realroot = "";
std::map<std::string, SharedDirInfo>::const_iterator cit;
@ -933,7 +926,7 @@ bool FileIndexMonitor::hashFile(std::string fullpath, FileEntry &fent)
}
/* reading failed for some reason */
if (ferror(fd))
if (ferror(fd))
{
delete sha_ctx;
fclose(fd);
@ -942,7 +935,7 @@ bool FileIndexMonitor::hashFile(std::string fullpath, FileEntry &fent)
SHA1_Final(&sha_buf[0], sha_ctx);
/* TODO: Actually we should store the hash data as binary ...
/* TODO: Actually we should store the hash data as binary ...
* but then it shouldn't be put in a string.
*/

View file

@ -1,16 +1,16 @@
/*
* RetroShare FileCache Module: fimonitor.h
*
*
* Copyright 2004-2007 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
@ -75,9 +75,9 @@ class FileIndexMonitor: public CacheSource, public RsThread
/* external interface for filetransfer */
bool findLocalFile(std::string hash,uint32_t f, std::string &fullpath, uint64_t &size) const;
int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags) ;
int SearchBoolExp(Expression *exp, std::list<FileDetail> &results,uint32_t flags) const ;
int filterResults(std::list<FileEntry*>& firesults,std::list<FileDetail>& results,uint32_t flags) const ;
int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) ;
int SearchBoolExp(Expression *exp, std::list<DirDetails> &results,uint32_t flags) const ;
int filterResults(std::list<FileEntry*>& firesults,std::list<DirDetails>& results,uint32_t flags) const ;
/* external interface for local access to files */

View file

@ -44,20 +44,20 @@
static RsMutex FIndexPtrMtx ;
std::set<void*> FileIndex::_pointers ;
void FileIndex::registerEntry(void*p)
{
void FileIndex::registerEntry(void*p)
{
RsStackMutex m(FIndexPtrMtx) ;
_pointers.insert(p) ;
_pointers.insert(p) ;
}
void FileIndex::unregisterEntry(void*p)
{
void FileIndex::unregisterEntry(void*p)
{
RsStackMutex m(FIndexPtrMtx) ;
_pointers.erase(p) ;
_pointers.erase(p) ;
}
bool FileIndex::isValid(void*p)
{
bool FileIndex::isValid(void*p)
{
RsStackMutex m(FIndexPtrMtx) ;
return _pointers.find(p) != _pointers.end() ;
return _pointers.find(p) != _pointers.end() ;
}
DirEntry::~DirEntry()
@ -291,7 +291,7 @@ int DirEntry::removeOldEntries(time_t old, bool recursive)
DirEntry *DirEntry::findOldDirectory(time_t old)
{
/* check if one of our directories is old ...
/* check if one of our directories is old ...
*/
/* get all dirs with old time */
@ -480,7 +480,7 @@ int FileEntry::print(std::ostream &out)
else
out << "[MISSING PARENT]";
out << " " << name;
out << " " << name;
out << " [ s: " << size << " ] ==> ";
out << " [ " << hash << " ]";
out << std::endl;
@ -645,7 +645,7 @@ int FileIndex::removeOldDirectory(std::string fpath, std::string name, time_t
std::cerr << std::endl;
#endif
/* because of this find - we cannot get a child of
/* because of this find - we cannot get a child of
* root (which is what we want!)
*/
@ -697,7 +697,7 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
{
#ifdef FI_DEBUG
std::cerr << "FileIndex::loadIndex error opening file: " << filename;
std::cerr << std::endl;
std::cerr << std::endl;
#endif
return 0;
}
@ -714,10 +714,10 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
/* calculate hash */
unsigned char sha_buf[SHA_DIGEST_LENGTH];
SHA_CTX *sha_ctx = new SHA_CTX;
SHA_CTX *sha_ctx = new SHA_CTX;
SHA1_Init(sha_ctx);
SHA1_Update(sha_ctx, ss.str().c_str(), ss.str().length());
SHA1_Final(&sha_buf[0], sha_ctx);
SHA1_Final(&sha_buf[0], sha_ctx);
delete sha_ctx;
std::ostringstream tmpout;
@ -729,19 +729,19 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
if (expectedHash != tmpout.str())
{
#ifdef FI_DEBUG
std::cerr << "FileIndex::loadIndex expected hash does not match" << std::endl;
std::cerr << "FileIndex::loadIndex expected hash does not match" << std::endl;
std::cerr << "Expected hash: " << expectedHash << std::endl;
std::cerr << "Hash found: " << tmpout.str() << std::endl;
#endif
return 0;
}
DirEntry *ndir = NULL;
FileEntry *nfile = NULL;
std::list<DirEntry *> dirlist;
std::string word;
char ch;
while(ss.get(ch))
{
if (ch == '-')
@ -750,7 +750,7 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
switch(dirlist.size())
{
/* parse error: out of directory */
case 0:
case 0:
{
#ifdef FI_DEBUG
std::cerr << "loadIndex error parsing saved file: " << filename;
@ -760,16 +760,16 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
goto error;
}
/* finished parse, last dir is root */
case 1:
case 1:
{
std::string pid = root -> id;
std::string pid = root -> id;
FileIndex::unregisterEntry((void*)root) ;
delete root; /* to clean up old entries */
root = new PersonEntry(pid);
registerEntry((void*)root) ;
/* shallow copy of all except id */
ndir = dirlist.back();
ndir = dirlist.back();
dirlist.pop_back(); /* empty list */
(*root) = (*ndir);
@ -782,13 +782,13 @@ int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_
/* must reset parent pointers now */
std::map<std::string, DirEntry *>::iterator it;
for(it = root->subdirs.begin();
for(it = root->subdirs.begin();
it != root->subdirs.end(); it++)
{
(it->second)->parent = root;
}
break;
break;
}
/* pop stack */
default: dirlist.pop_back(); ndir = dirlist.back();
@ -897,12 +897,12 @@ int FileIndex::saveIndex(std::string filename, std::string &fileHash, uint64_t &
unsigned char sha_buf[SHA_DIGEST_LENGTH];
std::ofstream file (filename.c_str(), std::ofstream::binary);
std::ostringstream oss;
if (!file)
{
#ifdef FI_DEBUG
std::cerr << "FileIndex::saveIndex error opening file: " << filename;
std::cerr << std::endl;
std::cerr << std::endl;
#endif
return 0;
}
@ -912,7 +912,7 @@ int FileIndex::saveIndex(std::string filename, std::string &fileHash, uint64_t &
oss << "# Dir: d name, path, parent, size, modtime, pop, updtime;" << std::endl;
oss << "# File: f name, hash, size, modtime, pop, updtime;" << std::endl;
oss << "#" << std::endl;
/* begin recusion */
root->writeDirInfo(oss) ;
@ -935,10 +935,10 @@ int FileIndex::saveIndex(std::string filename, std::string &fileHash, uint64_t &
oss << "-" << std::endl;
/* calculate sha1 hash */
SHA_CTX *sha_ctx = new SHA_CTX;
SHA_CTX *sha_ctx = new SHA_CTX;
SHA1_Init(sha_ctx);
SHA1_Update(sha_ctx, oss.str().c_str(), oss.str().length());
SHA1_Final(&sha_buf[0], sha_ctx);
SHA1_Final(&sha_buf[0], sha_ctx);
delete sha_ctx;
std::ostringstream tmpout;
@ -1022,7 +1022,7 @@ int FileIndex::searchHash(std::string hash, std::list<FileEntry *> &results) con
{
#ifdef FI_DEBUG
std::cerr << "FileIndex::searchHash(" << hash << ")";
std::cerr << std::endl;
std::cerr << std::endl;
#endif
DirEntry *ndir = NULL;
std::list<DirEntry *> dirlist;
@ -1049,7 +1049,7 @@ int FileIndex::searchHash(std::string hash, std::list<FileEntry *> &results) con
#ifdef FI_DEBUG
std::cerr << "FileIndex::searchHash(" << hash << ")";
std::cerr << " found: " << fit->second->name;
std::cerr << std::endl;
std::cerr << std::endl;
#endif
}
}
@ -1079,6 +1079,28 @@ int FileIndex::searchTerms(std::list<std::string> terms, std::list<FileEntry *>
dirlist.push_back(it->second);
}
for (iter = terms.begin(); iter != terms.end(); iter ++) {
std::string::const_iterator it2;
const std::string &str1 = ndir->name;
const std::string &str2 = *iter;
it2 = std::search(str1.begin(), str1.end(), str2.begin(), str2.end(), CompareCharIC());
if (it2 != str1.end()) {
/* first search to see if its parent is in the results list */
bool addDir = true;
for (std::list<FileEntry *>::iterator rit(results.begin()); rit != results.end() && addDir; rit ++) {
DirEntry *de = dynamic_cast<DirEntry *>(*rit);
if (de && (de == root))
continue;
if (de && (de == ndir->parent))
addDir = false;
}
if (addDir) {
results.push_back((FileEntry *) ndir);
break;
}
}
}
for(fit = ndir->files.begin(); fit != ndir->files.end(); fit++)
{
/* cycle through terms */
@ -1135,7 +1157,7 @@ int FileIndex::searchBoolExp(Expression * exp, std::list<FileEntry *> &results)
/*Evaluate the boolean expression and add it to the results if its true*/
bool ret = exp->eval(fit->second);
if (ret == true){
results.push_back(fit->second);
results.push_back(fit->second);
}
}
} //while
@ -1176,7 +1198,7 @@ int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
details.age = 0;
details.flags = 0;
}
else
else
{
if (dir) /* has children --- fill */
{
@ -1192,17 +1214,17 @@ int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
stub.type = DIR_TYPE_DIR;
stub.name = (dit->second) -> name;
stub.ref = (dit->second);
details.children.push_back(stub);
}
for(fit = dir->files.begin(); fit != dir->files.end(); fit++)
{
DirStub stub;
stub.type = DIR_TYPE_FILE;
stub.name = (fit->second) -> name;
stub.ref = (fit->second);
details.children.push_back(stub);
}
@ -1218,7 +1240,7 @@ int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
details.type = DIR_TYPE_FILE;
details.count = file->size;
}
#ifdef FI_DEBUG
std::cerr << "FileIndexStore::RequestDirDetails() name: " << file->name << std::endl;
#endif
@ -1253,7 +1275,7 @@ int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags)
if(parent==NULL)
{
if(NULL == (person = dynamic_cast<PersonEntry *>(file)))
if(NULL == (person = dynamic_cast<PersonEntry *>(file)))
{
std::cerr << "Major Error- Not PersonEntry!";
exit(1);

View file

@ -1,16 +1,16 @@
/*
* RetroShare FileCache Module: fistore.cc
*
*
* Copyright 2004-2007 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
@ -25,15 +25,15 @@
#include "rsiface/rsexpr.h"
#include "serialiser/rsserviceids.h"
FileIndexStore::FileIndexStore(CacheStrapper *cs, CacheTransfer *cft,
FileIndexStore::FileIndexStore(CacheStrapper *cs, CacheTransfer *cft,
NotifyBase *cb_in, RsPeerId ownid, std::string cachedir)
:CacheStore(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cft, cachedir),
:CacheStore(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cft, cachedir),
localId(ownid), localindex(NULL), cb(cb_in)
{
{
return;
}
FileIndexStore::~FileIndexStore()
FileIndexStore::~FileIndexStore()
{
/* clean up the Index */
return;
@ -151,7 +151,7 @@ int FileIndexStore::RequestDirDetails(std::string uid, std::string path, DirDeta
if (it == indices.end())
{
//DirEntry *fdir = (it->second).lookupDirectory(path);
/* translate it
/* translate it
*/
found = false;
}
@ -232,13 +232,13 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
/* get remote root entries */
for(pit = indices.begin(); pit != indices.end(); pit++)
{
/*
/*
*/
DirStub stub;
stub.type = DIR_TYPE_PERSON;
stub.name = (pit->second)->root->name;
stub.ref = (pit->second)->root;
details.children.push_back(stub);
}
details.parent = NULL;
@ -253,7 +253,7 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
details.flags = 0;
}
}
else
else
{
if (dir) /* has children --- fill */
{
@ -263,31 +263,31 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
std::map<std::string, FileEntry *>::iterator fit;
std::map<std::string, DirEntry *>::iterator dit;
/* extract all the entries */
for(dit = dir->subdirs.begin();
for(dit = dir->subdirs.begin();
dit != dir->subdirs.end(); dit++)
{
DirStub stub;
stub.type = DIR_TYPE_DIR;
stub.name = (dit->second) -> name;
stub.ref = (dit->second);
details.children.push_back(stub);
}
for(fit = dir->files.begin();
for(fit = dir->files.begin();
fit != dir->files.end(); fit++)
{
DirStub stub;
stub.type = DIR_TYPE_FILE;
stub.name = (fit->second) -> name;
stub.ref = (fit->second);
details.children.push_back(stub);
}
details.type = DIR_TYPE_DIR;
details.hash = "";
details.count = dir->subdirs.size() +
details.count = dir->subdirs.size() +
dir->files.size();
}
else
@ -298,7 +298,7 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
details.type = DIR_TYPE_FILE;
details.count = file->size;
}
#ifdef FIS_DEBUG
std::cerr << "FileIndexStore::RequestDirDetails() name: " << file->name << std::endl;
#endif
@ -333,7 +333,7 @@ int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t f
if(parent==NULL)
{
if(NULL == (person = dynamic_cast<PersonEntry *>(file)))
if(NULL == (person = dynamic_cast<PersonEntry *>(file)))
{
std::cerr << "Major Error- Not PersonEntry!";
exit(1);
@ -366,7 +366,7 @@ int FileIndexStore::SearchHash(std::string hash, std::list<FileDetail> &results)
{
lockData();
std::map<RsPeerId, FileIndex *>::const_iterator pit;
std::list<FileEntry *>::iterator rit;
std::list<FileEntry *>::iterator rit;
std::list<FileEntry *> firesults;
time_t now = time(NULL);
@ -411,11 +411,11 @@ int FileIndexStore::SearchHash(std::string hash, std::list<FileDetail> &results)
}
int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results,uint32_t flags) const
int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) const
{
lockData();
std::map<RsPeerId, FileIndex *>::const_iterator pit;
std::list<FileEntry *>::iterator rit;
std::list<FileEntry *>::iterator rit;
std::list<FileEntry *> firesults;
time_t now = time(NULL);
@ -432,18 +432,10 @@ int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<Fi
/* translate results */
for(rit = firesults.begin(); rit != firesults.end(); rit++)
{
FileDetail fd;
fd.id = pit->first;
fd.name = (*rit)->name;
fd.hash = (*rit)->hash;
fd.path = ""; /* TODO */
fd.size = (*rit)->size;
fd.age = now - (*rit)->modtime;
fd.rank = (*rit)->pop;
results.push_back(fd);
DirDetails dd;
(pit->second)->RequestDirDetails(*rit, dd, 0);
results.push_back(dd);
}
}
if(flags & DIR_FLAGS_LOCAL)
@ -455,16 +447,10 @@ int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<Fi
/* translate results */
for(rit = firesults.begin(); rit != firesults.end(); rit++)
{
FileDetail fd;
fd.id = "Local"; //localId;
fd.name = (*rit)->name;
fd.hash = (*rit)->hash;
fd.path = ""; /* TODO */
fd.size = (*rit)->size;
fd.age = now - (*rit)->modtime;
fd.rank = (*rit)->pop;
results.push_back(fd);
DirDetails dd;
(pit->second)->RequestDirDetails(*rit, dd, 0);
dd.id = "Local";
results.push_back(dd);
}
}
@ -474,11 +460,11 @@ int FileIndexStore::SearchKeywords(std::list<std::string> keywords, std::list<Fi
}
int FileIndexStore::searchBoolExp(Expression * exp, std::list<FileDetail> &results) const
int FileIndexStore::searchBoolExp(Expression * exp, std::list<DirDetails> &results) const
{
lockData();
std::map<RsPeerId, FileIndex *>::const_iterator pit;
std::list<FileEntry *>::iterator rit;
std::list<FileEntry *>::iterator rit;
std::list<FileEntry *> firesults;
time_t now = time(NULL);
@ -495,16 +481,9 @@ int FileIndexStore::searchBoolExp(Expression * exp, std::list<FileDetail> &resul
/* translate results */
for(rit = firesults.begin(); rit != firesults.end(); rit++)
{
FileDetail fd;
fd.id = pit->first;
fd.name = (*rit)->name;
fd.hash = (*rit)->hash;
fd.path = ""; /* TODO */
fd.size = (*rit)->size;
fd.age = now - (*rit)->modtime;
fd.rank = (*rit)->pop;
results.push_back(fd);
DirDetails dd;
(pit->second)->RequestDirDetails(*rit, dd, 0);
results.push_back(dd);
}
}
@ -519,16 +498,10 @@ int FileIndexStore::searchBoolExp(Expression * exp, std::list<FileDetail> &resul
/* translate results */
for(rit = firesults.begin(); rit != firesults.end(); rit++)
{
FileDetail fd;
fd.id = "Local"; //localId;
fd.name = (*rit)->name;
fd.hash = (*rit)->hash;
fd.path = ""; /* TODO */
fd.size = (*rit)->size;
fd.age = now - (*rit)->modtime;
fd.rank = (*rit)->pop;
results.push_back(fd);
DirDetails dd;
(pit->second)->RequestDirDetails(*rit, dd, 0);
dd.id = "Local";
results.push_back(dd);
}
}

View file

@ -1,16 +1,16 @@
/*
* RetroShare FileCache Module: fistore.h
*
*
* Copyright 2004-2007 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
@ -27,7 +27,7 @@
/**********
* Stores the FileCaches of the Peers
* must implement 'loadCache' to
* must implement 'loadCache' to
*
* This class is also accessed by the GUI....
* and the FileTransfer class.
@ -63,7 +63,7 @@ class FileIndexStore: public CacheStore
{
public:
FileIndexStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,
FileIndexStore(CacheStrapper *cs, CacheTransfer *cft, NotifyBase *cb_in,
RsPeerId ownid, std::string cachedir);
virtual ~FileIndexStore();
@ -74,10 +74,10 @@ virtual int loadCache(const CacheData &data); /* actual load, once data availa
int SearchHash(std::string hash, std::list<FileDetail> &results) const;
/* Search Interface - For Search Interface */
int SearchKeywords(std::list<std::string> terms, std::list<FileDetail> &results,uint32_t flags) const;
int SearchKeywords(std::list<std::string> terms, std::list<DirDetails> &results,uint32_t flags) const;
/* Search Interface - for Adv Search Interface */
int searchBoolExp(Expression * exp, std::list<FileDetail> &results) const;
int searchBoolExp(Expression * exp, std::list<DirDetails> &results) const;
/* Search Interface - For Directory Access */