Skip to content

Commit

Permalink
verify on start if any file is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Oct 9, 2019
1 parent ddf0407 commit ba3b756
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions internal/allocator/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (

// Allocator allocates files on the disk.
type Allocator struct {
Files []File
NeedHashCheck bool
Error error
Files []File
HasExisting bool
HasMissing bool
Error error

closeC chan struct{}
doneC chan struct{}
Expand Down Expand Up @@ -69,7 +70,9 @@ func (a *Allocator) Run(info *metainfo.Info, sto storage.Storage, progressC chan
}
a.Files[i] = File{Storage: sf, Name: f.Path}
if exists {
a.NeedHashCheck = true
a.HasExisting = true
} else {
a.HasMissing = true
}
allocatedSize += f.Length
a.sendProgress(progressC, allocatedSize)
Expand Down
4 changes: 2 additions & 2 deletions torrent/torrent_allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (t *torrent) handleAllocationDone(al *allocator.Allocator) {
}

// If we already have bitfield from resume db, skip verification and start downloading.
if t.bitfield != nil {
if t.bitfield != nil && !al.HasMissing {
for i := uint32(0); i < t.bitfield.Len(); i++ {
t.pieces[i].Done = t.bitfield.Test(i)
}
Expand All @@ -66,7 +66,7 @@ func (t *torrent) handleAllocationDone(al *allocator.Allocator) {
}

// No need to verify files if they didn't exist when we create them.
if !al.NeedHashCheck {
if !al.HasExisting {
t.mBitfield.Lock()
t.bitfield = bitfield.New(t.info.NumPieces)
t.mBitfield.Unlock()
Expand Down

0 comments on commit ba3b756

Please sign in to comment.