diff --git a/libretroshare/src/dbase/fimonitor.cc b/libretroshare/src/dbase/fimonitor.cc index 29bb95fe1..49437a23f 100644 --- a/libretroshare/src/dbase/fimonitor.cc +++ b/libretroshare/src/dbase/fimonitor.cc @@ -845,6 +845,7 @@ void FileIndexMonitor::updateCycle() if (fiMods) locked_saveFileIndexes(true) ; + fi.updateHashIndex() ; // update hash map that is used to accelerate search. fi.updateMaxModTime() ; // Update modification times for proper display. mInCheck = false; @@ -978,10 +979,10 @@ void FileIndexMonitor::hashFiles(const std::vector& to_hash) /* don't hit the disk too hard! */ #ifndef WINDOWS_SYS /********************************** WINDOWS/UNIX SPECIFIC PART ******************/ - usleep(40000); /* 40 msec */ + usleep(10000); /* 10 msec */ #else - Sleep(40); + Sleep(10); #endif // Save the hashing result every 60 seconds, so has to save what is already hashed. @@ -996,6 +997,7 @@ void FileIndexMonitor::hashFiles(const std::vector& to_hash) sleep(1) ; #endif RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/ + fi.updateHashIndex() ; FileIndexMonitor::locked_saveFileIndexes(true) ; last_save_size = hashed_size ; @@ -1007,6 +1009,8 @@ void FileIndexMonitor::hashFiles(const std::vector& to_hash) running = isRunning(); } + fi.updateHashIndex() ; + cb->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0); } diff --git a/libretroshare/src/dbase/findex.cc b/libretroshare/src/dbase/findex.cc index 78f70270e..cb442633b 100644 --- a/libretroshare/src/dbase/findex.cc +++ b/libretroshare/src/dbase/findex.cc @@ -515,6 +515,7 @@ FileIndex::FileIndex(const std::string& pid) { root = new PersonEntry(pid); registerEntry(root) ; + _file_hashes.clear() ; } FileIndex::~FileIndex() @@ -552,9 +553,28 @@ int FileIndex::setRootDirectories(const std::list &inlist, time_t u (it->second)->updtime = updtime; } + // update file hash index. + + updateHashIndex() ; + return 1; } +void FileIndex::updateHashIndex() +{ + _file_hashes.clear() ; + recursUpdateHashIndex(root) ; +} + +void FileIndex::recursUpdateHashIndex(DirEntry *dir) +{ + for(std::map::iterator it(dir->subdirs.begin());it!=dir->subdirs.end();++it) + recursUpdateHashIndex(it->second) ; + + for(std::map::iterator it(dir->files.begin());it!=dir->files.end();++it) + _file_hashes[it->second->hash] = it->second ; +} + void FileIndex::updateMaxModTime() { RecursUpdateMaxModTime(root) ; @@ -632,6 +652,7 @@ FileEntry *FileIndex::updateFileEntry(const std::string& fpath, const FileEntry& #endif return NULL; } + return parent -> updateFile(fe, utime); } @@ -909,6 +930,8 @@ int FileIndex::loadIndex(const std::string& filename, const std::string& expecte } } + updateHashIndex() ; + return 1; /* parse error encountered */ @@ -1072,10 +1095,17 @@ int DirEntry::saveEntry(std::string &s) int FileIndex::searchHash(const std::string& hash, std::list &results) const { -#ifdef FI_DEBUG +//#ifdef FI_DEBUG std::cerr << "FileIndex::searchHash(" << hash << ")"; std::cerr << std::endl; -#endif +//#endif + + std::map::const_iterator it = _file_hashes.find(hash) ; + + if(it!=_file_hashes.end() && isValid((void*)it->second)) + results.push_back(it->second) ; + +#ifdef OLD_CODE_PLZ_REMOVE DirEntry *ndir = NULL; std::list dirlist; dirlist.push_back(root); @@ -1106,6 +1136,7 @@ int FileIndex::searchHash(const std::string& hash, std::list &resul } } } +#endif return 0; } diff --git a/libretroshare/src/dbase/findex.h b/libretroshare/src/dbase/findex.h index 18d54c56e..4546f354c 100644 --- a/libretroshare/src/dbase/findex.h +++ b/libretroshare/src/dbase/findex.h @@ -257,6 +257,11 @@ class FileIndex void *findRef(const std::string& path) const ; bool extractData(const std::string& path,DirDetails& details) const ; + + void updateHashIndex() ; + void recursUpdateHashIndex(DirEntry *) ; + + std::map _file_hashes ; };