BUGFIX: Fix possible crash with folder scanning

This commit is contained in:
Christophe Dumez
2010-03-22 18:57:32 +00:00
parent 10c4fd330a
commit 0af5d82114
6 changed files with 34 additions and 23 deletions

View File

@@ -1,6 +1,8 @@
* Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.2.2 * Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.2.2
- BUGFIX: Fix possible crash with folder scanning
- BUGFIX: Fix Mac compilation - BUGFIX: Fix Mac compilation
- BUGFIX: Save fast resume data every 3 minutes (for robustness) - BUGFIX: Save fast resume data every 3 minutes (for robustness)
- I18N: Updated Polish translation (thanks Szymon Świerkosz)
* Sat Mar 20 2010 - Christophe Dumez <chris@qbittorrent.org> - v2.2.1 * Sat Mar 20 2010 - Christophe Dumez <chris@qbittorrent.org> - v2.2.1
- FEATURE: Display pieces that are being downloaded - FEATURE: Display pieces that are being downloaded

View File

@@ -281,12 +281,14 @@ void Bittorrent::configureSession() {
startTorrentsInPause(Preferences::addTorrentsInPause()); startTorrentsInPause(Preferences::addTorrentsInPause());
// * Scan dirs // * Scan dirs
const QStringList &scan_dirs = Preferences::getScanDirs(); const QStringList &scan_dirs = Preferences::getScanDirs();
foreach (const QString &dir, scan_dirs) { QVariantList downloadInDirList = Preferences::getDownloadInScanDirs();
m_scanFolders->addPath(dir); while(scan_dirs.size() > downloadInDirList.size()) {
downloadInDirList << QVariant(false);
} }
const QVariantList &downloadInDirList = Preferences::getDownloadInScanDirs(); int i = 0;
for (int i = 0; i < downloadInDirList.count(); ++i) { foreach (const QString &dir, scan_dirs) {
m_scanFolders->setDownloadAtPath(i, downloadInDirList.at(i).toBool()); m_scanFolders->addPath(dir, downloadInDirList.at(i).toBool());
++i;
} }
// * Export Dir // * Export Dir
const bool newTorrentExport = Preferences::isTorrentExportEnabled(); const bool newTorrentExport = Preferences::isTorrentExportEnabled();

View File

@@ -130,25 +130,29 @@ void EventManager::setGlobalPreferences(QVariantMap m) const {
Preferences::setTempPathEnabled(m["temp_path_enabled"].toBool()); Preferences::setTempPathEnabled(m["temp_path_enabled"].toBool());
if(m.contains("temp_path")) if(m.contains("temp_path"))
Preferences::setTempPath(m["temp_path"].toString()); Preferences::setTempPath(m["temp_path"].toString());
if(m.contains("scan_dirs")) { if(m.contains("scan_dirs") && m.contains("download_in_scan_dirs")) {
QVariantList download_at_path = m["download_in_scan_dirs"].toList();
QStringList old_folders = Preferences::getScanDirs(); QStringList old_folders = Preferences::getScanDirs();
QStringList new_folders = m["scan_dirs"].toStringList(); QStringList new_folders = m["scan_dirs"].toStringList();
foreach(const QString &old_folder, old_folders) {
// Update deleted folders
if(!new_folders.contains(old_folder)) {
BTSession->getScanFoldersModel()->removePath(old_folder);
}
}
foreach(const QString &new_folder, new_folders) {
// Update new folders
if(!old_folders.contains(new_folder)) {
BTSession->getScanFoldersModel()->addPath(new_folder);
}
}
Preferences::setScanDirs(new_folders); Preferences::setScanDirs(new_folders);
Preferences::setDownloadInScanDirs(download_at_path);
if(download_at_path.size() == new_folders.size()) {
foreach(const QString &old_folder, old_folders) {
// Update deleted folders
if(!new_folders.contains(old_folder)) {
BTSession->getScanFoldersModel()->removePath(old_folder);
}
}
int i = 0;
foreach(const QString &new_folder, new_folders) {
// Update new folders
if(!old_folders.contains(new_folder)) {
BTSession->getScanFoldersModel()->addPath(new_folder, download_at_path.at(i).toBool());
}
++i;
}
}
} }
if(m.contains("download_in_scan_dirs"))
Preferences::setDownloadInScanDirs(m["download_in_scan_dirs"].toList());
if(m.contains("export_dir")) if(m.contains("export_dir"))
Preferences::setExportDir(m["export_dir"].toString()); Preferences::setExportDir(m["export_dir"].toString());
if(m.contains("preallocate_all")) if(m.contains("preallocate_all"))

View File

@@ -1379,7 +1379,7 @@ int options_imp::getActionOnDblClOnTorrentFn() const {
void options_imp::on_addScanFolderButton_clicked() { void options_imp::on_addScanFolderButton_clicked() {
const QString dir = QFileDialog::getExistingDirectory(this, tr("Add directory to scan")); const QString dir = QFileDialog::getExistingDirectory(this, tr("Add directory to scan"));
if (!dir.isEmpty()) { if (!dir.isEmpty()) {
const ScanFoldersModel::PathStatus status = ScanFoldersModel::instance()->addPath(dir); const ScanFoldersModel::PathStatus status = ScanFoldersModel::instance()->addPath(dir, false);
QString error; QString error;
switch (status) { switch (status) {
case ScanFoldersModel::AlreadyInList: case ScanFoldersModel::AlreadyInList:

View File

@@ -110,7 +110,7 @@ bool ScanFoldersModel::setData(const QModelIndex &index, const QVariant &value,
return true; return true;
} }
ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &path) { ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &path, bool download_at_path) {
QDir dir(path); QDir dir(path);
if (!dir.exists()) if (!dir.exists())
return DoesNotExist; return DoesNotExist;
@@ -126,6 +126,9 @@ ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &path) {
beginInsertRows(QModelIndex(), rowCount(), rowCount()); beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_pathList << new PathData(canonicalPath); m_pathList << new PathData(canonicalPath);
endInsertRows(); endInsertRows();
// Set download at path
setDownloadAtPath(m_pathList.size()-1, download_at_path);
// Start scanning
m_fsWatcher->addPath(canonicalPath); m_fsWatcher->addPath(canonicalPath);
return Ok; return Ok;
} }

View File

@@ -55,7 +55,7 @@ public:
// TODO: removePaths(); singular version becomes private helper functions; // TODO: removePaths(); singular version becomes private helper functions;
// also: remove functions should take modelindexes // also: remove functions should take modelindexes
PathStatus addPath(const QString &path); PathStatus addPath(const QString &path, bool download_at_path);
void removePath(int row); void removePath(int row);
bool removePath(const QString &path); bool removePath(const QString &path);
PathStatus setDownloadAtPath(int row, bool downloadAtPath); PathStatus setDownloadAtPath(int row, bool downloadAtPath);