From 0485864d38666e439572675a6c2d3ca025819cf3 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Wed, 30 Sep 2009 18:36:47 +0000 Subject: [PATCH] - Fix a crash when scanned directory does not exist --- src/bittorrent.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 37a1e9acd..085d0da90 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -1044,6 +1044,11 @@ void bittorrent::saveTrackerFile(QString hash) { // Enable directory scanning void bittorrent::enableDirectoryScanning(QString scan_dir) { if(!scan_dir.isEmpty()) { + QDir newDir(scan_dir); + if(!newDir.exists()) { + qDebug("Scan dir %s does not exist, create it", scan_dir.toUtf8().data()); + newDir.mkpath(scan_dir); + } if(FSWatcher == 0) { FSMutex = new QMutex(); FSWatcher = new QFileSystemWatcher(QStringList(scan_dir), this); @@ -1051,9 +1056,12 @@ void bittorrent::enableDirectoryScanning(QString scan_dir) { // Initial scan scanDirectory(scan_dir); } else { - QString old_scan_dir = FSWatcher->directories().first(); + QString old_scan_dir = ""; + if(!FSWatcher->directories().empty()) + old_scan_dir = FSWatcher->directories().first(); if(old_scan_dir != scan_dir) { - FSWatcher->removePath(old_scan_dir); + if(!old_scan_dir.isEmpty()) + FSWatcher->removePath(old_scan_dir); FSWatcher->addPath(scan_dir); // Initial scan scanDirectory(scan_dir);