fixed another sparse files related bug in storage

This commit is contained in:
Arvid Norberg 2007-05-04 03:28:42 +00:00
parent f942308ccb
commit c39462c125
1 changed files with 78 additions and 73 deletions

View File

@ -628,6 +628,9 @@ namespace libtorrent
++file_iter; ++file_iter;
} }
int buf_pos = 0;
try
{
boost::shared_ptr<file> in(m_files.open_file( boost::shared_ptr<file> in(m_files.open_file(
this, m_save_path / file_iter->path, file::in)); this, m_save_path / file_iter->path, file::in));
@ -656,7 +659,6 @@ namespace libtorrent
assert(left_to_read >= 0); assert(left_to_read >= 0);
size_type result = left_to_read; size_type result = left_to_read;
int buf_pos = 0;
#ifndef NDEBUG #ifndef NDEBUG
int counter = 0; int counter = 0;
@ -682,16 +684,10 @@ namespace libtorrent
if (read_bytes != actual_read) if (read_bytes != actual_read)
{ {
if (fill_zero && actual_read < read_bytes) if (actual_read > 0) buf_pos += actual_read;
{
std::memset(buf + buf_pos + actual_read, 0, read_bytes - actual_read);
}
else
{
// the file was not big enough // the file was not big enough
throw file_error("slot has no storage"); throw file_error("slot has no storage");
} }
}
left_to_read -= read_bytes; left_to_read -= read_bytes;
buf_pos += read_bytes; buf_pos += read_bytes;
@ -715,9 +711,18 @@ namespace libtorrent
in->seek(0); in->seek(0);
} }
} }
return result; return result;
} }
catch (std::exception&)
{
if (fill_zero)
{
std::memset(buf + buf_pos, 0, size - buf_pos);
return size;
}
throw;
}
}
// throws file_error if it fails to write // throws file_error if it fails to write
void storage::write( void storage::write(