From d08fa164d298c6e72c0992a41bad32e62470a365 Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 13 Sep 2019 14:17:10 +0200 Subject: [PATCH] fix issue where pieces would be hashed despite disable_hash_checks was set --- ChangeLog | 1 + include/libtorrent/block_cache.hpp | 2 +- src/block_cache.cpp | 4 ++-- src/disk_io_thread.cpp | 12 +++++++++--- test/test_block_cache.cpp | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index e15fe19d4..60e4aa1ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 1.2.2 release + * fix cases where the disable_hash_checks setting was not honored * fix updating of is_finished torrent status, when changing piece priorities * fix regression in &left= reporting when adding a seeding torrent * fix integer overflow in http parser diff --git a/include/libtorrent/block_cache.hpp b/include/libtorrent/block_cache.hpp index 99ab9c9c0..203f6960b 100644 --- a/include/libtorrent/block_cache.hpp +++ b/include/libtorrent/block_cache.hpp @@ -450,7 +450,7 @@ namespace aux { // adds a block to the cache, marks it as dirty and // associates the job with it. When the block is // flushed, the callback is posted - cached_piece_entry* add_dirty_block(disk_io_job* j); + cached_piece_entry* add_dirty_block(disk_io_job* j, bool add_hasher); enum { blocks_inc_refcount = 1 }; void insert_blocks(cached_piece_entry* pe, int block, span iov diff --git a/src/block_cache.cpp b/src/block_cache.cpp index 0f30ad985..4a0b4ec63 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -695,7 +695,7 @@ cached_piece_entry* block_cache::allocate_piece(disk_io_job const* j, std::uint1 return p; } -cached_piece_entry* block_cache::add_dirty_block(disk_io_job* j) +cached_piece_entry* block_cache::add_dirty_block(disk_io_job* j, bool const add_hasher) { #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS INVARIANT_CHECK; @@ -755,7 +755,7 @@ cached_piece_entry* block_cache::add_dirty_block(disk_io_job* j) TORRENT_PIECE_ASSERT(j->piece == pe->piece, pe); pe->jobs.push_back(j); - if (block == 0 && !pe->hash && pe->hashing_done == false) + if (block == 0 && !pe->hash && pe->hashing_done == false && add_hasher) pe->hash.reset(new partial_hash); update_cache_state(pe); diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 0b2f2ead5..bdd57cb5d 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1566,7 +1566,8 @@ constexpr disk_job_flags_t disk_interface::cache_hit; return status_t::fatal_disk_error; } - pe = m_disk_cache.add_dirty_block(j); + pe = m_disk_cache.add_dirty_block(j + , !m_settings.get_bool(settings_pack::disable_hash_checks)); if (pe) { @@ -1786,7 +1787,8 @@ constexpr disk_job_flags_t disk_interface::cache_hit; std::unique_lock l(m_cache_mutex); // if we succeed in adding the block to the cache, the job will // be added along with it. we may not free j if so - cached_piece_entry* dpe = m_disk_cache.add_dirty_block(j); + cached_piece_entry* dpe = m_disk_cache.add_dirty_block(j + , !m_settings.get_bool(settings_pack::disable_hash_checks)); if (dpe != nullptr) { @@ -2187,6 +2189,9 @@ constexpr disk_job_flags_t disk_interface::cache_hit; status_t disk_io_thread::do_hash(disk_io_job* j, jobqueue_t& /* completed_jobs */ ) { + if (m_settings.get_bool(settings_pack::disable_hash_checks)) + return status_t::no_error; + int const piece_size = j->storage->files().piece_size(j->piece); open_mode_t const file_flags = file_flags_for_job(j , m_settings.get_bool(settings_pack::coalesce_reads)); @@ -3396,7 +3401,8 @@ constexpr disk_job_flags_t disk_interface::cache_hit; continue; } - cached_piece_entry* pe = m_disk_cache.add_dirty_block(j); + cached_piece_entry* pe = m_disk_cache.add_dirty_block(j + , !m_settings.get_bool(settings_pack::disable_hash_checks)); if (pe == nullptr) { diff --git a/test/test_block_cache.cpp b/test/test_block_cache.cpp index 9134764ec..4c7c1bd07 100644 --- a/test/test_block_cache.cpp +++ b/test/test_block_cache.cpp @@ -145,7 +145,7 @@ static void nop() {} wj.d.io.buffer_size = 0x4000; \ wj.piece = piece_index_t(p); \ wj.argument = disk_buffer_holder(alloc, bc.allocate_buffer("write-test"), 0x4000); \ - pe = bc.add_dirty_block(&wj) + pe = bc.add_dirty_block(&wj, true) #define READ_BLOCK(p, b, r) \ rj.action = job_action_t::read; \