more storage state machine fixes, added test to storage unit test and fix in file::set_size

This commit is contained in:
Arvid Norberg 2007-05-31 23:35:48 +00:00
parent 61f9315e34
commit aea4e503c5
3 changed files with 43 additions and 36 deletions

View File

@ -248,10 +248,10 @@ namespace libtorrent
void set_size(size_type s)
{
size_type pos = tell();
seek(s);
seek(s - 1);
char dummy = 0;
read(&dummy, 1);
seek(s);
seek(s - 1);
write(&dummy, 1);
seek(pos);
}

View File

@ -412,6 +412,7 @@ namespace libtorrent
void storage::initialize(bool allocate_files)
{
std::cerr << "storage initialize" << std::endl;
// first, create all missing directories
path last_path;
for (torrent_info::file_iterator file_iter = m_info.begin_files(),
@ -436,6 +437,7 @@ namespace libtorrent
// the directory exits.
if (file_iter->size == 0)
{
std::cerr << "creating empty file: " << file_iter->path.string() << std::endl;
file(m_save_path / file_iter->path, file::out);
continue;
}
@ -1613,50 +1615,45 @@ namespace libtorrent
m_unallocated_slots.push_back(i);
}
if (m_unallocated_slots.empty())
{
m_state = state_finished;
return true;
}
if (m_compact_mode)
if (m_compact_mode || m_unallocated_slots.empty())
{
m_state = state_create_files;
std::cerr << "storage: -> create_files" << std::endl;
return false;
}
}
m_current_slot = 0;
m_state = state_full_check;
std::cerr << "storage: -> full_check" << std::endl;
return false;
}
/*
state chart:
check_fastresume() ----+
|
| | |
| v |
| +------------+ |
| | full_check | |
| +------------+ |
| | |
| v |
| +------------+ |
| | allocating | |
| +------------+ |
| | |
| v |
| +--------------+ |
| | create_files |<-+
| +--------------+ |
| | |
| v |
| +----------+ |
+---->| finished |<--+
+----------+
check_fastresume()
| |
| v
| +------------+
| | full_check |
| +------------+
| |
| v
| +------------+
| | allocating |
| +------------+
| |
| v
| +--------------+
|->| create_files |
+--------------+
|
v
+----------+
| finished |
+----------+
*/
@ -1676,7 +1673,7 @@ namespace libtorrent
if (m_compact_mode || m_unallocated_slots.empty())
{
m_state = state_create_files;
return std::make_pair(true, 1.f);
return std::make_pair(false, 1.f);
}
if (int(m_unallocated_slots.size()) == m_info.num_pieces()
@ -1716,7 +1713,7 @@ namespace libtorrent
{
m_storage->initialize(!m_fill_mode && !m_compact_mode);
if (!m_unallocated_slots.empty())
if (!m_unallocated_slots.empty() && !m_compact_mode)
{
assert(!m_fill_mode);
assert(!m_compact_mode);

View File

@ -16,7 +16,7 @@ using namespace boost::filesystem;
const int piece_size = 16;
void run_storage_tests(torrent_info& info)
void run_storage_tests(torrent_info& info, bool compact_allocation = true)
{
const int half = piece_size / 2;
@ -81,7 +81,8 @@ void run_storage_tests(torrent_info& info)
std::vector<bool> pieces;
num_pieces = 0;
TEST_CHECK(pm.check_fastresume(d, pieces, num_pieces, true) == false);
TEST_CHECK(pm.check_fastresume(d, pieces, num_pieces
, compact_allocation) == false);
bool finished = false;
float progress;
num_pieces = 0;
@ -142,6 +143,15 @@ int test_main()
TEST_CHECK(file_size(initial_path() / "temp_storage" / "test1.tmp") == 48);
remove_all(initial_path() / "temp_storage");
// make sure full allocation mode actually allocates the files
// and creates the directories
run_storage_tests(info, false);
std::cerr << file_size(initial_path() / "temp_storage" / "test1.tmp") << std::endl;
TEST_CHECK(file_size(initial_path() / "temp_storage" / "test1.tmp") == 17 + 612 + 1);
remove_all(initial_path() / "temp_storage");
return 0;
}