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
|
||||||
// ***********/
|
// ***********/
|
||||||
|
#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,17 +603,27 @@ 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))
|
|
||||||
{
|
{
|
||||||
/* bad... drop out of updateCycle() - hopefully the initial cleanup
|
#ifdef FIM_DEBUG
|
||||||
* will deal with it next time! - otherwise we're in a continual loop
|
std::cerr << " This is a root directory. Keeping it empty." << std::endl;
|
||||||
*/
|
#endif
|
||||||
std::cerr << "FileIndexMonitor::updateCycle()";
|
}
|
||||||
std::cerr << "ERROR Failed to Remove: " << olddir->path << std::endl;
|
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 */
|
/* update this dir - as its valid */
|
||||||
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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 */
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -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));
|
||||||
|
Loading…
Reference in New Issue
Block a user