[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/network/ktorrent
From: Joris Guisson <joris.guisson () gmail ! com>
Date: 2010-08-31 17:33:36
Message-ID: 20100831173336.4AAA4AC857 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1170362 by guisson:
Prevent torrents from sharing the same files
BUG: 228220
M +1 -0 ChangeLog
M +22 -2 ktorrent/core.cpp
M +20 -7 ktorrent/dialogs/fileselectdlg.cpp
M +3 -1 ktorrent/dialogs/fileselectdlg.h
M +1 -1 ktorrent/gui.cpp
M +38 -0 libktcore/torrent/queuemanager.cpp
M +8 -0 libktcore/torrent/queuemanager.h
--- trunk/extragear/network/ktorrent/ChangeLog #1170361:1170362
@@ -19,6 +19,7 @@
- Add support for emule blocklists (194915)
- Add option to configure the number of log lines shown in the logviewer (223887)
- Add default move on completion location to group policy (248092)
+- Prevent torrents from sharing the same files (228220)
Changes in 4.0.3:
- Fix bug causing wrong encoding to be used when the default save location of a \
group is read (244873)
--- trunk/extragear/network/ktorrent/ktorrent/core.cpp #1170361:1170362
@@ -251,6 +251,17 @@
if (Settings::useCompletedDir() && silently)
tc->setMoveWhenCompletedDir(Settings::completedDir());
+ if (qman->alreadyLoaded(tc->getInfoHash()))
+ {
+ Out(SYS_GEN|LOG_IMPORTANT) << "Torrent " << tc->getDisplayName() << " already \
loaded" << endl; + // Cleanup tor dir
+ QString dir = tc->getTorDir();
+ if (bt::Exists(dir))
+ bt::Delete(dir,true);
+ delete tc;
+ return false;
+ }
+
if (!silently)
{
if (!gui->selectFiles(tc,&start_torrent,group,location,&skip_check))
@@ -290,9 +301,18 @@
}
}
- if (qman->alreadyLoaded(tc->getInfoHash()))
+ QStringList conflicting;
+ if (qman->checkFileConflicts(tc,conflicting))
{
- Out(SYS_GEN|LOG_IMPORTANT) << "Torrent " << tc->getDisplayName() << " already \
loaded" << endl; + Out(SYS_GEN|LOG_IMPORTANT) << "Torrent " << tc->getDisplayName() \
<< " conflicts with the following torrents: " << endl; + Out(SYS_GEN|LOG_IMPORTANT) \
<< conflicting.join(", ") << endl; + if (!silently)
+ {
+ QString err = i18n("Opening the torrent <b>%1</b>, "
+ "would share one or more files with the following torrents. ."
+ "Torrents are not allowed to write to the same files. ", \
tc->getDisplayName()); + KMessageBox::errorList(gui,err,conflicting);
+ }
// Cleanup tor dir
QString dir = tc->getTorDir();
if (bt::Exists(dir))
--- trunk/extragear/network/ktorrent/ktorrent/dialogs/fileselectdlg.cpp \
#1170361:1170362 @@ -35,6 +35,7 @@
#include <interfaces/functions.h>
#include <groups/group.h>
#include <groups/groupmanager.h>
+#include <torrent/queuemanager.h>
#include <torrent/torrentfiletreemodel.h>
#include <torrent/torrentfilelistmodel.h>
#include "fileselectdlg.h"
@@ -45,7 +46,8 @@
namespace kt
{
- FileSelectDlg::FileSelectDlg(kt::GroupManager* gman,const QString & \
group_hint,QWidget* parent) : \
KDialog(parent),gman(gman),initial_group(0),show_file_tree(true) \
+ FileSelectDlg::FileSelectDlg(kt::QueueManager* qman,kt::GroupManager* gman,const \
QString & group_hint,QWidget* parent) + : \
KDialog(parent),qman(qman),gman(gman),initial_group(0),show_file_tree(true) {
setupUi(mainWidget());
m_file_view->setAlternatingRowColors(true);
@@ -315,12 +317,6 @@
}
}
- for (Uint32 i = 0;i < tc->getNumFiles();i++)
- {
- bt::TorrentFileInterface & file = tc->getTorrentFile(i);
- file.setEmitDownloadStatusChanged(true);
- }
-
//Setup custom download location
QString ddir = tc->getDataDir();
if (!ddir.endsWith(bt::DirSeparator()))
@@ -331,6 +327,23 @@
else if (dn != ddir)
tc->changeOutputDir(dn, 0);
+ QStringList conflicting;
+ if (qman->checkFileConflicts(tc,conflicting))
+ {
+ QString err = i18n("Opening the torrent <b>%1</b>, "
+ "would share one or more files with the following torrents. "
+ "Torrents are not allowed to write to the same files. "
+ "Please select a different location.", tc->getDisplayName());
+ KMessageBox::errorList(this,err,conflicting);
+ return;
+ }
+
+ for (Uint32 i = 0;i < tc->getNumFiles();i++)
+ {
+ bt::TorrentFileInterface & file = tc->getTorrentFile(i);
+ file.setEmitDownloadStatusChanged(true);
+ }
+
//Make it user controlled if needed
*start = m_chkStartTorrent->isChecked();
*skip_check = m_skip_data_check->isChecked();
--- trunk/extragear/network/ktorrent/ktorrent/dialogs/fileselectdlg.h \
#1170361:1170362 @@ -35,6 +35,7 @@
namespace kt
{
class GroupManager;
+ class QueueManager;
class TorrentFileModel;
class Group;
@@ -48,7 +49,7 @@
Q_OBJECT
public:
- FileSelectDlg(kt::GroupManager* gman,const QString & group_hint,QWidget* parent);
+ FileSelectDlg(kt::QueueManager* qman,kt::GroupManager* gman,const QString & \
group_hint,QWidget* parent); virtual ~FileSelectDlg();
int execute(bt::TorrentInterface* tc, bool* start,bool* skip_check,const QString & \
location_hint); @@ -91,6 +92,7 @@
private:
bt::TorrentInterface* tc;
TorrentFileModel* model;
+ kt::QueueManager* qman;
kt::GroupManager* gman;
bool* start;
bool* skip_check;
--- trunk/extragear/network/ktorrent/ktorrent/gui.cpp #1170361:1170362
@@ -243,7 +243,7 @@
bool GUI::selectFiles(bt::TorrentInterface* tc,bool* start_torrent,const QString & \
group_hint,const QString & location_hint,bool* skip_check) {
- FileSelectDlg dlg(core->getGroupManager(),group_hint,this);
+ FileSelectDlg dlg(core->getQueueManager(),core->getGroupManager(),group_hint,this);
dlg.loadState(KGlobal::config());
bool ret = dlg.execute(tc,start_torrent,skip_check,location_hint) == \
QDialog::Accepted; dlg.saveState(KGlobal::config());
--- trunk/extragear/network/ktorrent/libktcore/torrent/queuemanager.cpp \
#1170361:1170362 @@ -887,8 +887,46 @@
}
}
+ bool QueueManager::checkFileConflicts(TorrentInterface* tc, QStringList & \
conflicting) const + {
+ conflicting.clear();
+ // First get a set off all files of tc
+ QSet<QString> files;
+ if (tc->getStats().multi_file_torrent)
+ {
+ for (bt::Uint32 i = 0;i < tc->getNumFiles();i++)
+ files.insert(tc->getTorrentFile(i).getPathOnDisk());
+ }
+ else
+ files.insert(tc->getStats().output_path);
+ foreach (bt::TorrentInterface* t, downloads)
+ {
+ if (t == tc)
+ continue;
+
+ if (t->getStats().multi_file_torrent)
+ {
+ for (bt::Uint32 i = 0;i < t->getNumFiles();i++)
+ {
+ if (files.contains(t->getTorrentFile(i).getPathOnDisk()))
+ {
+ conflicting.append(t->getDisplayName());
+ break;
+ }
+ }
+ }
+ else
+ {
+ if (files.contains(t->getStats().output_path))
+ conflicting.append(t->getDisplayName());
+ }
+ }
+
+ return !conflicting.isEmpty();
+ }
+
/////////////////////////////////////////////////////////////////////////////////////////////
--- trunk/extragear/network/ktorrent/libktcore/torrent/queuemanager.h \
#1170361:1170362 @@ -225,6 +225,14 @@
*/
void reindexQueue();
+ /**
+ * Check if a torrent has file conflicts with other torrents.
+ * If conflicting are found, a list of names of the conflicting torrents is filled \
in. + * @param tc The torrent
+ * @param conflicting List of conflicting torrents
+ */
+ bool checkFileConflicts(bt::TorrentInterface* tc, QStringList & conflicting) \
const; +
public slots:
/**
* Places all torrents from downloads in the right order in queue.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic