From 2d1824b01d2b091a68802b4d850a1b3800df67f7 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Sat, 6 Aug 2016 19:04:54 +0200 Subject: [PATCH] fixed virtual names --- .../src/file_sharing/directory_storage.cc | 30 ++++++++++++++++++- .../src/file_sharing/directory_updater.cc | 9 ++++++ .../src/file_sharing/directory_updater.h | 4 ++- libretroshare/src/file_sharing/hash_cache.cc | 7 +++++ libretroshare/src/file_sharing/p3filelists.cc | 7 +++++ 5 files changed, 55 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/file_sharing/directory_storage.cc b/libretroshare/src/file_sharing/directory_storage.cc index 8663dddda..b91bbe4cb 100644 --- a/libretroshare/src/file_sharing/directory_storage.cc +++ b/libretroshare/src/file_sharing/directory_storage.cc @@ -1,5 +1,6 @@ #include #include "util/rsdir.h" +#include "util/rsstring.h" #include "directory_storage.h" /******************************************************************************************************************/ @@ -374,6 +375,7 @@ time_t DirectoryStorage::FileIterator::modtime() const { const InternalFil DirectoryStorage::DirectoryStorage(const std::string& local_file_name) : mFileName(local_file_name), mDirStorageMtx("Directory storage "+local_file_name) { + RS_STACK_MUTEX(mDirStorageMtx) ; mFileHierarchy = new InternalFileHierarchyStorage(); } @@ -446,8 +448,33 @@ void LocalDirectoryStorage::setSharedDirectoryList(const std::list virtual_names ; // maps virtual to real name + std::list processed_list ; + for(std::list::const_iterator it(lst.begin());it!= lst.end();++it) - mLocalDirs[(*it).filename] = *it ; + { + int i=0; + std::string candidate_virtual_name = it->virtualname ; + + if(candidate_virtual_name.empty()) + candidate_virtual_name = RsDirUtil::getTopDir(it->filename); + + while(virtual_names.find(candidate_virtual_name) != virtual_names.end()) + rs_sprintf_append(candidate_virtual_name, "-%d", ++i); + + SharedDirInfo d(*it); + d.virtualname = candidate_virtual_name ; + processed_list.push_back(d) ; + + virtual_names.insert(candidate_virtual_name) ; + } + + mLocalDirs.clear(); + + for(std::list::const_iterator it(processed_list.begin());it!=processed_list.end();++it) + mLocalDirs[it->filename] = *it; } void LocalDirectoryStorage::getSharedDirectoryList(std::list& lst) { @@ -509,6 +536,7 @@ std::string LocalDirectoryStorage::locked_findRealRootFromVirtualFilename(const bool LocalDirectoryStorage::getFileInfo(DirectoryStorage::EntryIndex i,FileInfo& info) { + RS_STACK_MUTEX(mDirStorageMtx) ; NOT_IMPLEMENTED() ; return false; } diff --git a/libretroshare/src/file_sharing/directory_updater.cc b/libretroshare/src/file_sharing/directory_updater.cc index bccae26cf..149937901 100644 --- a/libretroshare/src/file_sharing/directory_updater.cc +++ b/libretroshare/src/file_sharing/directory_updater.cc @@ -1,4 +1,5 @@ #include "util/folderiterator.h" +#include "rsserver/p3face.h" #include "directory_storage.h" #include "directory_updater.h" @@ -31,8 +32,15 @@ void LocalDirectoryUpdater::data_tick() usleep(10*1000*1000); } +void LocalDirectoryUpdater::forceUpdate() +{ + mLastSweepTime = 0; +} + void LocalDirectoryUpdater::sweepSharedDirectories() { + RsServer::notify()->notifyListPreChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); + std::cerr << "LocalDirectoryUpdater::sweep()" << std::endl; // recursive update algorithm works that way: @@ -62,6 +70,7 @@ void LocalDirectoryUpdater::sweepSharedDirectories() std::cerr << " recursing into " << real_dir_it->filename << std::endl; recursUpdateSharedDir(real_dir_it->filename, *stored_dir_it) ; } + RsServer::notify()->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); } void LocalDirectoryUpdater::recursUpdateSharedDir(const std::string& cumulated_path, DirectoryStorage::EntryIndex indx) diff --git a/libretroshare/src/file_sharing/directory_updater.h b/libretroshare/src/file_sharing/directory_updater.h index 2d30793cd..d146a61b5 100644 --- a/libretroshare/src/file_sharing/directory_updater.h +++ b/libretroshare/src/file_sharing/directory_updater.h @@ -19,9 +19,11 @@ public: LocalDirectoryUpdater(HashStorage *hash_cache,LocalDirectoryStorage *lds) ; virtual ~LocalDirectoryUpdater() {} - virtual void data_tick() ; + virtual void forceUpdate(); protected: + virtual void data_tick() ; + virtual void hash_callback(uint32_t client_param, const std::string& name, const RsFileHash& hash, uint64_t size); void recursUpdateSharedDir(const std::string& cumulated_path,DirectoryStorage::EntryIndex indx); void sweepSharedDirectories(); diff --git a/libretroshare/src/file_sharing/hash_cache.cc b/libretroshare/src/file_sharing/hash_cache.cc index 58ca5d80a..32401ca4b 100644 --- a/libretroshare/src/file_sharing/hash_cache.cc +++ b/libretroshare/src/file_sharing/hash_cache.cc @@ -1,4 +1,5 @@ #include "util/rsdir.h" +#include "rsserver/p3face.h" #include "hash_cache.h" #define HASHSTORAGE_DEBUG 1 @@ -25,6 +26,8 @@ void HashStorage::data_tick() mRunning = false ; std::cerr << "done." << std::endl; + RsServer::notify()->notifyHashingInfo(NOTIFY_HASHTYPE_FINISH, "") ; + usleep(2*1000*1000); // when no files to hash, just wait for 2 secs. This avoids a dramatic loop. return ; } @@ -33,6 +36,10 @@ void HashStorage::data_tick() std::cerr << "Hashing file " << job.full_path << "..." ; std::cerr.flush(); + std::string tmpout; + //rs_sprintf(tmpout, "%lu/%lu (%s - %d%%) : %s", cnt+1, n_files, friendlyUnit(size).c_str(), int(size/double(total_size)*100.0), fe.name.c_str()) ; + + RsServer::notify()->notifyHashingInfo(NOTIFY_HASHTYPE_HASH_FILE, job.full_path) ; if(!RsDirUtil::getFileHash(job.full_path, hash,size, this)) std::cerr << "ERROR: cannot hash file " << job.full_path << std::endl; diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 302bc778d..299d90029 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -7,6 +7,8 @@ #include "retroshare/rsids.h" #include "retroshare/rspeers.h" +#include "rsserver/p3face.h" + #define P3FILELISTS_DEBUG() std::cerr << "p3FileLists: " static const uint32_t P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED = 0x0000 ; @@ -36,14 +38,19 @@ p3FileDatabase::p3FileDatabase(p3ServiceControl *mpeers) void p3FileDatabase::setSharedDirectories(const std::list& shared_dirs) { + RS_STACK_MUTEX(mFLSMtx) ; + mLocalSharedDirs->setSharedDirectoryList(shared_dirs) ; + mLocalDirWatcher->forceUpdate(); } void p3FileDatabase::getSharedDirectories(std::list& shared_dirs) { + RS_STACK_MUTEX(mFLSMtx) ; mLocalSharedDirs->getSharedDirectoryList(shared_dirs) ; } void p3FileDatabase::updateShareFlags(const SharedDirInfo& info) { + RS_STACK_MUTEX(mFLSMtx) ; mLocalSharedDirs->updateShareFlags(info) ; }