improvements and fixes to sparse files support. made the test pass again

This commit is contained in:
Arvid Norberg 2007-04-19 03:32:20 +00:00
parent 92cf13c2c2
commit 172205d7fb
3 changed files with 10 additions and 8 deletions

View File

@ -90,8 +90,10 @@ namespace libtorrent
struct TORRENT_EXPORT storage_interface
{
// create directories and set file sizes
// (if sparse files are supported)
virtual void initialize() = 0;
// if allocate_files is true.
// allocate_files is true if allocation mode
// is set to full and sparse files are supported
virtual void initialize(bool allocate_files) = 0;
// may throw file_error if storage for slot does not exist
virtual size_type read(char* buf, int slot, int offset, int size) = 0;

View File

@ -45,6 +45,7 @@ namespace libtorrent
{
assert(st != 0);
assert(p.is_complete());
assert(m == file::in || m == (file::in | file::out));
boost::mutex::scoped_lock l(m_mutex);
typedef nth_index<file_set, 0>::type path_view;
path_view& pt = get<0>(m_files);

View File

@ -372,7 +372,7 @@ namespace libtorrent
void release_files();
void initialize();
void initialize(bool allocate_files);
bool move_storage(path save_path);
size_type read(char* buf, int slot, int offset, int size);
void write(const char* buf, int slot, int offset, int size);
@ -392,10 +392,9 @@ namespace libtorrent
file_pool& m_files;
};
void storage::initialize()
void storage::initialize(bool allocate_files)
{
// first, create all missing directories
bool sparse = supports_sparse_files(m_save_path);
path last_path;
for (torrent_info::file_iterator file_iter = m_info.begin_files(),
end_iter = m_info.end_files(); file_iter != end_iter; ++file_iter)
@ -423,9 +422,9 @@ namespace libtorrent
continue;
}
if (sparse)
if (allocate_files)
{
m_files.open_file(this, m_save_path / file_iter->path, file::out)
m_files.open_file(this, m_save_path / file_iter->path, file::in | file::out)
->set_size(file_iter->size);
}
}
@ -1564,7 +1563,7 @@ namespace libtorrent
if (m_state == state_create_files)
{
m_storage->initialize();
m_storage->initialize(!m_fill_mode && !m_compact_mode);
m_current_slot = 0;
m_state = state_full_check;