fixed storage to generate a proper error when the read operation

This commit is contained in:
Arvid Norberg 2009-01-14 03:05:35 +00:00
parent d0546e702f
commit b9d7538ba8
2 changed files with 27 additions and 6 deletions

View File

@ -476,7 +476,7 @@ namespace libtorrent
{ {
l.unlock(); l.unlock();
file::iovec_t b = { buf.get(), buffer_size }; file::iovec_t b = { buf.get(), buffer_size };
ret += p.storage->read_impl(&b, p.piece, start_block * m_block_size, 1); ret = p.storage->read_impl(&b, p.piece, start_block * m_block_size, 1);
l.lock(); l.lock();
if (p.storage->error()) { return -1; } if (p.storage->error()) { return -1; }
++m_cache_stats.reads; ++m_cache_stats.reads;
@ -508,13 +508,14 @@ namespace libtorrent
if (iov) if (iov)
{ {
l.unlock(); l.unlock();
ret += p.storage->read_impl(iov.get(), p.piece, start_block * m_block_size, iov_counter); ret = p.storage->read_impl(iov.get(), p.piece, start_block * m_block_size, iov_counter);
l.lock(); l.lock();
if (p.storage->error()) { return -1; } if (p.storage->error()) { return -1; }
++m_cache_stats.reads; ++m_cache_stats.reads;
} }
TORRENT_ASSERT(ret <= buffer_size); TORRENT_ASSERT(ret <= buffer_size);
TORRENT_ASSERT(ret == buffer_size || p.storage->error());
return (ret != buffer_size) ? -1 : ret; return (ret != buffer_size) ? -1 : ret;
} }

View File

@ -1137,10 +1137,20 @@ ret:
+ file_offset, tmp_bufs, num_tmp_bufs, ec)); + file_offset, tmp_bufs, num_tmp_bufs, ec));
file_offset = 0; file_offset = 0;
if (read_bytes != actual_read || ec) if (ec)
{
set_error(m_save_path / file_iter->path, ec);
return -1;
}
if (read_bytes != actual_read)
{ {
// the file was not big enough // the file was not big enough
if (actual_read > 0) buf_pos += actual_read; #ifdef TORRENT_WINDOWS
ec = error_code(ERROR_READ_FAULT, get_system_category());
#else
ec = error_code(EIO, get_posix_category());
#endif
set_error(m_save_path / file_iter->path, ec); set_error(m_save_path / file_iter->path, ec);
return -1; return -1;
} }
@ -1283,10 +1293,20 @@ ret:
file_offset = 0; file_offset = 0;
if (write_bytes != actual_written || ec) if (ec)
{
set_error(m_save_path / file_iter->path, ec);
return -1;
}
if (write_bytes != actual_written)
{ {
// the file was not big enough // the file was not big enough
if (actual_written > 0) buf_pos += actual_written; #ifdef TORRENT_WINDOWS
ec = error_code(ERROR_READ_FAULT, get_system_category());
#else
ec = error_code(EIO, get_posix_category());
#endif
set_error(m_save_path / file_iter->path, ec); set_error(m_save_path / file_iter->path, ec);
return -1; return -1;
} }