From 81932b63135d7cfcf0fb2d5934320540d7ab5643 Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Sat, 7 Aug 2021 12:33:29 +0300 Subject: [PATCH] Delay processing of watched folders (#15282) Fixes regression of #14882. Closes #15272. --- src/base/torrentfileswatcher.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/base/torrentfileswatcher.cpp b/src/base/torrentfileswatcher.cpp index 51f1cbbdb..c84d25d1c 100644 --- a/src/base/torrentfileswatcher.cpp +++ b/src/base/torrentfileswatcher.cpp @@ -206,6 +206,7 @@ signals: private: void onTimeout(); + void scheduleWatchedFolderProcessing(const QString &path); void processWatchedFolder(const QString &path); void processFolder(const QString &path, const QString &watchedFolderPath, const TorrentFilesWatcher::WatchedFolderOptions &options); void processFailedTorrents(); @@ -435,7 +436,7 @@ TorrentFilesWatcher::Worker::Worker() , m_watchTimer {new QTimer(this)} , m_retryTorrentTimer {new QTimer(this)} { - connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, &Worker::processWatchedFolder); + connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, &Worker::scheduleWatchedFolderProcessing); connect(m_watchTimer, &QTimer::timeout, this, &Worker::onTimeout); connect(m_retryTorrentTimer, &QTimer::timeout, this, &Worker::processFailedTorrents); @@ -469,6 +470,14 @@ void TorrentFilesWatcher::Worker::removeWatchedFolder(const QString &path) m_retryTorrentTimer->stop(); } +void TorrentFilesWatcher::Worker::scheduleWatchedFolderProcessing(const QString &path) +{ + QTimer::singleShot(2000, this, [this, path]() + { + processWatchedFolder(path); + }); +} + void TorrentFilesWatcher::Worker::processWatchedFolder(const QString &path) { const TorrentFilesWatcher::WatchedFolderOptions options = m_watchedFolders.value(path); @@ -611,7 +620,7 @@ void TorrentFilesWatcher::Worker::addWatchedFolder(const QString &path, const To else { m_watcher->addPath(path); - QTimer::singleShot(2000, this, [this, path]() { processWatchedFolder(path); }); + scheduleWatchedFolderProcessing(path); } m_watchedFolders[path] = options; @@ -643,7 +652,7 @@ void TorrentFilesWatcher::Worker::updateWatchedFolder(const QString &path, const m_watchTimer->stop(); m_watcher->addPath(path); - QTimer::singleShot(2000, this, [this, path]() { processWatchedFolder(path); }); + scheduleWatchedFolderProcessing(path); } }