Skip to content

Commit

Permalink
fix bug where file_progress could sometimes be reported as >100%
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Oct 25, 2024
1 parent 24e658a commit dd1114c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

2.0.11 not released

* fix bug where file_progress could sometimes be reported as >100%
* don't hint FADV_RANDOM on posix systems. May improve seeding performance
* allow boost connect while checking resume data if no_verify_files flag is set
* fix BEP-40 peer priority for IPv6
Expand Down
11 changes: 11 additions & 0 deletions src/torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,9 @@ bool is_downloading_state(int const st)
continue;
}

if (has_piece_passed(piece))
continue;

// being in seed mode and missing a piece is not compatible.
// Leave seed mode if that happens
if (m_seed_mode) leave_seed_mode(seed_mode_t::skip_checking);
Expand Down Expand Up @@ -11506,6 +11509,12 @@ namespace {
file_storage const& fs = m_torrent_file->files();
for (auto const& dp : q)
{
if (has_piece_passed(dp.index))
{
// in this case this piece has already been accounted for in fp
continue;
}

std::int64_t offset = std::int64_t(static_cast<int>(dp.index))
* m_torrent_file->piece_length();
file_index_t file = fs.file_index_at_offset(offset);
Expand Down Expand Up @@ -11561,6 +11570,7 @@ namespace {
TORRENT_ASSERT(offset <= fs.file_offset(file) + fs.file_size(file));
std::int64_t const slice = std::min(fs.file_offset(file) + fs.file_size(file) - offset
, block);
TORRENT_ASSERT(fp[file] <= fs.file_size(file) - slice);
fp[file] += slice;
offset += slice;
block -= slice;
Expand All @@ -11582,6 +11592,7 @@ namespace {
}
else
{
TORRENT_ASSERT(fp[file] <= fs.file_size(file) - block);
fp[file] += block;
offset += block_size();
}
Expand Down

0 comments on commit dd1114c

Please sign in to comment.