From faa2f12f2ebf690fb59400e3fca1302fcd034fd4 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 29 Jan 2020 22:04:29 +0100 Subject: [PATCH] added optional delay to check files after download in order to prevent skiping recently downloaded files --- src/file_sharing/directory_updater.cc | 9 ++++++--- src/file_sharing/directory_updater.h | 2 +- src/file_sharing/file_sharing_defaults.h | 2 +- src/file_sharing/p3filelists.cc | 6 +++--- src/file_sharing/p3filelists.h | 2 +- src/ft/ftcontroller.cc | 2 +- src/ft/ftserver.cc | 4 ++-- src/ft/ftserver.h | 2 +- src/retroshare/rsfiles.h | 3 ++- 9 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/file_sharing/directory_updater.cc b/src/file_sharing/directory_updater.cc index 254c9ebe3..406c44024 100644 --- a/src/file_sharing/directory_updater.cc +++ b/src/file_sharing/directory_updater.cc @@ -107,10 +107,13 @@ void LocalDirectoryUpdater::threadTick() } } -void LocalDirectoryUpdater::forceUpdate() +void LocalDirectoryUpdater::forceUpdate(bool add_safe_delay) { mForceUpdate = true ; - mLastSweepTime = 0 ; + mLastSweepTime = rstime_t(time(NULL)) - rstime_t(mDelayBetweenDirectoryUpdates) ; + + if(add_safe_delay) + mLastSweepTime += rstime_t(MIN_TIME_AFTER_LAST_MODIFICATION); if(mHashCache != NULL && mHashCache->hashingProcessPaused()) mHashCache->togglePauseHashingProcess(); @@ -363,7 +366,7 @@ void LocalDirectoryUpdater::setFollowSymLinks(bool b) mFollowSymLinks = b ; - forceUpdate(); + forceUpdate(false); } bool LocalDirectoryUpdater::followSymLinks() const diff --git a/src/file_sharing/directory_updater.h b/src/file_sharing/directory_updater.h index 4b95daabe..b7d72b3a9 100644 --- a/src/file_sharing/directory_updater.h +++ b/src/file_sharing/directory_updater.h @@ -35,7 +35,7 @@ public: LocalDirectoryUpdater(HashStorage *hash_cache,LocalDirectoryStorage *lds) ; virtual ~LocalDirectoryUpdater() {} - void forceUpdate(); + void forceUpdate(bool add_safe_delay); bool inDirectoryCheck() const ; void togglePauseHashingProcess(); bool hashingProcessPaused(); diff --git a/src/file_sharing/file_sharing_defaults.h b/src/file_sharing/file_sharing_defaults.h index 75f19075a..92ff43947 100644 --- a/src/file_sharing/file_sharing_defaults.h +++ b/src/file_sharing/file_sharing_defaults.h @@ -48,7 +48,7 @@ static const std::string LOCAL_SHARED_DIRS_FILE_NAME = "local_dir_hierarchy.bin" static const uint32_t MIN_INTERVAL_BETWEEN_HASH_CACHE_SAVE = 20 ; // never save hash cache more often than every 20 secs. static const uint32_t MIN_INTERVAL_BETWEEN_REMOTE_DIRECTORY_SAVE = 23 ; // never save remote directories more often than this -static const uint32_t MIN_TIME_AFTER_LAST_MODIFICATION = 20 ; // never hash a file that is just being modified, otherwise we end up with a corrupted hash +static const uint32_t MIN_TIME_AFTER_LAST_MODIFICATION = 10 ; // never hash a file that is just being modified, otherwise we end up with a corrupted hash static const uint32_t MAX_DIR_SYNC_RESPONSE_DATA_SIZE = 20000 ; // Maximum RsItem data size in bytes for serialised directory transmission static const uint32_t DEFAULT_HASH_STORAGE_DURATION_DAYS = 30 ; // remember deleted/inaccessible files for 30 days diff --git a/src/file_sharing/p3filelists.cc b/src/file_sharing/p3filelists.cc index e4ea57dc7..c7db78b0f 100644 --- a/src/file_sharing/p3filelists.cc +++ b/src/file_sharing/p3filelists.cc @@ -114,7 +114,7 @@ void p3FileDatabase::setSharedDirectories(const std::list& shared RS_STACK_MUTEX(mFLSMtx) ; mLocalSharedDirs->setSharedDirectoryList(shared_dirs) ; - mLocalDirWatcher->forceUpdate(); + mLocalDirWatcher->forceUpdate(false); } @@ -1231,9 +1231,9 @@ uint32_t p3FileDatabase::getType(void *ref,FileSearchFlags flags) const } } -void p3FileDatabase::forceDirectoryCheck() // Force re-sweep the directories and see what's changed +void p3FileDatabase::forceDirectoryCheck(bool add_safe_delay) // Force re-sweep the directories and see what's changed { - mLocalDirWatcher->forceUpdate(); + mLocalDirWatcher->forceUpdate(add_safe_delay); } void p3FileDatabase::togglePauseHashingProcess() { diff --git a/src/file_sharing/p3filelists.h b/src/file_sharing/p3filelists.h index 7ddc6d282..41e8cbeaf 100644 --- a/src/file_sharing/p3filelists.h +++ b/src/file_sharing/p3filelists.h @@ -168,7 +168,7 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub // interfact for directory parsing - void forceDirectoryCheck(); // Force re-sweep the directories and see what's changed + void forceDirectoryCheck(bool add_safe_delay); // Force re-sweep the directories and see what's changed bool inDirectoryCheck(); void togglePauseHashingProcess(); bool hashingProcessPaused(); diff --git a/src/ft/ftcontroller.cc b/src/ft/ftcontroller.cc index d682caba7..45fc70845 100644 --- a/src/ft/ftcontroller.cc +++ b/src/ft/ftcontroller.cc @@ -821,7 +821,7 @@ bool ftController::completeFile(const RsFileHash& hash) RsServer::notify()->notifyDownloadComplete(hash.toStdString()); RsServer::notify()->notifyDownloadCompleteCount(completeCount); - rsFiles->ForceDirectoryCheck() ; + rsFiles->ForceDirectoryCheck(true) ; IndicateConfigChanged(); /* completed transfer -> save */ return true; diff --git a/src/ft/ftserver.cc b/src/ft/ftserver.cc index 293da6d51..256543da6 100644 --- a/src/ft/ftserver.cc +++ b/src/ft/ftserver.cc @@ -791,9 +791,9 @@ void ftServer::updateSinceGroupPermissionsChanged() { mFileDatabase->forceSyncWithPeers(); } -void ftServer::ForceDirectoryCheck() +void ftServer::ForceDirectoryCheck(bool add_safe_delay) { - mFileDatabase->forceDirectoryCheck(); + mFileDatabase->forceDirectoryCheck(add_safe_delay); return; } diff --git a/src/ft/ftserver.h b/src/ft/ftserver.h index 0cc88d6aa..6f719c04e 100644 --- a/src/ft/ftserver.h +++ b/src/ft/ftserver.h @@ -275,7 +275,7 @@ public: * Utility Functions ***/ virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath); - virtual void ForceDirectoryCheck(); + virtual void ForceDirectoryCheck(bool add_safe_delay); virtual void updateSinceGroupPermissionsChanged() ; virtual bool InDirectoryCheck(); virtual bool copyFile(const std::string& source, const std::string& dest); diff --git a/src/retroshare/rsfiles.h b/src/retroshare/rsfiles.h index daa83d3bc..e0793d8b7 100644 --- a/src/retroshare/rsfiles.h +++ b/src/retroshare/rsfiles.h @@ -591,9 +591,10 @@ public: /** * @brief Force shared directories check + * @param[in] add_safe_delay Schedule the check 20 seconds from now, to ensure to capture files written just now. * @jsonapi{development} */ - virtual void ForceDirectoryCheck() = 0; + virtual void ForceDirectoryCheck(bool add_safe_delay=false) = 0; virtual void updateSinceGroupPermissionsChanged() = 0; virtual bool InDirectoryCheck() = 0;