fix issue resuming 1.0.x downloads with a file priority 0

This commit is contained in:
arvidn 2018-01-14 16:14:30 +01:00 committed by Arvid Norberg
parent 01c41fadcf
commit 91e03c789c
3 changed files with 34 additions and 3 deletions

View File

@ -1,4 +1,5 @@
* fix issue resuming 1.0.x downloads with a file priority 0
* fix torrent_status::next_announce
* fix pad-file scalability issue
* made coalesce_reads/coalesce_writes settings take effect on linux and windows

View File

@ -478,6 +478,14 @@ namespace libtorrent
std::vector<boost::uint8_t> m_file_priority;
std::string m_save_path;
std::string m_part_file_name;
// if this is false, we're not using a part file to store priority-0
// pieces, but we instead look for them under their actual file names
// this defaults to true, but when checking resume data for a torrent
// where we would expect to have a part file, but there isn't one, we set
// this to false.
bool m_use_part_file;
// the file pool is typically stored in
// the session, to make all storage
// instances use the same pool

View File

@ -243,7 +243,8 @@ namespace libtorrent
int num_bufs = count_bufs(bufs, size);
if (file_index < int(m_storage.m_file_priority.size())
&& m_storage.m_file_priority[file_index] == 0)
&& m_storage.m_file_priority[file_index] == 0
&& m_storage.m_use_part_file)
{
TORRENT_ASSERT(m_storage.m_part_file);
@ -333,7 +334,8 @@ namespace libtorrent
}
if (file_index < int(m_storage.m_file_priority.size())
&& m_storage.m_file_priority[file_index] == 0)
&& m_storage.m_file_priority[file_index] == 0
&& m_storage.m_use_part_file)
{
TORRENT_ASSERT(m_storage.m_part_file);
@ -401,6 +403,7 @@ namespace libtorrent
default_storage::default_storage(storage_params const& params)
: m_files(*params.files)
, m_use_part_file(true)
, m_pool(*params.pool)
, m_allocate_files(params.mode == storage_mode_allocate)
{
@ -1039,6 +1042,21 @@ namespace libtorrent
return false;
}
// if some files have priority 0, we would expect therer to be a part file
// as well. If there isn't, it implies we're not using part files and the
// original file names are used to store the partial pieces. i.e. 1.0.x
// behavior
for (int i = 0; i < m_file_priority.size(); ++i)
{
if (m_file_priority[i] == 0 && !fs.pad_file_at(i))
{
file_status s;
stat_file(combine_path(m_save_path, m_part_file_name), &s, ec.ec);
m_use_part_file = !ec;
break;
}
}
for (int i = 0; i < file_sizes_ent.list_size(); ++i)
{
if (fs.pad_file_at(i)) continue;
@ -1046,8 +1064,12 @@ namespace libtorrent
// files with priority zero may not have been saved to disk at their
// expected location, but is likely to be in a partfile. Just exempt it
// from checking
// if we don't have a part-file, this may have been downloaded with a
// previous version of libtorrent. Then assume the pieces are in the
// files they belong in.
if (i < int(m_file_priority.size())
&& m_file_priority[i] == 0)
&& m_file_priority[i] == 0
&& m_use_part_file)
continue;
bdecode_node e = file_sizes_ent.list_at(i);