diff --git a/libretroshare/src/dbase/fimonitor.cc b/libretroshare/src/dbase/fimonitor.cc index 931bc99cd..43eb380e8 100644 --- a/libretroshare/src/dbase/fimonitor.cc +++ b/libretroshare/src/dbase/fimonitor.cc @@ -48,11 +48,12 @@ //*********** //#define FIM_DEBUG 1 // ***********/ +#define FIM_DEBUG 1 -FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in,std::string cachedir, std::string pid) +FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in,std::string cachedir, std::string pid,const std::string& config_dir) :CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fi(pid), pendingDirs(false), pendingForceCacheWrite(false), - mForceCheck(false), mInCheck(false),cb(cb_in), hashCache(cachedir+"/" + "fc-own-cache.rsfa"),useHashCache(true) + mForceCheck(false), mInCheck(false),cb(cb_in), hashCache(config_dir+"/" + "file_cache.lst"),useHashCache(true) { updatePeriod = 60; @@ -123,7 +124,7 @@ HashCache::HashCache(const std::string& path) int n=0 ; #endif - while(f.good()) + while(!f.eof()) { HashCacheInfo info ; @@ -602,17 +603,27 @@ void FileIndexMonitor::updateCycle() #ifdef FIM_DEBUG std::cerr << "FileIndexMonitor::updateCycle()"; std::cerr << " Missing Dir: " << realpath << std::endl; + std::cerr << " Root Dir: " << rootdir << std::endl; + std::cerr << " remdir: " << remdir << std::endl; #endif - /* bad directory - delete */ - if (!fi.removeOldDirectory(olddir->parent->path, olddir->name, stamp)) + if(directoryMap.end() != directoryMap.find(rootdir) && remdir=="") { - /* bad... drop out of updateCycle() - hopefully the initial cleanup - * will deal with it next time! - otherwise we're in a continual loop - */ - std::cerr << "FileIndexMonitor::updateCycle()"; - std::cerr << "ERROR Failed to Remove: " << olddir->path << std::endl; +#ifdef FIM_DEBUG + std::cerr << " This is a root directory. Keeping it empty." << std::endl; +#endif + } + else + { + if (!fi.removeOldDirectory(olddir->parent->path, olddir->name, stamp))/* bad directory - delete */ + { + /* bad... drop out of updateCycle() - hopefully the initial cleanup + * will deal with it next time! - otherwise we're in a continual loop + */ + std::cerr << "FileIndexMonitor::updateCycle()"; + std::cerr << "ERROR Failed to Remove: " << olddir->path << std::endl; + } + continue; } - continue; } /* update this dir - as its valid */ @@ -1069,18 +1080,18 @@ void FileIndexMonitor::setSharedDirectories(const std::list& d #endif /* check if dir exists before adding in */ - std::string path = (*it).filename; - if (!RsDirUtil::checkDirectory(path)) - { -#ifdef FIM_DEBUG - std::cerr << "FileIndexMonitor::setSharedDirectories()"; - std::cerr << " Ignoring NonExistant SharedDir: " << path << std::endl; -#endif - } - else - { +// std::string path = (*it).filename; +// if (!RsDirUtil::checkDirectory(path)) +// { +//#ifdef FIM_DEBUG +// std::cerr << "FileIndexMonitor::setSharedDirectories()"; +// std::cerr << " Ignoring NonExistant SharedDir: " << path << std::endl; +//#endif +// } +// else +// { checkeddirs.push_back(*it); - } +// } } { @@ -1247,13 +1258,13 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t { RsStackMutex mutex(fiMutex) ; -#ifdef FIM_DEBUG +#ifdef FIM_DEBUG2 std::cerr << "FileIndexMonitor::RequestDirDetails() ref=" << ref << " flags: " << flags << std::endl; #endif /* root case */ -#ifdef FIM_DEBUG +#ifdef FIM_DEBUG2 fi.root->checkParentPointers(); #endif @@ -1261,7 +1272,7 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t if (ref == NULL) { -#ifdef FI_DEBUG +#ifdef FI_DEBUG2 std::cerr << "FileIndex::RequestDirDetails() ref=NULL (root)" << std::endl; #endif /* local only */ @@ -1321,7 +1332,7 @@ uint32_t FileIndexMonitor::locked_findShareFlags(FileEntry *file) const if(dir != NULL && dir->parent != NULL) { -#ifdef FIM_DEBUG +#ifdef FIM_DEBUG2 std::cerr << "FileIndexMonitor::RequestDirDetails: top parent name=" << dir->name << std::endl ; #endif std::map::const_iterator it = directoryMap.find(dir->name) ; @@ -1330,7 +1341,7 @@ uint32_t FileIndexMonitor::locked_findShareFlags(FileEntry *file) const std::cerr << "*********** ERROR *********** In " << __PRETTY_FUNCTION__ << std::endl ; else flags = it->second.shareflags & (RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE) ; -#ifdef FIM_DEBUG +#ifdef FIM_DEBUG2 std::cerr << "flags = " << flags << std::endl ; #endif } diff --git a/libretroshare/src/dbase/fimonitor.h b/libretroshare/src/dbase/fimonitor.h index 692a64470..8c859e725 100644 --- a/libretroshare/src/dbase/fimonitor.h +++ b/libretroshare/src/dbase/fimonitor.h @@ -107,7 +107,7 @@ class HashCache class FileIndexMonitor: public CacheSource, public RsThread { public: - FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in, std::string cachedir, std::string pid); + FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in, std::string cachedir, std::string pid, const std::string& config_dir); virtual ~FileIndexMonitor(); /* external interface for filetransfer */ diff --git a/libretroshare/src/ft/ftdbase.cc b/libretroshare/src/ft/ftdbase.cc index bf5b4fd36..3651ca06f 100644 --- a/libretroshare/src/ft/ftdbase.cc +++ b/libretroshare/src/ft/ftdbase.cc @@ -119,8 +119,8 @@ bool ftFiStore::search(const std::string &hash, uint32_t hintflags, FileInfo &in } -ftFiMonitor::ftFiMonitor(CacheStrapper *cs,NotifyBase *cb_in, std::string cachedir, std::string pid) - :FileIndexMonitor(cs,cb_in, cachedir, pid), p3Config(CONFIG_TYPE_FT_SHARED) +ftFiMonitor::ftFiMonitor(CacheStrapper *cs,NotifyBase *cb_in, std::string cachedir, std::string pid,const std::string& config_dir) + :FileIndexMonitor(cs,cb_in, cachedir, pid,config_dir), p3Config(CONFIG_TYPE_FT_SHARED) { return; } diff --git a/libretroshare/src/ft/ftdbase.h b/libretroshare/src/ft/ftdbase.h index 8b6146ccb..715824e91 100644 --- a/libretroshare/src/ft/ftdbase.h +++ b/libretroshare/src/ft/ftdbase.h @@ -57,7 +57,7 @@ virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config { public: - ftFiMonitor(CacheStrapper *cs,NotifyBase *cb_in, std::string cachedir, std::string pid); + ftFiMonitor(CacheStrapper *cs,NotifyBase *cb_in, std::string cachedir, std::string pid,const std::string& config_dir); /* overloaded search function */ virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const; diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 5abcb4764..9321df954 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -132,7 +132,7 @@ void ftServer::SetupFtServer(NotifyBase *cb) /* Make Cache Source/Store */ mFiStore = new ftFiStore(mCacheStrapper, mFtController, cb,mConnMgr, ownId, remotecachedir); - mFiMon = new ftFiMonitor(mCacheStrapper,cb, localcachedir, ownId); + mFiMon = new ftFiMonitor(mCacheStrapper,cb, localcachedir, ownId,mConfigPath); /* now add the set to the cachestrapper */ CachePair cp(mFiMon, mFiStore, CacheId(RS_SERVICE_TYPE_FILE_INDEX, 0));