fix add torrent by url

This commit is contained in:
Arvid Norberg 2012-05-19 21:33:42 +00:00
parent ddbae1da86
commit 306b467b94
1 changed files with 45 additions and 7 deletions

View File

@ -730,7 +730,7 @@ namespace libtorrent
m_override_resume_data = true;
init();
announce_with_tracker();
start_announcing();
}
#else
@ -777,14 +777,50 @@ namespace libtorrent
m_ses.remove_torrent_impl(me, 0);
m_torrent_file = tf;
m_ses.m_torrents.insert(std::make_pair(m_torrent_file->info_hash(), shared_from_this()));
// now, we might already have this torrent in the session.
session_impl::torrent_map::iterator i = m_ses.m_torrents.find(m_torrent_file->info_hash());
if (i != m_ses.m_torrents.end())
{
if (!m_uuid.empty() && i->second->uuid().empty())
i->second->set_uuid(m_uuid);
if (!m_url.empty() && i->second->url().empty())
i->second->set_url(m_url);
if (!m_source_feed_url.empty() && i->second->source_feed_url().empty())
i->second->set_source_feed_url(m_source_feed_url);
// insert this torrent in the uuid index
if (!m_uuid.empty() || !m_url.empty())
{
m_ses.m_uuids.insert(std::make_pair(m_uuid.empty()
? m_url : m_uuid, i->second));
}
set_error(error_code(errors::duplicate_torrent, get_libtorrent_category()), "");
abort();
return;
}
m_ses.m_torrents.insert(std::make_pair(m_torrent_file->info_hash(), me));
if (!m_uuid.empty()) m_ses.m_uuids.insert(std::make_pair(m_uuid, me));
TORRENT_ASSERT(num_torrents == m_ses.m_torrents.size());
// TODO: if the user added any trackers while downloading the
// .torrent file, they are overwritten. Merge them into the
// new tracker list
m_trackers = m_torrent_file->trackers();
// if the user added any trackers while downloading the
// .torrent file, serge them into the new tracker list
std::vector<announce_entry> new_trackers = m_torrent_file->trackers();
for (std::vector<announce_entry>::iterator i = m_trackers.begin()
, end(m_trackers.end()); i != end; ++i)
{
// if we already have this tracker, ignore it
if (std::find_if(new_trackers.begin(), new_trackers.end()
, boost::bind(&announce_entry::url, _1) == i->url) != new_trackers.end())
continue;
// insert the tracker ordered by tier
new_trackers.insert(std::find_if(new_trackers.begin(), new_trackers.end()
, boost::bind(&announce_entry::tier, _1) >= i->tier), *i);
}
m_trackers.swap(new_trackers);
#ifndef TORRENT_DISABLE_ENCRYPTION
hasher h;
@ -799,11 +835,13 @@ namespace libtorrent
get_handle()));
}
state_updated();
set_state(torrent_status::downloading);
m_override_resume_data = true;
init();
announce_with_tracker();
start_announcing();
}
#endif