fixed bug in saving hash cache

This commit is contained in:
mr-alice 2016-09-02 22:08:27 +02:00
parent 7b566f2c55
commit 153783acb5

View File

@ -33,6 +33,16 @@ void HashStorage::data_tick()
bool empty ; bool empty ;
uint32_t st ; uint32_t st ;
{
RS_STACK_MUTEX(mHashMtx) ;
if(mChanged && mLastSaveTime + MIN_INTERVAL_BETWEEN_HASH_CACHE_SAVE < time(NULL))
{
locked_save();
mLastSaveTime = time(NULL) ;
mChanged = false ;
}
}
{ {
RS_STACK_MUTEX(mHashMtx) ; RS_STACK_MUTEX(mHashMtx) ;
@ -93,6 +103,8 @@ void HashStorage::data_tick()
// store the result // store the result
{
RS_STACK_MUTEX(mHashMtx) ;
HashStorageInfo& info(mFiles[job.full_path]); HashStorageInfo& info(mFiles[job.full_path]);
info.filename = job.full_path ; info.filename = job.full_path ;
@ -103,20 +115,12 @@ void HashStorage::data_tick()
mChanged = true ; mChanged = true ;
} }
}
// call the client // call the client
if(!hash.isNull()) if(!hash.isNull())
job.client->hash_callback(job.client_param, job.full_path, hash, size); job.client->hash_callback(job.client_param, job.full_path, hash, size);
{
RS_STACK_MUTEX(mHashMtx) ;
if(mChanged && mLastSaveTime + MIN_INTERVAL_BETWEEN_HASH_CACHE_SAVE < time(NULL))
{
locked_save();
mLastSaveTime = time(NULL) ;
mChanged = false ;
}
}
} }
bool HashStorage::requestHash(const std::string& full_path,uint64_t size,time_t mod_time,RsFileHash& known_hash,HashStorageClient *c,uint32_t client_param) bool HashStorage::requestHash(const std::string& full_path,uint64_t size,time_t mod_time,RsFileHash& known_hash,HashStorageClient *c,uint32_t client_param)
@ -170,6 +174,8 @@ bool HashStorage::requestHash(const std::string& full_path,uint64_t size,time_t
void HashStorage::clean() void HashStorage::clean()
{ {
RS_STACK_MUTEX(mHashMtx) ;
#ifdef HASHSTORAGE_DEBUG #ifdef HASHSTORAGE_DEBUG
std::cerr << "Cleaning HashStorage..." << std::endl ; std::cerr << "Cleaning HashStorage..." << std::endl ;
#endif #endif
@ -311,6 +317,7 @@ void HashStorage::locked_save()
#ifdef FIM_DEBUG #ifdef FIM_DEBUG
std::cerr << "done." << std::endl ; std::cerr << "done." << std::endl ;
#endif #endif
std::cerr << mFiles.size() << " Entries saved." << std::endl;
save_free: save_free:
free(encryptedData); free(encryptedData);