storage fixes

This commit is contained in:
Arvid Norberg 2014-07-20 08:59:02 +00:00
parent 55c21e8513
commit cd456964ad
4 changed files with 22 additions and 7 deletions

View File

@ -651,7 +651,7 @@ namespace libtorrent
enum return_t enum return_t
{ {
// return values from check_fastresume // return values from check_fastresume, and move_storage
no_error = 0, no_error = 0,
fatal_disk_error = -1, fatal_disk_error = -1,
need_full_check = -2, need_full_check = -2,

View File

@ -2375,7 +2375,8 @@ namespace libtorrent
pe->hashing = 1; pe->hashing = 1;
TORRENT_PIECE_ASSERT(pe->cache_state <= cached_piece_entry::read_lru1 || pe->cache_state == cached_piece_entry::read_lru2, pe); TORRENT_PIECE_ASSERT(pe->cache_state <= cached_piece_entry::read_lru1
|| pe->cache_state == cached_piece_entry::read_lru2, pe);
++pe->piece_refcount; ++pe->piece_refcount;
if (pe->hash == NULL) if (pe->hash == NULL)
@ -2472,6 +2473,19 @@ namespace libtorrent
break; break;
} }
// treat a short read as an error. The hash will be invalid, the
// block cannot be cached and the main thread should skip the rest
// of this file
if (ret != iov.iov_len)
{
ret = -1;
j->error.ec.assign(boost::asio::error::eof
, boost::asio::error::get_misc_category());
m_disk_cache.free_buffer((char*)iov.iov_base);
l.lock();
break;
}
if (!j->error.ec) if (!j->error.ec)
{ {
boost::uint32_t read_time = total_microseconds(time_now_hires() - start_time); boost::uint32_t read_time = total_microseconds(time_now_hires() - start_time);

View File

@ -1583,7 +1583,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
if (tmp_ret < 0) if (tmp_ret < 0)
{ {
#ifdef TORRENT_WINDOWS #ifdef TORRENT_WINDOWS
ec.assign(last_error, system_category()); ec.assign(GetLastError(), system_category());
#else #else
ec.assign(errno, get_posix_category()); ec.assign(errno, get_posix_category());
#endif #endif
@ -1596,7 +1596,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
return ret; return ret;
#else #else // not PREADV nor PREAD
int ret = 0; int ret = 0;

View File

@ -2421,7 +2421,7 @@ namespace libtorrent
dec_refcount("force_recheck"); dec_refcount("force_recheck");
state_updated(); state_updated();
if (j->ret == piece_manager::fatal_disk_error) if (j->ret < 0)
{ {
handle_disk_error(j); handle_disk_error(j);
return; return;
@ -2514,9 +2514,10 @@ namespace libtorrent
++m_num_checked_pieces; ++m_num_checked_pieces;
if (j->ret == piece_manager::fatal_disk_error) if (j->ret < 0)
{ {
if (j->error.ec == boost::system::errc::no_such_file_or_directory) if (j->error.ec == boost::system::errc::no_such_file_or_directory
|| j->error.ec == boost::asio::error::eof)
{ {
// skip this file by updating m_checking_piece to the first piece following it // skip this file by updating m_checking_piece to the first piece following it
file_storage const& st = m_torrent_file->files(); file_storage const& st = m_torrent_file->files();