mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-03 02:50:07 -05:00
only update subfiles and subdirs list during dir watching sweep when the TS of the dir has changed. Greatly improve cost of regular directory watching process
This commit is contained in:
parent
d020d8d896
commit
854eebb2cb
@ -137,59 +137,71 @@ void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_p
|
|||||||
|
|
||||||
librs::util::FolderIterator dirIt(cumulated_path);
|
librs::util::FolderIterator dirIt(cumulated_path);
|
||||||
|
|
||||||
// collect subdirs and subfiles
|
time_t dir_local_mod_time ;
|
||||||
|
if(!mSharedDirectories->getDirectoryLocalModTime(indx,dir_local_mod_time))
|
||||||
std::map<std::string,DirectoryStorage::FileTS> subfiles ;
|
|
||||||
std::map<std::string,time_t> subdirs ;
|
|
||||||
|
|
||||||
for(;dirIt.isValid();dirIt.next())
|
|
||||||
{
|
{
|
||||||
switch(dirIt.file_type())
|
std::cerr << "(EE) Cannot get local mod time for dir index " << indx << std::endl;
|
||||||
{
|
return;
|
||||||
case librs::util::FolderIterator::TYPE_FILE: subfiles[dirIt.file_name()].modtime = dirIt.file_modtime() ;
|
|
||||||
subfiles[dirIt.file_name()].size = dirIt.file_size();
|
|
||||||
#ifdef DEBUG_LOCAL_DIR_UPDATER
|
|
||||||
std::cerr << " adding sub-file \"" << dirIt.file_name() << "\"" << std::endl;
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
|
|
||||||
case librs::util::FolderIterator::TYPE_DIR: subdirs[dirIt.file_name()] = dirIt.file_modtime();
|
|
||||||
#ifdef DEBUG_LOCAL_DIR_UPDATER
|
|
||||||
std::cerr << " adding sub-dir \"" << dirIt.file_name() << "\"" << std::endl;
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
std::cerr << "(EE) Dir entry of unknown type with path \"" << cumulated_path << "/" << dirIt.file_name() << "\"" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// update folder modificatoin time, which is the only way to detect e.g. removed or renamed files.
|
|
||||||
|
|
||||||
mSharedDirectories->setDirectoryLocalModTime(indx,dirIt.dir_modtime()) ;
|
if(dirIt.dir_modtime() != dir_local_mod_time)
|
||||||
|
|
||||||
// update file and dir lists for current directory.
|
|
||||||
|
|
||||||
mSharedDirectories->updateSubDirectoryList(indx,subdirs) ;
|
|
||||||
|
|
||||||
std::map<std::string,DirectoryStorage::FileTS> new_files ;
|
|
||||||
mSharedDirectories->updateSubFilesList(indx,subfiles,new_files) ;
|
|
||||||
|
|
||||||
// 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.
|
// collect subdirs and subfiles
|
||||||
|
|
||||||
RsFileHash hash ;
|
std::map<std::string,DirectoryStorage::FileTS> subfiles ;
|
||||||
|
std::map<std::string,time_t> subdirs ;
|
||||||
|
|
||||||
if(mHashCache->requestHash(cumulated_path + "/" + dit.name(),dit.size(),dit.modtime(),hash,this,*dit) && dit.hash() != hash)
|
for(;dirIt.isValid();dirIt.next())
|
||||||
mSharedDirectories->updateHash(*dit,hash);
|
{
|
||||||
|
switch(dirIt.file_type())
|
||||||
|
{
|
||||||
|
case librs::util::FolderIterator::TYPE_FILE: subfiles[dirIt.file_name()].modtime = dirIt.file_modtime() ;
|
||||||
|
subfiles[dirIt.file_name()].size = dirIt.file_size();
|
||||||
|
#ifdef DEBUG_LOCAL_DIR_UPDATER
|
||||||
|
std::cerr << " adding sub-file \"" << dirIt.file_name() << "\"" << std::endl;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
|
||||||
|
case librs::util::FolderIterator::TYPE_DIR: subdirs[dirIt.file_name()] = dirIt.file_modtime();
|
||||||
|
#ifdef DEBUG_LOCAL_DIR_UPDATER
|
||||||
|
std::cerr << " adding sub-dir \"" << dirIt.file_name() << "\"" << std::endl;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
std::cerr << "(EE) Dir entry of unknown type with path \"" << cumulated_path << "/" << dirIt.file_name() << "\"" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// update folder modificatoin time, which is the only way to detect e.g. removed or renamed files.
|
||||||
|
|
||||||
|
mSharedDirectories->setDirectoryLocalModTime(indx,dirIt.dir_modtime()) ;
|
||||||
|
|
||||||
|
// update file and dir lists for current directory.
|
||||||
|
|
||||||
|
mSharedDirectories->updateSubDirectoryList(indx,subdirs) ;
|
||||||
|
|
||||||
|
std::map<std::string,DirectoryStorage::FileTS> new_files ;
|
||||||
|
mSharedDirectories->updateSubFilesList(indx,subfiles,new_files) ;
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
RsFileHash hash ;
|
||||||
|
|
||||||
|
if(mHashCache->requestHash(cumulated_path + "/" + dit.name(),dit.size(),dit.modtime(),hash,this,*dit) && dit.hash() != hash)
|
||||||
|
mSharedDirectories->updateHash(*dit,hash);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef DEBUG_LOCAL_DIR_UPDATER
|
||||||
|
else
|
||||||
|
std::cerr << " directory is unchanged. Keeping existing files and subdirs list." << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
// go through the list of sub-dirs and recursively update
|
// go through the list of sub-dirs and recursively update
|
||||||
|
|
||||||
DirectoryStorage::DirIterator stored_dir_it(mSharedDirectories,indx) ;
|
for(DirectoryStorage::DirIterator stored_dir_it(mSharedDirectories,indx) ; stored_dir_it; ++stored_dir_it)
|
||||||
|
|
||||||
for(std::map<std::string,time_t>::const_iterator real_dir_it(subdirs.begin());real_dir_it!=subdirs.end();++real_dir_it, ++stored_dir_it)
|
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_LOCAL_DIR_UPDATER
|
#ifdef DEBUG_LOCAL_DIR_UPDATER
|
||||||
std::cerr << " recursing into " << stored_dir_it.name() << std::endl;
|
std::cerr << " recursing into " << stored_dir_it.name() << std::endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user