reverted bug introduced a few check-ins ago. Fixed case when recursive_copy fails (don't remove the original files). Cleaned up callback dispatching in disk_io_thread in trunk. Improved unit tests for move_storage

This commit is contained in:
Arvid Norberg 2009-03-31 08:05:46 +00:00
parent 0070232f7c
commit c6017f9366
4 changed files with 26 additions and 12 deletions

View File

@ -260,6 +260,8 @@ namespace libtorrent
typedef std::list<cached_piece_entry> cache_t; typedef std::list<cached_piece_entry> cache_t;
bool test_error(disk_io_job& j); bool test_error(disk_io_job& j);
void post_callback(boost::function<void(int, disk_io_job const&)> const& handler
, disk_io_job const& j, int ret);
// cache operations // cache operations
cache_t::iterator find_cached_piece( cache_t::iterator find_cached_piece(

View File

@ -292,14 +292,13 @@ namespace libtorrent
} }
if (i->action == disk_io_job::read) if (i->action == disk_io_job::read)
{ {
if (i->callback) m_ios.post(bind(i->callback, -1, *i)); post_callback(i->callback, *i, -1);
m_jobs.erase(i++); m_jobs.erase(i++);
continue; continue;
} }
if (i->action == disk_io_job::check_files) if (i->action == disk_io_job::check_files)
{ {
if (i->callback) m_ios.post(bind(i->callback post_callback(i->callback, *i, piece_manager::disk_check_aborted);
, piece_manager::disk_check_aborted, *i));
m_jobs.erase(i++); m_jobs.erase(i++);
continue; continue;
} }
@ -1006,6 +1005,15 @@ namespace libtorrent
return false; return false;
} }
void disk_io_thread::post_callback(
boost::function<void(int, disk_io_job const&)> const& handler
, disk_io_job const& j, int ret)
{
if (!handler) return;
m_ios.post(bind(handler, ret, j));
}
void disk_io_thread::operator()() void disk_io_thread::operator()()
{ {
for (;;) for (;;)
@ -1103,8 +1111,7 @@ namespace libtorrent
} }
if (i->action == disk_io_job::check_files) if (i->action == disk_io_job::check_files)
{ {
if (i->callback) m_ios.post(bind(i->callback post_callback(i->callback, *i, piece_manager::disk_check_aborted);
, piece_manager::disk_check_aborted, *i));
m_jobs.erase(i++); m_jobs.erase(i++);
continue; continue;
} }
@ -1125,14 +1132,13 @@ namespace libtorrent
{ {
if (i->action == disk_io_job::read) if (i->action == disk_io_job::read)
{ {
if (i->callback) m_ios.post(bind(i->callback, -1, *i)); post_callback(i->callback, *i, -1);
m_jobs.erase(i++); m_jobs.erase(i++);
continue; continue;
} }
if (i->action == disk_io_job::check_files) if (i->action == disk_io_job::check_files)
{ {
if (i->callback) m_ios.post(bind(i->callback post_callback(i->callback, *i, piece_manager::disk_check_aborted);
, piece_manager::disk_check_aborted, *i));
m_jobs.erase(i++); m_jobs.erase(i++);
continue; continue;
} }
@ -1314,7 +1320,7 @@ namespace libtorrent
m_log << log_time() << " move" << std::endl; m_log << log_time() << " move" << std::endl;
#endif #endif
TORRENT_ASSERT(j.buffer == 0); TORRENT_ASSERT(j.buffer == 0);
ret = j.storage->move_storage_impl(j.str) ? 0 : 1; ret = j.storage->move_storage_impl(j.str);
if (ret != 0) if (ret != 0)
{ {
test_error(j); test_error(j);
@ -1438,7 +1444,7 @@ namespace libtorrent
#endif #endif
TORRENT_ASSERT(handler); TORRENT_ASSERT(handler);
if (handler && ret == piece_manager::need_full_check) if (handler && ret == piece_manager::need_full_check)
m_ios.post(bind(handler, ret, j)); post_callback(handler, j, ret);
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
} catch (std::exception&) {} } catch (std::exception&) {}
#endif #endif
@ -1497,7 +1503,7 @@ namespace libtorrent
#endif #endif
TORRENT_ASSERT(ret != -2 || !j.str.empty() TORRENT_ASSERT(ret != -2 || !j.str.empty()
|| j.action == disk_io_job::hash); || j.action == disk_io_job::hash);
if (handler) m_ios.post(bind(handler, ret, j)); post_callback(handler, j, ret);
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
} catch (std::exception&) } catch (std::exception&)
{ {

View File

@ -962,7 +962,10 @@ namespace libtorrent
set_error(m_save_path / files().name(), ec); set_error(m_save_path / files().name(), ec);
ret = false; ret = false;
} }
recursive_remove(old_path); else
{
recursive_remove(old_path);
}
} }
#endif #endif
} }

View File

@ -114,6 +114,8 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
{ {
TORRENT_ASSERT(fs.num_files() > 0); TORRENT_ASSERT(fs.num_files() > 0);
create_directory(test_path / "temp_storage"); create_directory(test_path / "temp_storage");
remove_all(test_path / "temp_storage2");
remove_all(test_path / "part0");
int num_pieces = fs.num_pieces(); int num_pieces = fs.num_pieces();
TEST_CHECK(info->num_pieces() == num_pieces); TEST_CHECK(info->num_pieces() == num_pieces);
@ -211,6 +213,7 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
ios.poll(ec); ios.poll(ec);
TEST_CHECK(!exists(test_path / "temp_storage/test1.tmp")); TEST_CHECK(!exists(test_path / "temp_storage/test1.tmp"));
TEST_CHECK(!exists(test_path / "temp_storage2"));
TEST_CHECK(exists(test_path / "part0")); TEST_CHECK(exists(test_path / "part0"));
// test move_storage with two files in the root directory // test move_storage with two files in the root directory