diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 85aef16b8..e67808cd5 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -127,6 +127,8 @@ namespace libtorrent static sha1_hash empty; return m_torrent_file ? m_torrent_file->info_hash() : empty; } + + bool is_deleted() const { return m_deleted; } // starts the announce timer void start(); @@ -1388,6 +1390,11 @@ namespace libtorrent // accidentally start seeding it without any authentication. bool m_ssl_torrent:1; + // this is set to true if we're trying to delete the + // files belonging to it. When set, don't write any + // more blocks to disk! + bool m_deleted:1; + #if defined TORRENT_DEBUG || TORRENT_RELEASE_ASSERTS public: // set to false until we've loaded resume data diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 17d0b5680..0d87909b2 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -2472,6 +2472,8 @@ namespace libtorrent } } + if (t->is_deleted()) return; + int write_queue_size = fs.async_write(p, data, boost::bind(&peer_connection::on_disk_write_complete , self(), _1, _2, p, t)); m_outstanding_writing_bytes += p.length; diff --git a/src/torrent.cpp b/src/torrent.cpp index bcafcf3a5..6e0ee019a 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -428,6 +428,7 @@ namespace libtorrent , m_is_active_download(false) , m_is_active_finished(false) , m_ssl_torrent(false) + , m_deleted(false) { // if there is resume data already, we don't need to trigger the initial save // resume data @@ -1220,6 +1221,8 @@ namespace libtorrent int piece_size = m_torrent_file->piece_size(piece); int blocks_in_piece = (piece_size + block_size() - 1) / block_size(); + if (m_deleted) return; + // avoid crash trying to access the picker when there is none if (!has_picker()) return; @@ -7029,6 +7032,7 @@ namespace libtorrent TORRENT_ASSERT(m_storage); m_storage->async_delete_files( boost::bind(&torrent::on_files_deleted, shared_from_this(), _1, _2)); + m_deleted = true; return true; } return false;