move storage fix

This commit is contained in:
Arvid Norberg 2009-03-30 04:55:23 +00:00
parent db9236fcf8
commit 36eb9c4f51
2 changed files with 20 additions and 2 deletions

View File

@ -1314,7 +1314,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) ? 1 : 0; ret = j.storage->move_storage_impl(j.str) ? 0 : 1;
if (ret != 0) if (ret != 0)
{ {
test_error(j); test_error(j);

View File

@ -141,6 +141,10 @@ void test_transfer()
ses2.set_alert_mask(alert::all_categories & ~alert::progress_notification); ses2.set_alert_mask(alert::all_categories & ~alert::progress_notification);
ses1.set_alert_dispatch(&print_alert); ses1.set_alert_dispatch(&print_alert);
// also test to move the storage of the downloader and the uploader
// to make sure it can handle switching paths
bool test_move_storage = false;
for (int i = 0; i < 30; ++i) for (int i = 0; i < 30; ++i)
{ {
print_alerts(ses1, "ses1"); print_alerts(ses1, "ses1");
@ -163,6 +167,14 @@ void test_transfer()
if (tor2.is_finished()) break; if (tor2.is_finished()) break;
if (!test_move_storage && st2.progress > 0.25f)
{
test_move_storage = true;
tor1.move_storage("./tmp1_transfer_moved");
tor2.move_storage("./tmp2_transfer_moved");
std::cerr << "moving storage" << std::endl;
}
TEST_CHECK(st1.state == torrent_status::seeding TEST_CHECK(st1.state == torrent_status::seeding
|| st1.state == torrent_status::checking_files); || st1.state == torrent_status::checking_files);
TEST_CHECK(st2.state == torrent_status::downloading); TEST_CHECK(st2.state == torrent_status::downloading);
@ -234,7 +246,7 @@ void test_transfer()
std::cout << "re-adding" << std::endl; std::cout << "re-adding" << std::endl;
add_torrent_params p; add_torrent_params p;
p.ti = t; p.ti = t;
p.save_path = "./tmp2_transfer"; p.save_path = "./tmp2_transfer_moved";
p.resume_data = &resume_data; p.resume_data = &resume_data;
tor2 = ses2.add_torrent(p); tor2 = ses2.add_torrent(p);
ses2.set_alert_mask(alert::all_categories & ~alert::progress_notification); ses2.set_alert_mask(alert::all_categories & ~alert::progress_notification);
@ -303,6 +315,8 @@ int test_main()
// in case the previous run was terminated // in case the previous run was terminated
try { remove_all("./tmp1_transfer"); } catch (std::exception&) {} try { remove_all("./tmp1_transfer"); } catch (std::exception&) {}
try { remove_all("./tmp2_transfer"); } catch (std::exception&) {} try { remove_all("./tmp2_transfer"); } catch (std::exception&) {}
try { remove_all("./tmp1_transfer_moved"); } catch (std::exception&) {}
try { remove_all("./tmp2_transfer_moved"); } catch (std::exception&) {}
#ifdef NDEBUG #ifdef NDEBUG
// test rate only makes sense in release mode // test rate only makes sense in release mode
@ -310,12 +324,16 @@ int test_main()
try { remove_all("./tmp1_transfer"); } catch (std::exception&) {} try { remove_all("./tmp1_transfer"); } catch (std::exception&) {}
try { remove_all("./tmp2_transfer"); } catch (std::exception&) {} try { remove_all("./tmp2_transfer"); } catch (std::exception&) {}
try { remove_all("./tmp1_transfer_moved"); } catch (std::exception&) {}
try { remove_all("./tmp2_transfer_moved"); } catch (std::exception&) {}
#endif #endif
test_transfer(); test_transfer();
try { remove_all("./tmp1_transfer"); } catch (std::exception&) {} try { remove_all("./tmp1_transfer"); } catch (std::exception&) {}
try { remove_all("./tmp2_transfer"); } catch (std::exception&) {} try { remove_all("./tmp2_transfer"); } catch (std::exception&) {}
try { remove_all("./tmp1_transfer_moved"); } catch (std::exception&) {}
try { remove_all("./tmp2_transfer_moved"); } catch (std::exception&) {}
return 0; return 0;
} }