mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 22:25:04 -04:00
added infrastructure to add a ignore list in shared files
This commit is contained in:
parent
160ab7b4f3
commit
884b3a6220
11 changed files with 216 additions and 11 deletions
|
@ -232,16 +232,17 @@ void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_p
|
|||
// now go through list of subfiles and request the hash to hashcache
|
||||
|
||||
for(DirectoryStorage::FileIterator dit(mSharedDirectories,indx);dit;++dit)
|
||||
{
|
||||
// ask about the hash. If not present, ask HashCache. If not present, or different, the callback will update it.
|
||||
if(filterFile(dit.name()))
|
||||
{
|
||||
// ask about the hash. If not present, ask HashCache. If not present, or different, the callback will update it.
|
||||
|
||||
RsFileHash hash ;
|
||||
RsFileHash hash ;
|
||||
|
||||
// mSharedDirectories des two things: store H(F), and compute H(H(F)), which is used in FT. The later is always needed.
|
||||
// mSharedDirectories does two things: store H(F), and compute H(H(F)), which is used in FT. The later is always needed.
|
||||
|
||||
if(mHashCache->requestHash(cumulated_path + "/" + dit.name(),dit.size(),dit.modtime(),hash,this,*dit))
|
||||
mSharedDirectories->updateHash(*dit,hash,hash != dit.hash());
|
||||
}
|
||||
if(mHashCache->requestHash(cumulated_path + "/" + dit.name(),dit.size(),dit.modtime(),hash,this,*dit))
|
||||
mSharedDirectories->updateHash(*dit,hash,hash != dit.hash());
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG_LOCAL_DIR_UPDATER
|
||||
else
|
||||
|
@ -259,6 +260,21 @@ void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_p
|
|||
}
|
||||
}
|
||||
|
||||
bool LocalDirectoryUpdater::filterFile(const std::string& fname) const
|
||||
{
|
||||
if(mIgnoreFlags & RS_FILE_SHARE_FLAGS_IGNORE_SUFFIXES)
|
||||
for(auto it(mIgnoredSuffixes.begin());it!=mIgnoredSuffixes.end();++it)
|
||||
if(fname.size() >= (*it).size() && fname.substr( fname.size() - (*it).size()) == *it)
|
||||
return false ;
|
||||
|
||||
if(mIgnoreFlags & RS_FILE_SHARE_FLAGS_IGNORE_PREFIXES)
|
||||
for(auto it(mIgnoredPrefixes.begin());it!=mIgnoredPrefixes.end();++it)
|
||||
if(fname.size() >= (*it).size() && fname.substr( 0,(*it).size()) == *it)
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool LocalDirectoryUpdater::inDirectoryCheck() const
|
||||
{
|
||||
return mHashCache->isRunning();
|
||||
|
@ -301,5 +317,19 @@ bool LocalDirectoryUpdater::followSymLinks() const
|
|||
return mFollowSymLinks ;
|
||||
}
|
||||
|
||||
void LocalDirectoryUpdater::setIgnoreLists(const std::list<std::string>& ignored_prefixes,const std::list<std::string>& ignored_suffixes,uint32_t ignore_flags)
|
||||
{
|
||||
mIgnoredPrefixes = ignored_prefixes ;
|
||||
mIgnoredSuffixes = ignored_suffixes ;
|
||||
mIgnoreFlags = ignore_flags;
|
||||
}
|
||||
bool LocalDirectoryUpdater::getIgnoreLists(std::list<std::string>& ignored_prefixes,std::list<std::string>& ignored_suffixes,uint32_t& ignore_flags) const
|
||||
{
|
||||
ignored_prefixes = mIgnoredPrefixes;
|
||||
ignored_suffixes = mIgnoredSuffixes;
|
||||
ignore_flags = mIgnoreFlags ;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -53,6 +53,9 @@ public:
|
|||
void setEnabled(bool b) ;
|
||||
bool isEnabled() const ;
|
||||
|
||||
void setIgnoreLists(const std::list<std::string>& ignored_prefixes,const std::list<std::string>& ignored_suffixes,uint32_t ignore_flags) ;
|
||||
bool getIgnoreLists(std::list<std::string>& ignored_prefixes,std::list<std::string>& ignored_suffixes,uint32_t& ignore_flags) const ;
|
||||
|
||||
protected:
|
||||
virtual void data_tick() ;
|
||||
|
||||
|
@ -63,6 +66,8 @@ protected:
|
|||
bool sweepSharedDirectories();
|
||||
|
||||
private:
|
||||
bool filterFile(const std::string& fname) const ; // reponds true if the file passes the ignore lists test.
|
||||
|
||||
HashStorage *mHashCache ;
|
||||
LocalDirectoryStorage *mSharedDirectories ;
|
||||
|
||||
|
@ -77,5 +82,9 @@ private:
|
|||
bool mNeedsFullRecheck ;
|
||||
bool mIsChecking ;
|
||||
bool mForceUpdate ;
|
||||
|
||||
uint32_t mIgnoreFlags ;
|
||||
std::list<std::string> mIgnoredPrefixes ;
|
||||
std::list<std::string> mIgnoredSuffixes ;
|
||||
};
|
||||
|
||||
|
|
|
@ -39,6 +39,9 @@ static const std::string WATCH_FILE_DURATION_SS = "WATCH_FILES_DELAY" ; // key
|
|||
static const std::string WATCH_FILE_ENABLED_SS = "WATCH_FILES_ENABLED"; // key to store ON/OFF flags for file whatch
|
||||
static const std::string FOLLOW_SYMLINKS_SS = "FOLLOW_SYMLINKS"; // dereference symbolic links, or just ignore them.
|
||||
static const std::string WATCH_HASH_SALT_SS = "WATCH_HASH_SALT"; // Salt that is used to hash directory names
|
||||
static const std::string IGNORED_PREFIXES_SS = "IGNORED_PREFIXES"; // ignore file prefixes
|
||||
static const std::string IGNORED_SUFFIXES_SS = "IGNORED_SUFFIXES"; // ignore file suffixes
|
||||
static const std::string IGNORE_LIST_FLAGS_SS = "IGNORED_FLAGS"; // ignore file flags
|
||||
|
||||
static const std::string FILE_SHARING_DIR_NAME = "file_sharing" ; // hard-coded directory name to store friend file lists, hash cache, etc.
|
||||
static const std::string HASH_CACHE_FILE_NAME = "hash_cache.bin" ; // hard-coded directory name to store encrypted hash cache.
|
||||
|
|
|
@ -81,6 +81,17 @@ p3FileDatabase::p3FileDatabase(p3ServiceControl *mpeers)
|
|||
addSerialType(new RsFileListsSerialiser()) ;
|
||||
}
|
||||
|
||||
void p3FileDatabase::setIgnoreLists(const std::list<std::string>& ignored_prefixes,const std::list<std::string>& ignored_suffixes, uint32_t ignore_flags)
|
||||
{
|
||||
RS_STACK_MUTEX(mFLSMtx) ;
|
||||
mLocalDirWatcher->setIgnoreLists(ignored_prefixes,ignored_suffixes,ignore_flags) ;
|
||||
}
|
||||
bool p3FileDatabase::getIgnoreLists(std::list<std::string>& ignored_prefixes,std::list<std::string>& ignored_suffixes, uint32_t& ignore_flags)
|
||||
{
|
||||
RS_STACK_MUTEX(mFLSMtx) ;
|
||||
return mLocalDirWatcher->getIgnoreLists(ignored_prefixes,ignored_suffixes,ignore_flags) ;
|
||||
}
|
||||
|
||||
RsSerialiser *p3FileDatabase::setupSerialiser()
|
||||
{
|
||||
// This one is for saveList/loadList
|
||||
|
@ -345,6 +356,28 @@ cleanup = true;
|
|||
|
||||
rskv->tlvkvs.pairs.push_back(kv);
|
||||
}
|
||||
{
|
||||
std::list<std::string> prefix_list,suffix_list;
|
||||
uint32_t flags ;
|
||||
|
||||
mLocalDirWatcher->getIgnoreLists(prefix_list,suffix_list,flags) ;
|
||||
|
||||
std::string prefix_string, suffix_string ;
|
||||
|
||||
for(auto it(prefix_list.begin());it!=prefix_list.end();++it) prefix_string += *it + ";" ;
|
||||
for(auto it(suffix_list.begin());it!=suffix_list.end();++it) suffix_string += *it + ";" ;
|
||||
|
||||
RsTlvKeyValue kv;
|
||||
|
||||
kv.key = IGNORED_PREFIXES_SS; kv.value = prefix_string; rskv->tlvkvs.pairs.push_back(kv);
|
||||
kv.key = IGNORED_SUFFIXES_SS; kv.value = suffix_string; rskv->tlvkvs.pairs.push_back(kv);
|
||||
|
||||
std::string s ;
|
||||
rs_sprintf(s, "%lu", flags) ;
|
||||
|
||||
kv.key = IGNORE_LIST_FLAGS_SS; kv.value = s; rskv->tlvkvs.pairs.push_back(kv);
|
||||
}
|
||||
|
||||
/* Add KeyValue to saveList */
|
||||
sList.push_back(rskv);
|
||||
|
||||
|
@ -363,6 +396,8 @@ bool p3FileDatabase::loadList(std::list<RsItem *>& load)
|
|||
#endif
|
||||
|
||||
std::list<SharedDirInfo> dirList;
|
||||
std::list<std::string> ignored_prefixes,ignored_suffixes ;
|
||||
uint32_t ignore_flags ;
|
||||
|
||||
for(std::list<RsItem *>::iterator it = load.begin(); it != load.end(); ++it)
|
||||
{
|
||||
|
@ -400,6 +435,31 @@ bool p3FileDatabase::loadList(std::list<RsItem *>& load)
|
|||
std::cerr << "Initing directory watcher with saved secret salt..." << std::endl;
|
||||
mLocalDirWatcher->setHashSalt(RsFileHash(kit->value)) ;
|
||||
}
|
||||
else if(kit->key == IGNORED_PREFIXES_SS)
|
||||
{
|
||||
std::string b ;
|
||||
for(uint32_t i=0;i<kit->value.size();++i)
|
||||
if(kit->value[i] == ';')
|
||||
ignored_prefixes.push_back(b) ;
|
||||
else
|
||||
b.push_back(kit->value[i]) ;
|
||||
}
|
||||
else if(kit->key == IGNORED_SUFFIXES_SS)
|
||||
{
|
||||
std::string b ;
|
||||
for(uint32_t i=0;i<kit->value.size();++i)
|
||||
if(kit->value[i] == ';')
|
||||
ignored_suffixes.push_back(b) ;
|
||||
else
|
||||
b.push_back(kit->value[i]) ;
|
||||
}
|
||||
else if(kit->key == IGNORE_LIST_FLAGS_SS)
|
||||
{
|
||||
int t=0 ;
|
||||
if(sscanf(kit->value.c_str(),"%d",&t) == 1)
|
||||
ignore_flags = (uint32_t)t ;
|
||||
}
|
||||
|
||||
delete *it ;
|
||||
continue ;
|
||||
}
|
||||
|
@ -427,6 +487,8 @@ bool p3FileDatabase::loadList(std::list<RsItem *>& load)
|
|||
|
||||
/* set directories */
|
||||
mLocalSharedDirs->setSharedDirectoryList(dirList);
|
||||
mLocalDirWatcher->setIgnoreLists(ignored_prefixes,ignored_suffixes,ignore_flags) ;
|
||||
|
||||
load.clear() ;
|
||||
|
||||
return true;
|
||||
|
|
|
@ -127,6 +127,9 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub
|
|||
void updateShareFlags(const SharedDirInfo& info) ;
|
||||
bool convertSharedFilePath(const std::string& path,std::string& fullpath);
|
||||
|
||||
void setIgnoreLists(const std::list<std::string>& ignored_prefixes,const std::list<std::string>& ignored_suffixes, uint32_t ignore_flags) ;
|
||||
bool getIgnoreLists(std::list<std::string>& ignored_prefixes,std::list<std::string>& ignored_suffixes, uint32_t& ignore_flags) ;
|
||||
|
||||
// computes/gathers statistics about shared directories
|
||||
|
||||
int getSharedDirStatistics(const RsPeerId& pid,SharedDirStats& stats);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue