handle invalid handles when removing torrents

This commit is contained in:
Arvid Norberg 2011-07-14 03:45:24 +00:00
parent 40fb16b703
commit 9baa134343
1 changed files with 6 additions and 3 deletions

View File

@ -869,7 +869,8 @@ void handle_alert(libtorrent::session& ses, libtorrent::alert* a
std::vector<char> out; std::vector<char> out;
bencode(std::back_inserter(out), *p->resume_data); bencode(std::back_inserter(out), *p->resume_data);
save_file(combine_path(h.save_path(), ".resume/" + to_hex(h.info_hash().to_string()) + ".resume"), out); save_file(combine_path(h.save_path(), ".resume/" + to_hex(h.info_hash().to_string()) + ".resume"), out);
if (non_files.find(h) == non_files.end() if (h.is_valid()
&& non_files.find(h) == non_files.end()
&& std::find_if(files.begin(), files.end() && std::find_if(files.begin(), files.end()
, boost::bind(&handles_t::value_type::second, _1) == h) == files.end()) , boost::bind(&handles_t::value_type::second, _1) == h) == files.end())
ses.remove_torrent(h); ses.remove_torrent(h);
@ -879,7 +880,8 @@ void handle_alert(libtorrent::session& ses, libtorrent::alert* a
{ {
--num_outstanding_resume_data; --num_outstanding_resume_data;
torrent_handle h = p->handle; torrent_handle h = p->handle;
if (non_files.find(h) == non_files.end() if (h.is_valid()
&& non_files.find(h) == non_files.end()
&& std::find_if(files.begin(), files.end() && std::find_if(files.begin(), files.end()
, boost::bind(&handles_t::value_type::second, _1) == h) == files.end()) , boost::bind(&handles_t::value_type::second, _1) == h) == files.end())
ses.remove_torrent(h); ses.remove_torrent(h);
@ -1532,6 +1534,7 @@ int main(int argc, char* argv[])
remove(combine_path(monitor_dir, i->first), ec); remove(combine_path(monitor_dir, i->first), ec);
if (ec) printf("failed to delete .torrent file: %s\n", ec.message().c_str()); if (ec) printf("failed to delete .torrent file: %s\n", ec.message().c_str());
} }
if (h.is_valid())
ses.remove_torrent(h, session::delete_files); ses.remove_torrent(h, session::delete_files);
} }
} }