allow saving resume data before metadata has been downloaded (for magnet links)
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
* allow saving resume data before metadata has been downloaded (for magnet links)
|
||||
* record blocks in the disk queue as downloaded in the resume data
|
||||
* fix bug in set_piece_deadline() when set in a zero-priority piece
|
||||
* fix issue in URL parser, causing issues with certain tracker URLs
|
||||
|
@ -1041,7 +1041,7 @@ namespace libtorrent {
|
||||
|
||||
torrent_handle get_handle();
|
||||
|
||||
void write_resume_data(add_torrent_params& atp) const;
|
||||
void write_resume_data(resume_data_flags_t const flags, add_torrent_params& ret) const;
|
||||
|
||||
void seen_complete() { m_last_seen_complete = ::time(nullptr); }
|
||||
int time_since_complete() const { return int(::time(nullptr) - m_last_seen_complete); }
|
||||
@ -1613,9 +1613,7 @@ namespace libtorrent {
|
||||
// the maximum number of uploads for this torrent
|
||||
std::uint32_t m_max_uploads:24;
|
||||
|
||||
// these are the flags sent in on a call to save_resume_data
|
||||
// we need to save them to check them in write_resume_data
|
||||
resume_data_flags_t m_save_resume_flags;
|
||||
// 8 bits free
|
||||
|
||||
// ----
|
||||
|
||||
|
@ -210,7 +210,6 @@ bool is_downloading_state(int const st)
|
||||
, m_enable_dht(!bool(p.flags & torrent_flags::disable_dht))
|
||||
, m_enable_lsd(!bool(p.flags & torrent_flags::disable_lsd))
|
||||
, m_max_uploads((1 << 24) - 1)
|
||||
, m_save_resume_flags()
|
||||
, m_num_uploads(0)
|
||||
, m_enable_pex(!bool(p.flags & torrent_flags::disable_pex))
|
||||
, m_magnet_link(false)
|
||||
@ -6322,7 +6321,7 @@ bool is_downloading_state(int const st)
|
||||
aep.enabled = true;
|
||||
}
|
||||
|
||||
void torrent::write_resume_data(add_torrent_params& ret) const
|
||||
void torrent::write_resume_data(resume_data_flags_t const flags, add_torrent_params& ret) const
|
||||
{
|
||||
ret.version = LIBTORRENT_VERSION_NUM;
|
||||
ret.storage_mode = storage_mode();
|
||||
@ -6341,7 +6340,7 @@ bool is_downloading_state(int const st)
|
||||
ret.num_incomplete = m_incomplete;
|
||||
ret.num_downloaded = m_downloaded;
|
||||
|
||||
ret.flags = flags();
|
||||
ret.flags = this->flags();
|
||||
|
||||
ret.added_time = m_added_time;
|
||||
ret.completed_time = m_completed_time;
|
||||
@ -6358,7 +6357,7 @@ bool is_downloading_state(int const st)
|
||||
|
||||
if (valid_metadata())
|
||||
{
|
||||
if (m_magnet_link || (m_save_resume_flags & torrent_handle::save_info_dict))
|
||||
if (m_magnet_link || (flags & torrent_handle::save_info_dict))
|
||||
{
|
||||
ret.ti = m_torrent_file;
|
||||
}
|
||||
@ -6455,7 +6454,8 @@ bool is_downloading_state(int const st)
|
||||
}
|
||||
|
||||
// write renamed files
|
||||
if (&m_torrent_file->files() != &m_torrent_file->orig_files()
|
||||
if (valid_metadata()
|
||||
&& &m_torrent_file->files() != &m_torrent_file->orig_files()
|
||||
&& m_torrent_file->files().num_files() == m_torrent_file->orig_files().num_files())
|
||||
{
|
||||
file_storage const& fs = m_torrent_file->files();
|
||||
@ -6537,7 +6537,7 @@ bool is_downloading_state(int const st)
|
||||
ret.file_priorities = m_file_priority;
|
||||
}
|
||||
|
||||
if (has_picker())
|
||||
if (valid_metadata() && has_picker())
|
||||
{
|
||||
// write piece priorities
|
||||
// but only if they are not set to the default
|
||||
@ -8564,13 +8564,6 @@ bool is_downloading_state(int const st)
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
INVARIANT_CHECK;
|
||||
|
||||
if (!valid_metadata())
|
||||
{
|
||||
alerts().emplace_alert<save_resume_data_failed_alert>(get_handle()
|
||||
, errors::no_metadata);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((flags & torrent_handle::only_if_modified) && !m_need_save_resume_data)
|
||||
{
|
||||
alerts().emplace_alert<save_resume_data_failed_alert>(get_handle()
|
||||
@ -8579,7 +8572,6 @@ bool is_downloading_state(int const st)
|
||||
}
|
||||
|
||||
m_need_save_resume_data = false;
|
||||
m_save_resume_flags = flags;
|
||||
state_updated();
|
||||
|
||||
if ((flags & torrent_handle::flush_disk_cache) && m_storage)
|
||||
@ -8588,7 +8580,7 @@ bool is_downloading_state(int const st)
|
||||
state_updated();
|
||||
|
||||
add_torrent_params atp;
|
||||
write_resume_data(atp);
|
||||
write_resume_data(flags, atp);
|
||||
alerts().emplace_alert<save_resume_data_alert>(std::move(atp), get_handle());
|
||||
}
|
||||
|
||||
|
@ -724,7 +724,7 @@ namespace libtorrent {
|
||||
{
|
||||
add_torrent_params params;
|
||||
auto retr = std::ref(params);
|
||||
sync_call(&torrent::write_resume_data, retr);
|
||||
sync_call(&torrent::write_resume_data, resume_data_flags_t{}, retr);
|
||||
return libtorrent::write_resume_data(params);
|
||||
}
|
||||
|
||||
|
@ -1578,6 +1578,26 @@ TORRENT_TEST(paused)
|
||||
// and trackers for instance
|
||||
}
|
||||
|
||||
TORRENT_TEST(no_metadata)
|
||||
{
|
||||
lt::session ses(settings());
|
||||
|
||||
add_torrent_params p;
|
||||
p.info_hash = sha1_hash("abababababababababab");
|
||||
p.save_path = ".";
|
||||
torrent_handle h = ses.add_torrent(p);
|
||||
h.save_resume_data(torrent_handle::save_info_dict);
|
||||
alert const* a = wait_for_alert(ses, save_resume_data_alert::alert_type);
|
||||
TEST_CHECK(a);
|
||||
save_resume_data_alert const* ra = alert_cast<save_resume_data_alert>(a);
|
||||
TEST_CHECK(ra);
|
||||
if (ra)
|
||||
{
|
||||
auto const& atp = ra->params;
|
||||
TEST_EQUAL(atp.info_hash, p.info_hash);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Fun>
|
||||
void test_unfinished_pieces(Fun f)
|
||||
{
|
||||
|
Reference in New Issue
Block a user