diff --git a/libretroshare/src/dbase/fimonitor.cc b/libretroshare/src/dbase/fimonitor.cc index 060cb9825..96b0d20e6 100644 --- a/libretroshare/src/dbase/fimonitor.cc +++ b/libretroshare/src/dbase/fimonitor.cc @@ -1288,12 +1288,11 @@ std::string FileIndexMonitor::locked_findRealRoot(std::string rootdir) const return realroot; } -int FileIndexMonitor::RequestDirDetails(std::string uid, std::string /*path*/, DirDetails &/*details*/) const +int FileIndexMonitor::RequestDirDetails(const std::string& path, DirDetails& details) const { /* lock it up */ RsStackMutex mutex(fiMutex) ; - - return (uid == fi.root->id) ; + return fi.extractData(path,details) ; } uint32_t FileIndexMonitor::getType(void *ref) const diff --git a/libretroshare/src/dbase/fimonitor.h b/libretroshare/src/dbase/fimonitor.h index 8c859e725..29c69059f 100644 --- a/libretroshare/src/dbase/fimonitor.h +++ b/libretroshare/src/dbase/fimonitor.h @@ -136,7 +136,7 @@ class FileIndexMonitor: public CacheSource, public RsThread // Interface for browsing dir hirarchy int RequestDirDetails(void*, DirDetails&, uint32_t) const ; uint32_t getType(void*) const ; - int RequestDirDetails(std::string uid, std::string path, DirDetails &details) const ; + int RequestDirDetails(const std::string& path, DirDetails &details) const ; // set/update shared directories virtual void setSharedDirectories(const std::list& dirs); diff --git a/libretroshare/src/dbase/findex.cc b/libretroshare/src/dbase/findex.cc index 557561880..25c3b3d08 100644 --- a/libretroshare/src/dbase/findex.cc +++ b/libretroshare/src/dbase/findex.cc @@ -1227,6 +1227,59 @@ uint32_t FileIndex::getType(void *ref) return static_cast(ref)->type() ; } + +bool FileIndex::extractData(const std::string& fpath,DirDetails& details) const +{ + void *ref = findRef(fpath) ; + + if(ref == NULL) + return false ; + + return extractData(ref,details) ; +} + +void *FileIndex::findRef(const std::string& fpath) const +{ + DirEntry *parent = root->findDirectory(fpath); + + std::cerr << "findRef() Called on " << fpath << std::endl; + + if (!parent) + { +//#ifdef FI_DEBUG + std::cerr << "FileIndex::updateFileEntry() NULL parent"; + std::cerr << std::endl; +//#endif + return false; + } + std::cerr << "Found parent directory: " << std::endl; + std::cerr << " parent.name = " << parent->name << std::endl; + std::cerr << " parent.path = " << parent->path << std::endl; + + if(parent->path == fpath) // directory! + { + std::cerr << " fpath is a directory. Returning parent!" << std::endl; + return parent ; + } + else + { + std::cerr << " fpath is a file. Looking into parent directory..." << std::endl; + /* search in current dir */ + for(std::map::iterator fit = parent->files.begin(); fit != parent->files.end(); ++fit) + { + std::cerr << " trying " << parent->path + "/" + fit->second->name << std::endl; + if(parent->path + "/" + fit->second->name == fpath) + { + std::cerr << " found !" << std::endl; + return fit->second ; + } + } + + std::cerr << " (EE) not found !" << std::endl; + return NULL ; + } +} + bool FileIndex::extractData(void *ref,DirDetails& details) { if(!isValid(ref)) diff --git a/libretroshare/src/dbase/findex.h b/libretroshare/src/dbase/findex.h index 29c4089d4..f8830ce3c 100644 --- a/libretroshare/src/dbase/findex.h +++ b/libretroshare/src/dbase/findex.h @@ -255,6 +255,9 @@ class FileIndex // static bool extractData(void *ref,DirDetails& details) ; static uint32_t getType(void *ref) ; + + void *findRef(const std::string& path) const ; + bool extractData(const std::string& path,DirDetails& details) const ; }; diff --git a/libretroshare/src/dbase/fistore.cc b/libretroshare/src/dbase/fistore.cc index 6cf3c2a71..4302db617 100644 --- a/libretroshare/src/dbase/fistore.cc +++ b/libretroshare/src/dbase/fistore.cc @@ -161,8 +161,21 @@ int FileIndexStore::loadCache(const CacheData &data) /* Search Interface - For Directory Access */ -int FileIndexStore::RequestDirDetails(std::string uid, std::string /*path*/, DirDetails& details) const +int FileIndexStore::RequestDirDetails(const std::string& uid, const std::string& path, DirDetails& details) const { + lockData(); + + std::map::const_iterator it = indices.find(uid); + bool found = true; + + if (it != indices.end()) + found = it->second->extractData(path,details) ; + + unlockData(); + + return found ; + +#ifdef OLD_STUFF_TO_REMOVE /* lock it up */ lockData(); @@ -184,6 +197,7 @@ int FileIndexStore::RequestDirDetails(std::string uid, std::string /*path*/, Dir unlockData(); return found; +#endif } int FileIndexStore::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const diff --git a/libretroshare/src/dbase/fistore.h b/libretroshare/src/dbase/fistore.h index 562e7d2f1..436bf456d 100644 --- a/libretroshare/src/dbase/fistore.h +++ b/libretroshare/src/dbase/fistore.h @@ -82,7 +82,7 @@ virtual int loadCache(const CacheData &data); /* actual load, once data availa /* Search Interface - For Directory Access */ - int RequestDirDetails(std::string uid, std::string path, DirDetails &details) const; + int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details) const; int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const; uint32_t getType(void *ref) const ; diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index c15f48d7b..9cbe6f95a 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -484,7 +484,7 @@ bool ftServer::ExtraFileMove(std::string fname, std::string hash, uint64_t size, /******************** Directory Listing ************************/ /***************************************************************/ -int ftServer::RequestDirDetails(std::string uid, std::string path, DirDetails &details) +int ftServer::RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details) { #ifdef SERVER_DEBUG std::cerr << "ftServer::RequestDirDetails(uid:" << uid; @@ -497,7 +497,10 @@ int ftServer::RequestDirDetails(std::string uid, std::string path, DirDetails &d std::cerr << std::endl; } #endif - return mFiStore->RequestDirDetails(uid, path, details); + if(uid == mLinkMgr->getOwnId()) + return mFiMon->RequestDirDetails(path, details); + else + return mFiStore->RequestDirDetails(uid, path, details); } int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index 6275f0767..78b9fc31d 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -175,7 +175,7 @@ virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size, /*** * Directory Listing / Search Interface ***/ -virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details); +virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details); virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags); virtual uint32_t getType(void *ref,uint32_t flags) ; diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 5d18098ab..f4c5dea50 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -162,7 +162,7 @@ class RsFiles /*** * Directory Listing / Search Interface */ - virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details) = 0; + virtual int RequestDirDetails(const std::string& uid, const std::string& path, DirDetails &details) = 0; virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) = 0; virtual uint32_t getType(void *ref,uint32_t flags) = 0;