improved unit test for storage, modified move_storage to hopefully fix a bug. updated Changelog.
This commit is contained in:
parent
e051892c21
commit
bb0b8c9d95
2
COPYING
2
COPYING
|
@ -1,4 +1,4 @@
|
||||||
Copyright (c) 2003 - 2006, Arvid Norberg
|
Copyright (c) 2003 - 2007, Arvid Norberg
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
* fixed bug where directories would be left behind when moving storage
|
||||||
|
in some cases.
|
||||||
|
* fixed crashing bug when restarting or stopping the DHT.
|
||||||
* added python binding, using boost.python
|
* added python binding, using boost.python
|
||||||
* improved character conversion on windows when strings are not utf-8.
|
* improved character conversion on windows when strings are not utf-8.
|
||||||
* metadata extension now respects the private flag in the torrent.
|
* metadata extension now respects the private flag in the torrent.
|
||||||
|
|
|
@ -417,29 +417,8 @@ namespace libtorrent
|
||||||
|
|
||||||
m_pimpl->files.release(m_pimpl.get());
|
m_pimpl->files.release(m_pimpl.get());
|
||||||
|
|
||||||
if (m_pimpl->info.num_files() == 1)
|
old_path = m_pimpl->save_path / m_pimpl->info.name();
|
||||||
{
|
new_path = save_path / m_pimpl->info.name();
|
||||||
path single_file = m_pimpl->info.begin_files()->path;
|
|
||||||
assert(!single_file.is_complete());
|
|
||||||
if (single_file.has_branch_path())
|
|
||||||
{
|
|
||||||
assert(single_file.begin() != single_file.end());
|
|
||||||
std::string trunk = *single_file.begin();
|
|
||||||
old_path = m_pimpl->save_path / trunk;
|
|
||||||
new_path = save_path / trunk;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
old_path = m_pimpl->save_path / single_file;
|
|
||||||
new_path = save_path / m_pimpl->info.begin_files()->path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assert(m_pimpl->info.num_files() > 1);
|
|
||||||
old_path = m_pimpl->save_path / m_pimpl->info.name();
|
|
||||||
new_path = save_path / m_pimpl->info.name();
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,17 +14,11 @@
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
using namespace boost::filesystem;
|
using namespace boost::filesystem;
|
||||||
|
|
||||||
int test_main()
|
const int piece_size = 16;
|
||||||
|
|
||||||
|
void run_storage_tests(torrent_info& info)
|
||||||
{
|
{
|
||||||
const int piece_size = 16;
|
|
||||||
const int half = piece_size / 2;
|
const int half = piece_size / 2;
|
||||||
torrent_info info;
|
|
||||||
info.set_piece_size(piece_size);
|
|
||||||
info.add_file("temp_storage/test1.tmp", 17);
|
|
||||||
info.add_file("temp_storage/test2.tmp", 612);
|
|
||||||
info.add_file("temp_storage/test3.tmp", 0);
|
|
||||||
info.add_file("temp_storage/test4.tmp", 0);
|
|
||||||
info.add_file("temp_storage/test5.tmp", 1);
|
|
||||||
|
|
||||||
char piece0[piece_size] =
|
char piece0[piece_size] =
|
||||||
{ 6, 6, 6, 6, 6, 6, 6, 6
|
{ 6, 6, 6, 6, 6, 6, 6, 6
|
||||||
|
@ -74,13 +68,11 @@ int test_main()
|
||||||
s.read(piece, 2, 0, piece_size);
|
s.read(piece, 2, 0, piece_size);
|
||||||
TEST_CHECK(std::equal(piece, piece + piece_size, piece2));
|
TEST_CHECK(std::equal(piece, piece + piece_size, piece2));
|
||||||
|
|
||||||
// make sure the files have the correct size
|
|
||||||
TEST_CHECK(file_size(initial_path() / "temp_storage" / "test1.tmp") == 17);
|
|
||||||
TEST_CHECK(file_size(initial_path() / "temp_storage" / "test2.tmp") == 31);
|
|
||||||
s.release_files();
|
s.release_files();
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure the piece_manager can identify the pieces
|
// make sure the piece_manager can identify the pieces
|
||||||
|
{
|
||||||
file_pool fp;
|
file_pool fp;
|
||||||
piece_manager pm(info, initial_path(), fp);
|
piece_manager pm(info, initial_path(), fp);
|
||||||
boost::mutex lock;
|
boost::mutex lock;
|
||||||
|
@ -97,7 +89,14 @@ int test_main()
|
||||||
|
|
||||||
TEST_CHECK(num_pieces == std::count(pieces.begin(), pieces.end()
|
TEST_CHECK(num_pieces == std::count(pieces.begin(), pieces.end()
|
||||||
, true));
|
, true));
|
||||||
|
|
||||||
|
pm.move_storage("temp_storage2");
|
||||||
|
TEST_CHECK(!exists("temp_storage"));
|
||||||
|
TEST_CHECK(exists("temp_storage2/temp_storage"));
|
||||||
|
pm.move_storage(".");
|
||||||
|
TEST_CHECK(!exists("temp_storage2/temp_storage"));
|
||||||
|
remove_all("temp_storage2");
|
||||||
|
|
||||||
TEST_CHECK(pm.read(piece, 0, 0, piece_size) == piece_size);
|
TEST_CHECK(pm.read(piece, 0, 0, piece_size) == piece_size);
|
||||||
TEST_CHECK(std::equal(piece, piece + piece_size, piece0));
|
TEST_CHECK(std::equal(piece, piece + piece_size, piece0));
|
||||||
|
|
||||||
|
@ -108,11 +107,38 @@ int test_main()
|
||||||
TEST_CHECK(std::equal(piece, piece + piece_size, piece2));
|
TEST_CHECK(std::equal(piece, piece + piece_size, piece2));
|
||||||
pm.release_files();
|
pm.release_files();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_main()
|
||||||
|
{
|
||||||
|
torrent_info info;
|
||||||
|
info.set_piece_size(piece_size);
|
||||||
|
info.add_file("temp_storage/test1.tmp", 17);
|
||||||
|
info.add_file("temp_storage/test2.tmp", 612);
|
||||||
|
info.add_file("temp_storage/test3.tmp", 0);
|
||||||
|
info.add_file("temp_storage/test4.tmp", 0);
|
||||||
|
info.add_file("temp_storage/test5.tmp", 1);
|
||||||
|
|
||||||
|
run_storage_tests(info);
|
||||||
|
|
||||||
|
// make sure the files have the correct size
|
||||||
|
TEST_CHECK(file_size(initial_path() / "temp_storage" / "test1.tmp") == 17);
|
||||||
|
TEST_CHECK(file_size(initial_path() / "temp_storage" / "test2.tmp") == 31);
|
||||||
TEST_CHECK(exists("temp_storage/test3.tmp"));
|
TEST_CHECK(exists("temp_storage/test3.tmp"));
|
||||||
TEST_CHECK(exists("temp_storage/test4.tmp"));
|
TEST_CHECK(exists("temp_storage/test4.tmp"));
|
||||||
|
|
||||||
remove_all(initial_path() / "temp_storage");
|
remove_all(initial_path() / "temp_storage");
|
||||||
|
|
||||||
|
info = torrent_info();
|
||||||
|
info.set_piece_size(piece_size);
|
||||||
|
info.add_file("temp_storage/test1.tmp", 17 + 612 + 1);
|
||||||
|
|
||||||
|
run_storage_tests(info);
|
||||||
|
|
||||||
|
// 48 = piece_size * 3
|
||||||
|
TEST_CHECK(file_size(initial_path() / "temp_storage" / "test1.tmp") == 48);
|
||||||
|
remove_all(initial_path() / "temp_storage");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue