if err != nil {
panic(err)
}
+ me.mu.Lock()
me.completed = make(map[[20]byte]struct{}, len(fis))
for _, fi := range fis {
binHash, ok := hexStringPieceHashArray(fi.Name())
}
me.completed[binHash] = struct{}{}
}
+ me.mu.Unlock()
}
func (me *store) completePieceDirPath() string {
}
func (me *store) pieceComplete(p metainfo.Piece) bool {
+ me.mu.Lock()
+ defer me.mu.Unlock()
_, ok := me.completed[sliceToPieceHashArray(p.Hash())]
return ok
}
// Returns the file for the given piece, if it exists. It could be completed,
// or incomplete.
func (me *store) pieceRead(p metainfo.Piece) (f *os.File) {
- me.mu.Lock()
- defer me.mu.Unlock()
f, err := os.Open(me.path(p, true))
if err == nil {
return
// Mark the file not completed, in case we thought it was. TODO: Trigger
// an asynchronous initCompleted to reinitialize the entire completed map
// as there are likely other files missing.
+ me.mu.Lock()
delete(me.completed, sliceToPieceHashArray(p.Hash()))
+ me.mu.Unlock()
f, err = os.Open(me.path(p, false))
if err == nil {
return
}
binHash, ok := hexStringPieceHashArray(name)
if ok {
+ me.mu.Lock()
delete(me.completed, binHash)
+ me.mu.Unlock()
}
return
}
return
}
os.Remove(incompletePiecePath)
+ me.mu.Lock()
me.completed[sliceToPieceHashArray(p.Hash())] = struct{}{}
+ me.mu.Unlock()
return
}