From 6272856b5e6f6f1697a80ab47d4c0ac8a08f9c2a Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 16 Nov 2016 21:41:32 +0100 Subject: [PATCH] added param to folderIterator to skip/follow symbolic links --- .../src/file_sharing/directory_updater.cc | 2 +- libretroshare/src/file_sharing/hash_cache.cc | 4 ++++ libretroshare/src/plugins/pluginmanager.cc | 3 ++- libretroshare/src/rsserver/rsaccounts.cc | 3 ++- libretroshare/src/util/folderiterator.cc | 17 +++++++++++++++-- libretroshare/src/util/folderiterator.h | 3 ++- libretroshare/src/util/rsdir.cc | 2 +- 7 files changed, 27 insertions(+), 7 deletions(-) diff --git a/libretroshare/src/file_sharing/directory_updater.cc b/libretroshare/src/file_sharing/directory_updater.cc index 331e51822..bba2ff35e 100644 --- a/libretroshare/src/file_sharing/directory_updater.cc +++ b/libretroshare/src/file_sharing/directory_updater.cc @@ -141,7 +141,7 @@ void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_p // make sure list of subfiles is the same // request all hashes to the hashcache - librs::util::FolderIterator dirIt(cumulated_path); + librs::util::FolderIterator dirIt(cumulated_path,false); time_t dir_local_mod_time ; if(!mSharedDirectories->getDirectoryLocalModTime(indx,dir_local_mod_time)) diff --git a/libretroshare/src/file_sharing/hash_cache.cc b/libretroshare/src/file_sharing/hash_cache.cc index 200a0de4d..9032f6531 100644 --- a/libretroshare/src/file_sharing/hash_cache.cc +++ b/libretroshare/src/file_sharing/hash_cache.cc @@ -145,7 +145,9 @@ void HashStorage::data_tick() if(job.client->hash_confirm(job.client_param)) { +#ifdef HASHSTORAGE_DEBUG std::cerr << "Hashing file " << job.full_path << "..." ; std::cerr.flush(); +#endif std::string tmpout; rs_sprintf(tmpout, "%lu/%lu (%s - %d%%) : %s", (unsigned long int)mHashCounter+1, (unsigned long int)mTotalFilesToHash, friendlyUnit(mTotalHashedSize).c_str(), int(mTotalHashedSize/double(mTotalSizeToHash)*100.0), job.full_path.c_str()) ; @@ -156,7 +158,9 @@ void HashStorage::data_tick() { // store the result +#ifdef HASHSTORAGE_DEBUG std::cerr << "done."<< std::endl; +#endif RS_STACK_MUTEX(mHashMtx) ; HashStorageInfo& info(mFiles[job.full_path]); diff --git a/libretroshare/src/plugins/pluginmanager.cc b/libretroshare/src/plugins/pluginmanager.cc index 19980c812..431b6c2f8 100644 --- a/libretroshare/src/plugins/pluginmanager.cc +++ b/libretroshare/src/plugins/pluginmanager.cc @@ -138,7 +138,8 @@ void RsPluginManager::loadPlugins(const std::vector& plugin_directo for(uint32_t i=0;i & */ /* check for the dir existance */ - librs::util::FolderIterator dirIt(mBaseDirectory); + librs::util::FolderIterator dirIt(mBaseDirectory,false); + if (!dirIt.isValid()) { std::cerr << "Cannot Open Base Dir - No Available Accounts" << std::endl; diff --git a/libretroshare/src/util/folderiterator.cc b/libretroshare/src/util/folderiterator.cc index c5eec9d05..5846ded20 100644 --- a/libretroshare/src/util/folderiterator.cc +++ b/libretroshare/src/util/folderiterator.cc @@ -16,8 +16,8 @@ namespace librs { namespace util { -FolderIterator::FolderIterator(const std::string& folderName) - : mFolderName(folderName) +FolderIterator::FolderIterator(const std::string& folderName,bool allow_symlinks) + : mFolderName(folderName),mAllowSymLinks(allow_symlinks) { is_open = false ; validity = false ; @@ -112,6 +112,19 @@ bool FolderIterator::updateFileInfo(bool& should_skip) mFullPath = mFolderName + "/" + mFileName ; + if( ent->d_type == DT_LNK && !mAllowSymLinks) + { + std::cerr << "(II) Skipping symbolic link " << mFullPath << std::endl; + should_skip = true ; + return true ; + } + else if( ent->d_type != DT_DIR && ent->d_type != DT_REG) + { + std::cerr << "(II) Skipping file of unknown type " << ent->d_type << ": " << mFullPath << std::endl; + should_skip = true ; + return true ; + } + struct stat64 buf ; #ifdef DEBUG_FOLDER_ITERATOR diff --git a/libretroshare/src/util/folderiterator.h b/libretroshare/src/util/folderiterator.h index ed4d04013..3ff4b31e1 100644 --- a/libretroshare/src/util/folderiterator.h +++ b/libretroshare/src/util/folderiterator.h @@ -22,7 +22,7 @@ namespace librs { namespace util { class FolderIterator { public: - FolderIterator(const std::string& folderName); + FolderIterator(const std::string& folderName,bool allow_symlinks); ~FolderIterator(); enum { TYPE_UNKNOWN = 0x00, @@ -68,6 +68,7 @@ private: std::string mFileName ; std::string mFullPath ; std::string mFolderName ; + bool mAllowSymLinks; }; diff --git a/libretroshare/src/util/rsdir.cc b/libretroshare/src/util/rsdir.cc index c2ae4c916..7fe0db682 100644 --- a/libretroshare/src/util/rsdir.cc +++ b/libretroshare/src/util/rsdir.cc @@ -438,7 +438,7 @@ bool RsDirUtil::checkCreateDirectory(const std::string& dir) bool RsDirUtil::cleanupDirectory(const std::string& cleandir, const std::set &keepFiles) { - for(librs::util::FolderIterator it(cleandir);it.isValid();it.next()) + for(librs::util::FolderIterator it(cleandir,false);it.isValid();it.next()) if(it.file_type() == librs::util::FolderIterator::TYPE_FILE && (keepFiles.end() == std::find(keepFiles.begin(), keepFiles.end(), it.file_name()))) remove( (cleandir + "/" + it.file_name()).c_str() ) ;