mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
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:
parent
2a82826fba
commit
f290c8eca4
@ -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<SharedDirInfo>& 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<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 ;
|
||||
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
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user