From 408fec30ed55f2411b536cd3f6bd3ec1aa1dc448 Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Mon, 18 Nov 2013 18:01:30 -0200 Subject: [PATCH] periodically save user_data --- src/twister.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/twister.cpp b/src/twister.cpp index d017fa4e..2fa87516 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -338,6 +338,16 @@ void saveTorrentResumeData() } } +void lockAndSaveUserData() +{ + LOCK(cs_twister); + if( m_users.size() ) { + printf("saving user_data (followers and DMs)...\n"); + boost::filesystem::path userDataPath = GetDataDir() / USER_DATA_FILE; + saveUserData(userDataPath.string(), m_users); + } +} + int getDhtNodes() { if( !ses ) @@ -446,6 +456,7 @@ void ThreadMaintainDHTNodes() if( GetTime() > lastSaveResumeTime + 15 * 60 ) { lastSaveResumeTime = GetTime(); saveTorrentResumeData(); + lockAndSaveUserData(); } MilliSleep(5000); @@ -645,11 +656,7 @@ void stopSessionTorrent() boost::filesystem::path globalDataPath = GetDataDir() / GLOBAL_DATA_FILE; saveGlobalData(globalDataPath.string()); - if( m_users.size() ) { - printf("saving user_data (followers and DMs)...\n"); - boost::filesystem::path userDataPath = GetDataDir() / USER_DATA_FILE; - saveUserData(userDataPath.string(), m_users); - } + lockAndSaveUserData(); printf("libtorrent + dht stopped\n"); }