Browse Source

Duplicate torrent trackers and url seeds are added to existing torrent even if it was added through folder scanning

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
f833f26212
  1. 101
      src/bittorrent.cpp

101
src/bittorrent.cpp

@ -70,13 +70,13 @@ enum VersionType { NORMAL,ALPHA,BETA,RELEASE_CANDIDATE,DEVEL };
// Main constructor // Main constructor
Bittorrent::Bittorrent() Bittorrent::Bittorrent()
: m_scanFolders(ScanFoldersModel::instance(this)), : m_scanFolders(ScanFoldersModel::instance(this)),
preAllocateAll(false), addInPause(false), ratio_limit(-1), preAllocateAll(false), addInPause(false), ratio_limit(-1),
UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false), UPnPEnabled(false), NATPMPEnabled(false), LSDEnabled(false),
DHTEnabled(false), current_dht_port(0), queueingEnabled(false), DHTEnabled(false), current_dht_port(0), queueingEnabled(false),
torrentExport(false), exiting(false) torrentExport(false), exiting(false)
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
, geoipDBLoaded(false), resolve_countries(false) , geoipDBLoaded(false), resolve_countries(false)
#endif #endif
{ {
// To avoid some exceptions // To avoid some exceptions
@ -972,56 +972,55 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
if(s->find_torrent(t->info_hash()).is_valid()) { if(s->find_torrent(t->info_hash()).is_valid()) {
qDebug("/!\\ Torrent is already in download list"); qDebug("/!\\ Torrent is already in download list");
// Update info Bar // Update info Bar
if(!fromScanDir) { if(!from_url.isNull()) {
if(!from_url.isNull()) { // If download from url, remove temp file
// If download from url, remove temp file QFile::remove(file);
QFile::remove(file); addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(from_url));
addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(from_url)); //emit duplicateTorrent(from_url);
//emit duplicateTorrent(from_url); }else{
}else{ addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(file));
addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(file)); //emit duplicateTorrent(file);
//emit duplicateTorrent(file); }
} // Check if the torrent contains trackers or url seeds we don't know about
// Check if the torrent contains trackers or url seeds we don't know about // and add them
// and add them QTorrentHandle h_ex = getTorrentHandle(hash);
QTorrentHandle h_ex = getTorrentHandle(hash); if(h_ex.is_valid()) {
if(h_ex.is_valid()) { std::vector<announce_entry> old_trackers = h_ex.trackers();
std::vector<announce_entry> old_trackers = h_ex.trackers(); std::vector<announce_entry> new_trackers = t->trackers();
std::vector<announce_entry> new_trackers = t->trackers(); bool trackers_added = false;
bool trackers_added = false; for(std::vector<announce_entry>::iterator it=new_trackers.begin();it!=new_trackers.end();it++) {
for(std::vector<announce_entry>::iterator it=new_trackers.begin();it!=new_trackers.end();it++) { std::string tracker_url = it->url;
std::string tracker_url = it->url; bool found = false;
bool found = false; for(std::vector<announce_entry>::iterator itold=old_trackers.begin();itold!=old_trackers.end();itold++) {
for(std::vector<announce_entry>::iterator itold=old_trackers.begin();itold!=old_trackers.end();itold++) { if(tracker_url == itold->url) {
if(tracker_url == itold->url) { found = true;
found = true; break;
break;
}
}
if(found) {
trackers_added = true;
announce_entry entry(tracker_url);
h_ex.add_tracker(entry);
} }
} }
if(trackers_added) { if(found) {
addConsoleMessage(tr("Note: new trackers were added to the existing torrent.")); trackers_added = true;
} announce_entry entry(tracker_url);
bool urlseeds_added = false; h_ex.add_tracker(entry);
const QStringList &old_urlseeds = h_ex.url_seeds();
std::vector<std::string> new_urlseeds = t->url_seeds();
for(std::vector<std::string>::iterator it = new_urlseeds.begin(); it != new_urlseeds.end(); it++) {
const QString &new_url = misc::toQString(it->c_str());
if(!old_urlseeds.contains(new_url)) {
urlseeds_added = true;
h_ex.add_url_seed(new_url);
}
} }
if(urlseeds_added) { }
addConsoleMessage(tr("Note: new URL seeds were added to the existing torrent.")); if(trackers_added) {
addConsoleMessage(tr("Note: new trackers were added to the existing torrent."));
}
bool urlseeds_added = false;
const QStringList &old_urlseeds = h_ex.url_seeds();
std::vector<std::string> new_urlseeds = t->url_seeds();
for(std::vector<std::string>::iterator it = new_urlseeds.begin(); it != new_urlseeds.end(); it++) {
const QString &new_url = misc::toQString(it->c_str());
if(!old_urlseeds.contains(new_url)) {
urlseeds_added = true;
h_ex.add_url_seed(new_url);
} }
} }
}else{ if(urlseeds_added) {
addConsoleMessage(tr("Note: new URL seeds were added to the existing torrent."));
}
}
if(fromScanDir) {
// Delete torrent from scan dir // Delete torrent from scan dir
QFile::remove(file); QFile::remove(file);
} }

Loading…
Cancel
Save