mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
fix crash on close torrent and clean pieces
This commit is contained in:
@@ -35,6 +35,7 @@ type Cache struct {
|
|||||||
muReaders sync.Mutex
|
muReaders sync.Mutex
|
||||||
|
|
||||||
isRemove bool
|
isRemove bool
|
||||||
|
isClosed bool
|
||||||
muRemove sync.Mutex
|
muRemove sync.Mutex
|
||||||
torrent *torrent.Torrent
|
torrent *torrent.Torrent
|
||||||
}
|
}
|
||||||
@@ -89,6 +90,8 @@ func (c *Cache) Piece(m metainfo.Piece) storage.PieceImpl {
|
|||||||
|
|
||||||
func (c *Cache) Close() error {
|
func (c *Cache) Close() error {
|
||||||
log.TLogln("Close cache for:", c.hash)
|
log.TLogln("Close cache for:", c.hash)
|
||||||
|
c.isClosed = true
|
||||||
|
|
||||||
delete(c.storage.caches, c.hash)
|
delete(c.storage.caches, c.hash)
|
||||||
|
|
||||||
if settings.BTsets.RemoveCacheOnDrop {
|
if settings.BTsets.RemoveCacheOnDrop {
|
||||||
@@ -114,7 +117,9 @@ func (c *Cache) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) removePiece(piece *Piece) {
|
func (c *Cache) removePiece(piece *Piece) {
|
||||||
|
if !c.isClosed {
|
||||||
piece.Release()
|
piece.Release()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) AdjustRA(readahead int64) {
|
func (c *Cache) AdjustRA(readahead int64) {
|
||||||
@@ -177,7 +182,7 @@ func (c *Cache) GetState() *state.CacheState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) cleanPieces() {
|
func (c *Cache) cleanPieces() {
|
||||||
if c.isRemove {
|
if c.isRemove || c.isClosed {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.muRemove.Lock()
|
c.muRemove.Lock()
|
||||||
|
|||||||
@@ -76,7 +76,9 @@ func (p *Piece) Release() {
|
|||||||
p.dPiece.Release()
|
p.dPiece.Release()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !p.cache.isClosed {
|
||||||
p.cache.torrent.Piece(p.Id).SetPriority(torrent.PiecePriorityNone)
|
p.cache.torrent.Piece(p.Id).SetPriority(torrent.PiecePriorityNone)
|
||||||
// fix remove pieces hash
|
// fix remove pieces hash
|
||||||
p.cache.torrent.Piece(p.Id).UpdateCompletion()
|
p.cache.torrent.Piece(p.Id).UpdateCompletion()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user