fix issue where pieces would be hashed despite disable_hash_checks was set

This commit is contained in:
arvidn 2019-09-13 14:17:10 +02:00 committed by Arvid Norberg
parent d1e0e8701b
commit d08fa164d2
5 changed files with 14 additions and 7 deletions

View File

@ -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

View File

@ -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<iovec_t const> iov

View File

@ -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);

View File

@ -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<std::mutex> 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)
{

View File

@ -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; \