Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure files starting on a new piece aren't marked complete twice #245

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/torrent/data/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class LIBTORRENT_EXPORT lt_cacheline_aligned File {
bool has_permissions(int prot) const { return !(prot & ~m_protection); }

uint64_t offset() const { return m_offset; }
uint64_t offset_end() const { return m_offset + m_size; }

uint64_t size_bytes() const { return m_size; }
uint32_t size_chunks() const { return m_range.second - m_range.first; }
Expand Down
9 changes: 5 additions & 4 deletions src/torrent/data/file_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -674,15 +674,16 @@ FileList::mark_completed(uint32_t index) {

FileList::iterator
FileList::inc_completed(iterator firstItr, uint32_t index) {
firstItr = std::find_if(firstItr, end(), rak::less(index, std::mem_fun(&File::range_second)));
iterator lastItr = std::find_if(firstItr, end(), rak::less(index + 1, std::mem_fun(&File::range_second)));
firstItr = std::find_if(firstItr, end(), rak::less(index, std::mem_fun(&File::range_second)));

if (firstItr == end())
throw internal_error("FileList::inc_completed() first == m_entryList->end().", data()->hash());

// TODO: Check if this works right for zero-length files.
uint64_t boundary = (index+1)*m_chunkSize;
iterator lastItr = std::find_if(firstItr, end(), rak::less_equal(boundary, std::mem_fun(&File::offset_end)));

std::for_each(firstItr,
lastItr == end() ? end() : (lastItr + 1),
lastItr == end() ? end() : lastItr + 1,
std::mem_fun(&File::inc_completed_protected));

return lastItr;
Expand Down