@@ -376,6 +376,7 @@ func (s *sharedPullerState) Progress() *pullerProgress {
|
|||||||
defer s.mut.RUnlock()
|
defer s.mut.RUnlock()
|
||||||
total := s.reused + s.copyTotal + s.pullTotal
|
total := s.reused + s.copyTotal + s.pullTotal
|
||||||
done := total - s.copyNeeded - s.pullNeeded
|
done := total - s.copyNeeded - s.pullNeeded
|
||||||
|
file := len(s.file.Blocks)
|
||||||
return &pullerProgress{
|
return &pullerProgress{
|
||||||
Total: total,
|
Total: total,
|
||||||
Reused: s.reused,
|
Reused: s.reused,
|
||||||
@@ -383,8 +384,8 @@ func (s *sharedPullerState) Progress() *pullerProgress {
|
|||||||
CopiedFromElsewhere: s.copyTotal - s.copyNeeded - s.copyOrigin,
|
CopiedFromElsewhere: s.copyTotal - s.copyNeeded - s.copyOrigin,
|
||||||
Pulled: s.pullTotal - s.pullNeeded,
|
Pulled: s.pullTotal - s.pullNeeded,
|
||||||
Pulling: s.pullNeeded,
|
Pulling: s.pullNeeded,
|
||||||
BytesTotal: blocksToSize(s.file.BlockSize(), total),
|
BytesTotal: blocksToSize(total, file, s.file.BlockSize(), s.file.Size),
|
||||||
BytesDone: blocksToSize(s.file.BlockSize(), done),
|
BytesDone: blocksToSize(done, file, s.file.BlockSize(), s.file.Size),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,9 +413,12 @@ func (s *sharedPullerState) Available() []int {
|
|||||||
return blocks
|
return blocks
|
||||||
}
|
}
|
||||||
|
|
||||||
func blocksToSize(size int, num int) int64 {
|
func blocksToSize(blocks, blocksInFile, blockSize int, fileSize int64) int64 {
|
||||||
if num < 2 {
|
// The last/only block has somewhere between 1 and blockSize bytes. We do
|
||||||
return int64(size / 2)
|
// not know whether the smaller block is part of the blocks and use an
|
||||||
|
// estimate assuming a random chance that the small block is contained.
|
||||||
|
if blocksInFile == 0 {
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
return int64(num-1)*int64(size) + int64(size/2)
|
return int64(blocks)*int64(blockSize) - (int64(blockSize)-fileSize%int64(blockSize))*int64(blocks)/int64(blocksInFile)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user