From 172205d7fb283df19e347407b47ce6e26e7f0874 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 19 Apr 2007 03:32:20 +0000 Subject: [PATCH] improvements and fixes to sparse files support. made the test pass again --- include/libtorrent/storage.hpp | 6 ++++-- src/file_pool.cpp | 1 + src/storage.cpp | 11 +++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index 885403776..233338c0e 100755 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -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; diff --git a/src/file_pool.cpp b/src/file_pool.cpp index db4c715bb..ab4ea8d6c 100644 --- a/src/file_pool.cpp +++ b/src/file_pool.cpp @@ -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::type path_view; path_view& pt = get<0>(m_files); diff --git a/src/storage.cpp b/src/storage.cpp index 5e440b13c..1e9818264 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -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;