From 63694011502f63ae9e0939aac7f48deb78fdcc6b Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 27 Dec 2008 12:12:13 +0000 Subject: [PATCH] - Fixed assert hit in new FSWatcher code --- src/bittorrent.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index a272d1ffc..8e023c483 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -924,12 +924,21 @@ void bittorrent::setDefaultSavePath(QString savepath) { // Enable directory scanning void bittorrent::enableDirectoryScanning(QString scan_dir) { if(!scan_dir.isEmpty()) { - Q_ASSERT(FSWatcher == 0); - FSMutex = new QMutex(); - FSWatcher = new QFileSystemWatcher(QStringList(scan_dir), this); - connect(FSWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(scanDirectory(QString))); - // Initial scan - scanDirectory(scan_dir); + if(FSWatcher == 0) { + FSMutex = new QMutex(); + FSWatcher = new QFileSystemWatcher(QStringList(scan_dir), this); + connect(FSWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(scanDirectory(QString))); + // Initial scan + scanDirectory(scan_dir); + } else { + QString old_scan_dir = FSWatcher->directories().first(); + if(old_scan_dir != scan_dir) { + FSWatcher->removePath(old_scan_dir); + FSWatcher->addPath(scan_dir); + // Initial scan + scanDirectory(scan_dir); + } + } } }