From abd7e25a2e737720f7ff5a5f0f32685ac44f1530 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 24 Sep 2017 18:14:45 +0200 Subject: [PATCH] added checks for mMaxShareDepth and mIgnoreDuplicates --- .../src/file_sharing/directory_updater.cc | 18 ++++++++++-------- .../src/file_sharing/directory_updater.h | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libretroshare/src/file_sharing/directory_updater.cc b/libretroshare/src/file_sharing/directory_updater.cc index b82072bcb..744fb1da4 100644 --- a/libretroshare/src/file_sharing/directory_updater.cc +++ b/libretroshare/src/file_sharing/directory_updater.cc @@ -148,7 +148,7 @@ bool LocalDirectoryUpdater::sweepSharedDirectories() std::cerr << "[directory storage] recursing into " << stored_dir_it.name() << std::endl; #endif - recursUpdateSharedDir(stored_dir_it.name(), *stored_dir_it,existing_dirs) ; // here we need to use the list that was stored, instead of the shared dir list, because the two + recursUpdateSharedDir(stored_dir_it.name(), *stored_dir_it,existing_dirs,1) ; // here we need to use the list that was stored, instead of the shared dir list, because the two // are not necessarily in the same order. } @@ -158,15 +158,16 @@ bool LocalDirectoryUpdater::sweepSharedDirectories() return true ; } -void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_path, DirectoryStorage::EntryIndex indx,std::set& existing_directories) +void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_path, DirectoryStorage::EntryIndex indx,std::set& existing_directories,int current_depth) { #ifdef DEBUG_LOCAL_DIR_UPDATER std::cerr << "[directory storage] parsing directory " << cumulated_path << ", index=" << indx << std::endl; #endif - if(mFollowSymLinks) + if(mFollowSymLinks && mIgnoreDuplicates) { std::string real_path = RsDirUtil::removeSymLinks(cumulated_path) ; + if(existing_directories.end() != existing_directories.find(real_path)) { std::cerr << "(WW) Directory " << cumulated_path << " has real path " << real_path << " which already belongs to another shared directory. Ignoring" << std::endl; @@ -249,13 +250,14 @@ void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_p // go through the list of sub-dirs and recursively update - for(DirectoryStorage::DirIterator stored_dir_it(mSharedDirectories,indx) ; stored_dir_it; ++stored_dir_it) - { + if(mMaxShareDepth > 0 && current_depth <= mMaxShareDepth) + for(DirectoryStorage::DirIterator stored_dir_it(mSharedDirectories,indx) ; stored_dir_it; ++stored_dir_it) + { #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; #endif - recursUpdateSharedDir(cumulated_path + "/" + stored_dir_it.name(), *stored_dir_it,existing_directories) ; - } + recursUpdateSharedDir(cumulated_path + "/" + stored_dir_it.name(), *stored_dir_it,existing_directories,current_depth+1) ; + } } bool LocalDirectoryUpdater::filterFile(const std::string& fname) const diff --git a/libretroshare/src/file_sharing/directory_updater.h b/libretroshare/src/file_sharing/directory_updater.h index 211194a48..f38081be4 100644 --- a/libretroshare/src/file_sharing/directory_updater.h +++ b/libretroshare/src/file_sharing/directory_updater.h @@ -70,7 +70,7 @@ protected: virtual void hash_callback(uint32_t client_param, const std::string& name, const RsFileHash& hash, uint64_t size); virtual bool hash_confirm(uint32_t client_param) ; - void recursUpdateSharedDir(const std::string& cumulated_path, DirectoryStorage::EntryIndex indx, std::set& existing_directories); + void recursUpdateSharedDir(const std::string& cumulated_path, DirectoryStorage::EntryIndex indx, std::set& existing_directories, int current_depth); bool sweepSharedDirectories(); private: