fixed rename_file() bug where the new name would not be saved in the resume data in some cases

This commit is contained in:
Arvid Norberg 2009-06-22 00:52:57 +00:00
parent 93e1c70263
commit cc3e6621ed
8 changed files with 31 additions and 14 deletions

View File

@ -67,6 +67,8 @@ release 0.14.5
* fixed memory leak in disk io thread when not using the cache
* fixed bug in connect candidate counter
* allow 0 upload slots
* fixed bug in rename_file(). The new name would not always be saved in
the resume data
release 0.14.4

View File

@ -314,7 +314,7 @@ add_torrent()
::
typedef storage_interface* (&storage_constructor_type)(
file_storage const&, fs::path const&, file_pool&);
file_storage const&, file_storage const*, fs::path const&, file_pool&);
struct add_torrent_params
{

View File

@ -230,7 +230,7 @@ namespace libtorrent
{
file_pool fp;
boost::scoped_ptr<storage_interface> st(
default_storage_constructor(const_cast<file_storage&>(t.files()), p, fp));
default_storage_constructor(const_cast<file_storage&>(t.files()), 0, p, fp));
// calculate the hash for all pieces
int num = t.num_pieces();
@ -304,7 +304,7 @@ namespace libtorrent
std::string utf8;
wchar_utf8(p.string(), utf8);
boost::scoped_ptr<storage_interface> st(
default_storage_constructor(const_cast<file_storage&>(t.files()), utf8, fp));
default_storage_constructor(const_cast<file_storage&>(t.files()), 0, utf8, fp));
// calculate the hash for all pieces
int num = t.num_pieces();

View File

@ -190,10 +190,10 @@ namespace libtorrent
};
typedef storage_interface* (*storage_constructor_type)(
file_storage const&, fs::path const&, file_pool&);
file_storage const&, file_storage const*, fs::path const&, file_pool&);
TORRENT_EXPORT storage_interface* default_storage_constructor(
file_storage const&, fs::path const&, file_pool&);
file_storage const&, file_storage const* orig, fs::path const&, file_pool&);
struct disk_io_thread;

View File

@ -398,12 +398,14 @@ namespace libtorrent
class storage : public storage_interface, boost::noncopyable
{
public:
storage(file_storage const& fs, fs::path const& path, file_pool& fp)
storage(file_storage const& fs, file_storage const* orig, fs::path const& path, file_pool& fp)
: m_files(fs)
, m_pool(fp)
, m_page_size(4096)
, m_allocate_files(false)
{
if (orig) m_mapped_files.reset(new file_storage(*orig));
TORRENT_ASSERT(m_files.begin() != m_files.end());
m_save_path = fs::complete(path);
TORRENT_ASSERT(m_save_path.is_complete());
@ -890,6 +892,18 @@ namespace libtorrent
bool storage::verify_resume_data(lazy_entry const& rd, std::string& error)
{
lazy_entry const* mapped_files = rd.dict_find_list("mapped_files");
if (mapped_files && mapped_files->list_size() == m_files.num_files())
{
m_mapped_files.reset(new file_storage(m_files));
for (int i = 0; i < m_files.num_files(); ++i)
{
std::string new_filename = mapped_files->list_string_value_at(i);
if (new_filename.empty()) continue;
m_mapped_files->rename_file(i, new_filename);
}
}
lazy_entry const* file_priority = rd.dict_find_list("file_priority");
if (file_priority && file_priority->list_size()
== files().num_files())
@ -1471,9 +1485,9 @@ ret:
}
storage_interface* default_storage_constructor(file_storage const& fs
, fs::path const& path, file_pool& fp)
, file_storage const* orig, fs::path const& path, file_pool& fp)
{
return new storage(fs, path, fp);
return new storage(fs, orig, path, fp);
}
// -- piece_manager -----------------------------------------------------
@ -1488,7 +1502,8 @@ ret:
, storage_mode_t sm)
: m_info(info)
, m_files(m_info->files())
, m_storage(sc(m_files, save_path, fp))
, m_storage(sc(m_info->files(), &m_info->files() != &m_info->orig_files()
? &m_info->orig_files() : 0, save_path, fp))
, m_storage_mode(sm)
, m_save_path(complete(save_path))
, m_state(state_none)

View File

@ -3257,7 +3257,7 @@ namespace libtorrent
{
std::string new_filename = mapped_files->list_string_value_at(i);
if (new_filename.empty()) continue;
rename_file(i, new_filename);
m_torrent_file->rename_file(i, new_filename);
}
}

View File

@ -146,7 +146,7 @@ void run_storage_tests(boost::intrusive_ptr<torrent_info> info
file_pool fp;
disk_buffer_pool dp(16 * 1024);
boost::scoped_ptr<storage_interface> s(
default_storage_constructor(fs, test_path, fp));
default_storage_constructor(fs, 0, test_path, fp));
s->m_settings = &set;
s->m_disk_pool = &dp;
@ -324,7 +324,7 @@ void test_remove(path const& test_path, bool unbuffered)
file_pool fp;
disk_buffer_pool dp(16 * 1024);
boost::scoped_ptr<storage_interface> s(
default_storage_constructor(fs, test_path, fp));
default_storage_constructor(fs, 0, test_path, fp));
s->m_settings = &set;
s->m_disk_pool = &dp;

View File

@ -115,7 +115,7 @@ void print_alert(alert const& a)
struct test_storage : storage_interface
{
test_storage(file_storage const& fs, fs::path const& p, file_pool& fp)
: m_lower_layer(default_storage_constructor(fs, p, fp))
: m_lower_layer(default_storage_constructor(fs, 0, p, fp))
, m_written(0)
, m_limit(16 * 1024 * 2)
{}
@ -204,7 +204,7 @@ struct test_storage : storage_interface
};
storage_interface* test_storage_constructor(file_storage const& fs
, fs::path const& path, file_pool& fp)
, file_storage const*, fs::path const& path, file_pool& fp)
{
return new test_storage(fs, path, fp);
}