fix issue when hash checking files resulting in a short read

This commit is contained in:
Arvid Norberg 2014-10-12 23:49:51 +00:00
parent 32d368e1ce
commit d287ce9c46
3 changed files with 21 additions and 1 deletions

View File

@ -1145,6 +1145,9 @@ namespace libtorrent
// call disk function
int ret = (this->*(job_functions[j->action]))(j, completed_jobs);
// note that -2 erros are OK
TORRENT_ASSERT(ret != -1 || (j->error.ec && j->error.operation != 0));
--m_outstanding_jobs;
if (ret == retry_job)
@ -1209,6 +1212,8 @@ namespace libtorrent
int ret = j->storage->get_storage_impl()->readv(&b, 1
, j->piece, j->d.io.offset, file_flags, j->error);
TORRENT_ASSERT(ret >= 0 || j->error.ec);
if (!j->error.ec)
{
boost::uint32_t read_time = total_microseconds(time_now_hires() - start_time);
@ -2545,6 +2550,8 @@ namespace libtorrent
m_disk_cache.maybe_free_piece(pe);
TORRENT_ASSERT(ret >= 0 || (j->error.ec && j->error.operation != 0));
return ret < 0 ? ret : 0;
}

View File

@ -1224,6 +1224,9 @@ namespace libtorrent
bytes_transferred = (int)((*handle).*op.op)(adjusted_offset
, tmp_bufs, num_tmp_bufs, e, op.mode);
// we either get an error or 0 or more bytes read
TORRENT_ASSERT(e || bytes_transferred >= 0);
#ifdef TORRENT_DISK_STATS
write_access_log(adjusted_offset + bytes_transferred, handle->file_id(), op_end | flags, time_now_hires());
#endif
@ -1235,12 +1238,20 @@ namespace libtorrent
{
ec.ec = e;
ec.file = file_index;
ec.operation = (op.mode & file::rw_mask) == file::read_only ? storage_error::read : storage_error::write;
ec.operation = (op.mode & file::rw_mask) == file::read_only
? storage_error::read : storage_error::write;
return -1;
}
if (file_bytes_left != bytes_transferred)
{
// fill in this information in case the caller wants to treat
// this as an error
ec.file = file_index;
ec.operation = (op.mode & file::rw_mask) == file::read_only
? storage_error::read : storage_error::write;
return bytes_transferred;
}
advance_bufs(current_buf, bytes_transferred);
TORRENT_ASSERT(count_bufs(current_buf, bytes_left - file_bytes_left) <= num_bufs);

View File

@ -2527,6 +2527,8 @@ namespace libtorrent
#endif
)
{
TORRENT_ASSERT(j->error.file >= 0);
// skip this file by updating m_checking_piece to the first piece following it
file_storage const& st = m_torrent_file->files();
boost::uint64_t file_size = st.file_size(j->error.file);