diff --git a/ChangeLog b/ChangeLog index 85df2b7e4..80be059c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -85,6 +85,8 @@ incoming connection * added more detailed instrumentation of the disk I/O thread + * fixed bug in session::delete_files option to remove_torrent + 0.15.6 release * fixed crash in udp trackers when using SOCKS5 proxy diff --git a/examples/client_test.cpp b/examples/client_test.cpp index e8b57d0b2..131cec73a 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -1377,6 +1377,32 @@ int main(int argc, char* argv[]) if (c == 'q') break; + if (c == 'D') + { + torrent_handle h = get_active_torrent(handles).handle; + if (h.is_valid()) + { + printf("\n\nARE YOU SURE YOU WANT TO DELETE THE FILES FOR '%s'. THIS OPERATION CANNOT BE UNDONE. (y/N)" + , h.name().c_str()); + char response = 'n'; + scanf("%c", &response); + if (response == 'y') + { + // also delete the .torrent file from the torrent directory + handles_t::iterator i = std::find_if(files.begin(), files.end() + , boost::bind(&handles_t::value_type::second, _1) == h); + if (i != files.end()) + { + files.erase(i); + error_code ec; + remove(combine_path(monitor_dir, i->first), ec); + if (ec) printf("failed to delete .torrent file: %s\n", ec.message().c_str()); + } + ses.remove_torrent(h, session::delete_files); + } + } + } + if (c == 'j' && !handles.empty()) { get_active_torrent(handles).handle.force_recheck(); diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 361e00981..0d037f31d 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -2377,6 +2377,7 @@ namespace libtorrent mutex::scoped_lock l(m_piece_mutex); INVARIANT_CHECK; + // delete all write cache entries for this storage cache_piece_index_t& idx = m_pieces.get<0>(); cache_piece_index_t::iterator start = idx.lower_bound(std::pair(j.storage.get(), 0)); cache_piece_index_t::iterator end = idx.upper_bound(std::pair(j.storage.get(), INT_MAX)); @@ -2384,17 +2385,21 @@ namespace libtorrent // build a vector of all the buffers we need to free // and free them all in one go std::vector buffers; + torrent_info const& ti = *j.storage->info(); for (cache_piece_index_t::iterator i = start; i != end; ++i) { - torrent_info const& ti = *i->storage->info(); int blocks_in_piece = (ti.piece_size(i->piece) + m_block_size - 1) / m_block_size; + cached_piece_entry& e = const_cast(*i); for (int j = 0; j < blocks_in_piece; ++j) { if (i->blocks[j].buf == 0) continue; buffers.push_back(i->blocks[j].buf); i->blocks[j].buf = 0; --m_cache_stats.cache_size; + TORRENT_ASSERT(e.num_blocks > 0); + --e.num_blocks; } + TORRENT_ASSERT(i->num_blocks == 0); } idx.erase(start, end); l.unlock();