diff options
Diffstat (limited to 'libtorrent/src/storage.cpp')
-rwxr-xr-x | libtorrent/src/storage.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/libtorrent/src/storage.cpp b/libtorrent/src/storage.cpp index 82402629f..905ee1da7 100755 --- a/libtorrent/src/storage.cpp +++ b/libtorrent/src/storage.cpp @@ -970,15 +970,26 @@ namespace libtorrent int actual_read = int(in->read(buf + buf_pos, read_bytes, ec)); - 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 - if (actual_read > 0) buf_pos += actual_read; if (!fill_zero) { +#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); return -1; } + if (actual_read > 0) buf_pos += actual_read; std::memset(buf + buf_pos, 0, size - buf_pos); return size; } @@ -1111,12 +1122,24 @@ namespace libtorrent error_code ec; size_type written = out->write(buf + buf_pos, write_bytes, ec); - if (written != write_bytes || ec) + if (ec) { set_error(m_save_path / file_iter->path, ec); return -1; } + if (write_bytes != written) + { + // the file was not big enough +#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); + return -1; + } + left_to_write -= write_bytes; buf_pos += write_bytes; TORRENT_ASSERT(buf_pos >= 0); |