added error handling for set_piece_hashes

This commit is contained in:
Arvid Norberg 2009-03-19 17:32:40 +00:00
parent 7e01b9d990
commit cc432a8cd8
3 changed files with 64 additions and 4 deletions

View File

@ -45,6 +45,7 @@ release 0.14.3
changing DHT port
* fixed move_storage bug when files were renamed to be moved out
of the root directory
* added error handling for set_piece_hashes
release 0.14.2

View File

@ -93,9 +93,19 @@ set_piece_hashes()
void set_piece_hashes(create_torrent& t, boost::filesystem::path const& p, Fun f);
template <class Fun>
void set_piece_hashes(create_torrent& t, boost::filesystem::wpath const& p, Fun f);
template <class Fun>
void set_piece_hashes(create_torrent& t, boost::filesystem::path const& p, Fun f
, error_code& ec);
template <class Fun>
void set_piece_hashes(create_torrent& t, boost::filesystem::wpath const& p, Fun f
, error_code& ec);
void set_piece_hashes(create_torrent& t, boost::filesystem::path const& p);
void set_piece_hashes(create_torrent& t, boost::filesystem::wpath const& p);
void set_piece_hashes(create_torrent& t, boost::filesystem::path const& p
, error_code& ec);
void set_piece_hashes(create_torrent& t, boost::filesystem::wpath const& p
, error_code& ec);
This function will assume that the files added to the torrent file exists at path
``p``, read those files and hash the content and set the hashes in the ``create_torrent``
@ -104,6 +114,9 @@ must have the following signature::
void Fun(int);
The overloads that don't take an ``error_code&`` may throw an exception in case of a
file error, the other overloads sets the error code to reflect the error, if any.
file_storage
============

View File

@ -224,7 +224,8 @@ namespace libtorrent
};
template <class Fun>
void set_piece_hashes(create_torrent& t, boost::filesystem::path const& p, Fun f)
void set_piece_hashes(create_torrent& t, boost::filesystem::path const& p, Fun f
, error_code& ec)
{
file_pool fp;
boost::scoped_ptr<storage_interface> st(
@ -238,17 +239,39 @@ namespace libtorrent
// read hits the disk and will block. Progress should
// be updated in between reads
st->read(buf.bytes(), i, 0, t.piece_size(i));
if (st->error())
{
ec = st->error();
return;
}
hasher h(buf.bytes(), t.piece_size(i));
t.set_hash(i, h.final());
f(i);
}
}
template <class Fun>
void set_piece_hashes(create_torrent& t, boost::filesystem::path const& p, Fun f)
{
error_code ec;
set_piece_hashes(t, p, f, ec);
if (ec) throw libtorrent_exception(ec);
}
#ifndef BOOST_NOEXCEPTIONS
inline void set_piece_hashes(create_torrent& t, boost::filesystem::path const& p)
{
set_piece_hashes(t, p, detail::nop);
error_code ec;
set_piece_hashes(t, p, detail::nop, ec);
if (ec) throw libtorrent_exception(ec);
}
inline void set_piece_hashes(create_torrent& t, boost::filesystem::path const& p, error_code& ec)
{
set_piece_hashes(t, p, detail::nop, ec);
}
#endif
// wpath versions
template <class Pred>
@ -273,7 +296,8 @@ namespace libtorrent
}
template <class Fun>
void set_piece_hashes(create_torrent& t, boost::filesystem::wpath const& p, Fun f)
void set_piece_hashes(create_torrent& t, boost::filesystem::wpath const& p, Fun f
, error_code& ec)
{
file_pool fp;
std::string utf8;
@ -289,15 +313,37 @@ namespace libtorrent
// read hits the disk and will block. Progress should
// be updated in between reads
st->read(&buf[0], i, 0, t.piece_size(i));
if (st->error())
{
ec = st->error();
return;
}
hasher h(&buf[0], t.piece_size(i));
t.set_hash(i, h.final());
f(i);
}
}
#ifndef BOOST_NOEXCEPTIONS
template <class Fun>
void set_piece_hashes(create_torrent& t, boost::filesystem::wpath const& p, Fun f)
{
error_code ec;
set_piece_hashes(t, p, f, ec);
if (ec) throw libtorrent_exception(ec);
}
inline void set_piece_hashes(create_torrent& t, boost::filesystem::wpath const& p)
{
set_piece_hashes(t, p, detail::nop);
error_code ec;
set_piece_hashes(t, p, detail::nop, ec);
if (ec) throw libtorrent_exception(ec);
}
#endif
inline void set_piece_hashes(create_torrent& t, boost::filesystem::wpath const& p, error_code& ec)
{
set_piece_hashes(t, p, detail::nop, ec);
}
}