mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
added pause to file hashing
This commit is contained in:
parent
ea25d4b5a4
commit
eff5c5d6ee
11 changed files with 95 additions and 2 deletions
|
@ -275,6 +275,15 @@ bool LocalDirectoryUpdater::filterFile(const std::string& fname) const
|
|||
return true ;
|
||||
}
|
||||
|
||||
void LocalDirectoryUpdater::togglePauseHashingProcess()
|
||||
{
|
||||
mHashCache->togglePauseHashingProcess() ;
|
||||
}
|
||||
bool LocalDirectoryUpdater::hashingProcessPaused()
|
||||
{
|
||||
return mHashCache->hashingProcessPaused();
|
||||
}
|
||||
|
||||
bool LocalDirectoryUpdater::inDirectoryCheck() const
|
||||
{
|
||||
return mHashCache->isRunning();
|
||||
|
|
|
@ -40,6 +40,8 @@ public:
|
|||
|
||||
void forceUpdate();
|
||||
bool inDirectoryCheck() const ;
|
||||
void togglePauseHashingProcess();
|
||||
bool hashingProcessPaused();
|
||||
|
||||
void setHashSalt(const RsFileHash& hash) { mHashSalt = hash; }
|
||||
const RsFileHash& hashSalt() const { return mHashSalt; }
|
||||
|
|
|
@ -44,6 +44,7 @@ HashStorage::HashStorage(const std::string& save_file_name)
|
|||
mTotalSizeToHash = 0;
|
||||
mTotalFilesToHash = 0;
|
||||
mMaxStorageDurationDays = DEFAULT_HASH_STORAGE_DURATION_DAYS ;
|
||||
mHashingProcessPaused = false;
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mHashMtx) ;
|
||||
|
@ -52,6 +53,18 @@ HashStorage::HashStorage(const std::string& save_file_name)
|
|||
try_load_import_old_hash_cache();
|
||||
}
|
||||
}
|
||||
|
||||
void HashStorage::togglePauseHashingProcess()
|
||||
{
|
||||
RS_STACK_MUTEX(mHashMtx) ;
|
||||
mHashingProcessPaused = !mHashingProcessPaused ;
|
||||
}
|
||||
bool HashStorage::hashingProcessPaused()
|
||||
{
|
||||
RS_STACK_MUTEX(mHashMtx) ;
|
||||
return mHashingProcessPaused;
|
||||
}
|
||||
|
||||
static std::string friendlyUnit(uint64_t val)
|
||||
{
|
||||
const std::string units[5] = {"B","KB","MB","GB","TB"};
|
||||
|
@ -78,12 +91,14 @@ void HashStorage::data_tick()
|
|||
RsFileHash hash;
|
||||
uint64_t size = 0;
|
||||
|
||||
|
||||
{
|
||||
bool empty ;
|
||||
uint32_t st ;
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mHashMtx) ;
|
||||
|
||||
if(mChanged && mLastSaveTime + MIN_INTERVAL_BETWEEN_HASH_CACHE_SAVE < time(NULL))
|
||||
{
|
||||
locked_save();
|
||||
|
@ -136,6 +151,19 @@ void HashStorage::data_tick()
|
|||
}
|
||||
mInactivitySleepTime = DEFAULT_INACTIVITY_SLEEP_TIME;
|
||||
|
||||
bool paused = false ;
|
||||
{
|
||||
RS_STACK_MUTEX(mHashMtx) ;
|
||||
paused = mHashingProcessPaused ;
|
||||
}
|
||||
|
||||
if(paused)
|
||||
{
|
||||
usleep(MAX_INACTIVITY_SLEEP_TIME) ;
|
||||
std::cerr << "Hashing process currently paused." << std::endl;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
RS_STACK_MUTEX(mHashMtx) ;
|
||||
|
||||
|
|
|
@ -84,6 +84,8 @@ public:
|
|||
uint32_t rememberHashFilesDuration() const { return mMaxStorageDurationDays ; }
|
||||
void clear() { mFiles.clear(); mChanged=true; } // drop all known hashes. Not something to do, except if you want to rehash the entire database
|
||||
bool empty() const { return mFiles.empty() ; }
|
||||
void togglePauseHashingProcess() ;
|
||||
bool hashingProcessPaused();
|
||||
|
||||
// Functions called by the thread
|
||||
|
||||
|
@ -112,6 +114,7 @@ private:
|
|||
std::map<std::string, HashStorageInfo> mFiles ; // stored as (full_path, hash_info)
|
||||
std::string mFilePath ; // file where the hash database is stored
|
||||
bool mChanged ;
|
||||
bool mHashingProcessPaused ;
|
||||
|
||||
struct FileHashJob
|
||||
{
|
||||
|
|
|
@ -442,7 +442,10 @@ bool p3FileDatabase::loadList(std::list<RsItem *>& load)
|
|||
std::string b ;
|
||||
for(uint32_t i=0;i<kit->value.size();++i)
|
||||
if(kit->value[i] == ';')
|
||||
{
|
||||
ignored_prefixes.push_back(b) ;
|
||||
b.clear();
|
||||
}
|
||||
else
|
||||
b.push_back(kit->value[i]) ;
|
||||
}
|
||||
|
@ -451,7 +454,10 @@ bool p3FileDatabase::loadList(std::list<RsItem *>& load)
|
|||
std::string b ;
|
||||
for(uint32_t i=0;i<kit->value.size();++i)
|
||||
if(kit->value[i] == ';')
|
||||
{
|
||||
ignored_suffixes.push_back(b) ;
|
||||
b.clear();
|
||||
}
|
||||
else
|
||||
b.push_back(kit->value[i]) ;
|
||||
}
|
||||
|
@ -972,6 +978,16 @@ void p3FileDatabase::forceDirectoryCheck() // Force re-sweep the di
|
|||
{
|
||||
mLocalDirWatcher->forceUpdate();
|
||||
}
|
||||
void p3FileDatabase::togglePauseHashingProcess()
|
||||
{
|
||||
RS_STACK_MUTEX(mFLSMtx) ;
|
||||
mLocalDirWatcher->togglePauseHashingProcess();
|
||||
}
|
||||
bool p3FileDatabase::hashingProcessPaused()
|
||||
{
|
||||
RS_STACK_MUTEX(mFLSMtx) ;
|
||||
return mLocalDirWatcher->hashingProcessPaused();
|
||||
}
|
||||
bool p3FileDatabase::inDirectoryCheck()
|
||||
{
|
||||
RS_STACK_MUTEX(mFLSMtx) ;
|
||||
|
|
|
@ -148,6 +148,8 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub
|
|||
|
||||
void forceDirectoryCheck(); // Force re-sweep the directories and see what's changed
|
||||
bool inDirectoryCheck();
|
||||
void togglePauseHashingProcess();
|
||||
bool hashingProcessPaused();
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -844,6 +844,9 @@ void ftServer::setWatchEnabled(bool b) { mFileDatabase->setWatchEnab
|
|||
void ftServer::setWatchPeriod(int minutes) { mFileDatabase->setWatchPeriod(minutes*60) ; }
|
||||
void ftServer::setFollowSymLinks(bool b) { mFileDatabase->setFollowSymLinks(b) ; }
|
||||
|
||||
void ftServer::togglePauseHashingProcess() { mFileDatabase->togglePauseHashingProcess() ; }
|
||||
bool ftServer::hashingProcessPaused() { return mFileDatabase->hashingProcessPaused() ; }
|
||||
|
||||
bool ftServer::getShareDownloadDirectory()
|
||||
{
|
||||
std::list<SharedDirInfo> dirList;
|
||||
|
|
|
@ -225,6 +225,8 @@ public:
|
|||
virtual bool watchEnabled() ;
|
||||
virtual bool followSymLinks() const;
|
||||
virtual void setFollowSymLinks(bool b);
|
||||
virtual void togglePauseHashingProcess();
|
||||
virtual bool hashingProcessPaused();
|
||||
|
||||
/***************************************************************/
|
||||
/*************** Data Transfer Interface ***********************/
|
||||
|
|
|
@ -263,6 +263,8 @@ class RsFiles
|
|||
virtual bool watchEnabled() =0;
|
||||
virtual bool followSymLinks() const=0;
|
||||
virtual void setFollowSymLinks(bool b)=0 ;
|
||||
virtual void togglePauseHashingProcess() =0; // pauses/resumes the hashing process.
|
||||
virtual bool hashingProcessPaused() =0;
|
||||
|
||||
virtual bool getShareDownloadDirectory() = 0;
|
||||
virtual bool shareDownloadDirectory(bool share) = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue