Made the hash-cache more compliant with mounted/network drives:

- corrected bug that would wipe out the cache file every other start
- missing root directories are not discarded anymore, but kept empty, unless the user really removes them


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4271 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2011-06-15 20:03:26 +00:00
parent 2a82826fba
commit f290c8eca4
5 changed files with 43 additions and 32 deletions

View File

@ -48,11 +48,12 @@
//*********** //***********
//#define FIM_DEBUG 1 //#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), :CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fi(pid),
pendingDirs(false), pendingForceCacheWrite(false), 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; updatePeriod = 60;
@ -123,7 +124,7 @@ HashCache::HashCache(const std::string& path)
int n=0 ; int n=0 ;
#endif #endif
while(f.good()) while(!f.eof())
{ {
HashCacheInfo info ; HashCacheInfo info ;
@ -602,9 +603,18 @@ void FileIndexMonitor::updateCycle()
#ifdef FIM_DEBUG #ifdef FIM_DEBUG
std::cerr << "FileIndexMonitor::updateCycle()"; std::cerr << "FileIndexMonitor::updateCycle()";
std::cerr << " Missing Dir: " << realpath << std::endl; std::cerr << " Missing Dir: " << realpath << std::endl;
std::cerr << " Root Dir: " << rootdir << std::endl;
std::cerr << " remdir: " << remdir << std::endl;
#endif #endif
/* bad directory - delete */ if(directoryMap.end() != directoryMap.find(rootdir) && remdir=="")
if (!fi.removeOldDirectory(olddir->parent->path, olddir->name, stamp)) {
#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 /* bad... drop out of updateCycle() - hopefully the initial cleanup
* will deal with it next time! - otherwise we're in a continual loop * will deal with it next time! - otherwise we're in a continual loop
@ -614,6 +624,7 @@ void FileIndexMonitor::updateCycle()
} }
continue; continue;
} }
}
/* update this dir - as its valid */ /* update this dir - as its valid */
fe.name = olddir->name; fe.name = olddir->name;
@ -1069,18 +1080,18 @@ void FileIndexMonitor::setSharedDirectories(const std::list<SharedDirInfo>& d
#endif #endif
/* check if dir exists before adding in */ /* check if dir exists before adding in */
std::string path = (*it).filename; // std::string path = (*it).filename;
if (!RsDirUtil::checkDirectory(path)) // if (!RsDirUtil::checkDirectory(path))
{ // {
#ifdef FIM_DEBUG //#ifdef FIM_DEBUG
std::cerr << "FileIndexMonitor::setSharedDirectories()"; // std::cerr << "FileIndexMonitor::setSharedDirectories()";
std::cerr << " Ignoring NonExistant SharedDir: " << path << std::endl; // std::cerr << " Ignoring NonExistant SharedDir: " << path << std::endl;
#endif //#endif
} // }
else // else
{ // {
checkeddirs.push_back(*it); checkeddirs.push_back(*it);
} // }
} }
{ {
@ -1247,13 +1258,13 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t
{ {
RsStackMutex mutex(fiMutex) ; RsStackMutex mutex(fiMutex) ;
#ifdef FIM_DEBUG #ifdef FIM_DEBUG2
std::cerr << "FileIndexMonitor::RequestDirDetails() ref=" << ref << " flags: " << flags << std::endl; std::cerr << "FileIndexMonitor::RequestDirDetails() ref=" << ref << " flags: " << flags << std::endl;
#endif #endif
/* root case */ /* root case */
#ifdef FIM_DEBUG #ifdef FIM_DEBUG2
fi.root->checkParentPointers(); fi.root->checkParentPointers();
#endif #endif
@ -1261,7 +1272,7 @@ int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t
if (ref == NULL) if (ref == NULL)
{ {
#ifdef FI_DEBUG #ifdef FI_DEBUG2
std::cerr << "FileIndex::RequestDirDetails() ref=NULL (root)" << std::endl; std::cerr << "FileIndex::RequestDirDetails() ref=NULL (root)" << std::endl;
#endif #endif
/* local only */ /* local only */
@ -1321,7 +1332,7 @@ uint32_t FileIndexMonitor::locked_findShareFlags(FileEntry *file) const
if(dir != NULL && dir->parent != NULL) if(dir != NULL && dir->parent != NULL)
{ {
#ifdef FIM_DEBUG #ifdef FIM_DEBUG2
std::cerr << "FileIndexMonitor::RequestDirDetails: top parent name=" << dir->name << std::endl ; std::cerr << "FileIndexMonitor::RequestDirDetails: top parent name=" << dir->name << std::endl ;
#endif #endif
std::map<std::string,SharedDirInfo>::const_iterator it = directoryMap.find(dir->name) ; std::map<std::string,SharedDirInfo>::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 ; std::cerr << "*********** ERROR *********** In " << __PRETTY_FUNCTION__ << std::endl ;
else else
flags = it->second.shareflags & (RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE) ; 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 ; std::cerr << "flags = " << flags << std::endl ;
#endif #endif
} }

View File

@ -107,7 +107,7 @@ class HashCache
class FileIndexMonitor: public CacheSource, public RsThread class FileIndexMonitor: public CacheSource, public RsThread
{ {
public: 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(); virtual ~FileIndexMonitor();
/* external interface for filetransfer */ /* external interface for filetransfer */

View File

@ -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) ftFiMonitor::ftFiMonitor(CacheStrapper *cs,NotifyBase *cb_in, std::string cachedir, std::string pid,const std::string& config_dir)
:FileIndexMonitor(cs,cb_in, cachedir, pid), p3Config(CONFIG_TYPE_FT_SHARED) :FileIndexMonitor(cs,cb_in, cachedir, pid,config_dir), p3Config(CONFIG_TYPE_FT_SHARED)
{ {
return; return;
} }

View File

@ -57,7 +57,7 @@ virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info)
class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config
{ {
public: 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 */ /* overloaded search function */
virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const; virtual bool search(const std::string &hash, uint32_t hintflags, FileInfo &info) const;

View File

@ -132,7 +132,7 @@ void ftServer::SetupFtServer(NotifyBase *cb)
/* Make Cache Source/Store */ /* Make Cache Source/Store */
mFiStore = new ftFiStore(mCacheStrapper, mFtController, cb,mConnMgr, ownId, remotecachedir); 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 */ /* now add the set to the cachestrapper */
CachePair cp(mFiMon, mFiStore, CacheId(RS_SERVICE_TYPE_FILE_INDEX, 0)); CachePair cp(mFiMon, mFiStore, CacheId(RS_SERVICE_TYPE_FILE_INDEX, 0));