diff --git a/libretroshare/src/file_sharing/directory_storage.h b/libretroshare/src/file_sharing/directory_storage.h index a89d6a7db..b7b64ed96 100644 --- a/libretroshare/src/file_sharing/directory_storage.h +++ b/libretroshare/src/file_sharing/directory_storage.h @@ -204,6 +204,8 @@ public: * \return */ time_t& lastSweepTime() { return mLastSweepTime ; } + + const std::string& filename() const { return mFileName ; } private: time_t mLastSavedTime ; time_t mLastSweepTime ; diff --git a/libretroshare/src/file_sharing/file_sharing_defaults.h b/libretroshare/src/file_sharing/file_sharing_defaults.h index b2b64afc9..63ad5e9f9 100644 --- a/libretroshare/src/file_sharing/file_sharing_defaults.h +++ b/libretroshare/src/file_sharing/file_sharing_defaults.h @@ -31,6 +31,9 @@ static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORY_SYNC_REQ = 120 ; // 2 min static const uint32_t DELAY_BETWEEN_LOCAL_DIRECTORIES_TS_UPDATE = 20 ; // 20 sec. But we only update for real if something has changed. static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP = 60 ; // 60 sec. +static const uint32_t DELAY_BEFORE_DELETE_NON_EMPTY_REMOTE_DIR = 60*24*86400 ; // delete non empty remoe directories after 60 days of inactivity +static const uint32_t DELAY_BEFORE_DELETE_EMPTY_REMOTE_DIR = 5*24*86400 ; // delete empty remote directories after 5 days of inactivity + static const std::string HASH_CACHE_DURATION_SS = "HASH_CACHE_DURATION" ; // key string to store hash remembering time static const std::string WATCH_FILE_DURATION_SS = "WATCH_FILES_DELAY" ; // key to store delay before re-checking for new files static const std::string WATCH_FILE_ENABLED_SS = "WATCH_FILES_ENABLED"; // key to store ON/OFF flags for file whatch diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 71a87d6fd..91a7546df 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -440,10 +440,30 @@ void p3FileDatabase::cleanup() for(std::list::const_iterator it(friend_lst.begin());it!=friend_lst.end();++it) friend_set.insert(*it) ; } + time_t now = time(NULL); for(uint32_t i=0;ipeerId()) == friend_set.end()) + if(mRemoteDirectories[i] != NULL) { + time_t recurs_mod_time ; + mRemoteDirectories[i]->getDirectoryRecursModTime(0,recurs_mod_time) ; + + time_t last_contact = 0 ; + RsPeerDetails pd ; + if(rsPeers->getPeerDetails(mRemoteDirectories[i]->peerId(),pd)) + last_contact = pd.lastConnect ; + + // We remove directories in the following situations: + // - the peer is not a friend + // - the dir list is non empty but the peer is offline since more than 60 days + // - the dir list is empty and the peer is ffline since more than 5 days + + bool should_remove = friend_set.find(mRemoteDirectories[i]->peerId()) == friend_set.end() + || (recurs_mod_time == 0 && last_contact + DELAY_BEFORE_DELETE_EMPTY_REMOTE_DIR < now ) + || (recurs_mod_time != 0 && last_contact + DELAY_BEFORE_DELETE_NON_EMPTY_REMOTE_DIR < now ); + + if(!should_remove) + continue ; #ifdef DEBUG_P3FILELISTS P3FILELISTS_DEBUG() << " removing file list of non friend " << mRemoteDirectories[i]->peerId() << std::endl; @@ -455,6 +475,10 @@ void p3FileDatabase::cleanup() mFriendIndexMap.erase(mRemoteDirectories[i]->peerId()); + // also remove the existing file + + remove(mRemoteDirectories[i]->filename().c_str()) ; + delete mRemoteDirectories[i]; mRemoteDirectories[i] = NULL ; @@ -487,8 +511,6 @@ void p3FileDatabase::cleanup() std::set online_peers ; mServCtrl->getPeersConnected(getServiceInfo().mServiceType, online_peers) ; - time_t now = time(NULL); - for(std::map::iterator it = mPendingSyncRequests.begin();it!=mPendingSyncRequests.end();) if(online_peers.find(it->second.peer_id) == online_peers.end() || it->second.request_TS + DELAY_BEFORE_DROP_REQUEST < now) {