From 065d75b02d35f467ae93577b656bcba7ceb3764b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 19 Feb 2012 19:00:52 +0000 Subject: [PATCH] fix bug in file storage unit test, and the bug causing mapped files to not be restored correctly from resume files --- src/torrent.cpp | 17 +++++++++++++++++ test/test_storage.cpp | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/torrent.cpp b/src/torrent.cpp index 65d5cb2d2..686c15158 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -4859,6 +4859,23 @@ namespace libtorrent ? m_url : m_uuid, me)); } + // TODO: make this more generic to not just work if files have been + // renamed, but also if they have been merged into a single file for instance + // maybe use the same format as .torrent files and reuse some code from torrent_info + // The mapped_files needs to be read both in the network thread + // and in the disk thread, since they both have their own mapped files structures + // which are kept in sync + lazy_entry const* mapped_files = rd.dict_find_list("mapped_files"); + if (mapped_files && mapped_files->list_size() == m_torrent_file->num_files()) + { + for (int i = 0; i < m_torrent_file->num_files(); ++i) + { + std::string new_filename = mapped_files->list_string_value_at(i); + if (new_filename.empty()) continue; + m_torrent_file->rename_file(i, new_filename); + } + } + m_added_time = rd.dict_find_int_value("added_time", m_added_time); m_completed_time = rd.dict_find_int_value("completed_time", m_completed_time); if (m_completed_time != 0 && m_completed_time < m_added_time) diff --git a/test/test_storage.cpp b/test/test_storage.cpp index a38c1e4b8..cfa27475d 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -975,7 +975,7 @@ void test_rename_file_in_fastresume(std::string const& test_path) if (print_alerts(ses, "ses", true, true, true, &got_file_rename_alert)) renamed = true; test_sleep(1000); torrent_status s = h.status(); - if (s.state == torrent_status::seeding && renamed) return; + if (s.state == torrent_status::seeding && renamed) break; } std::cout << "stop loop" << std::endl; torrent_status s = h.status();