fix remove cache on disk on reading torrent

This commit is contained in:
yourok
2024-01-08 19:16:00 +03:00
parent d4bcf81690
commit 6ac8e1b84e
3 changed files with 17 additions and 14 deletions

View File

@@ -140,6 +140,7 @@ func SetTorrent(hashHex, title, poster, data string) *Torrent {
func RemTorrent(hashHex string) {
hash := metainfo.NewHashFromHex(hashHex)
if bts.RemoveTorrent(hash) {
if sets.BTsets.UseDisk && hashHex != "" && hashHex != "/" {
name := filepath.Join(sets.BTsets.TorrentsSavePath, hashHex)
ff, _ := os.ReadDir(name)
@@ -151,7 +152,7 @@ func RemTorrent(hashHex string) {
log.TLogln("Error remove cache:", err)
}
}
bts.RemoveTorrent(hash)
}
RemTorrentDB(hash)
}

View File

@@ -200,10 +200,11 @@ func (bt *BTServer) ListTorrents() map[metainfo.Hash]*Torrent {
return list
}
func (bt *BTServer) RemoveTorrent(hash torrent.InfoHash) {
func (bt *BTServer) RemoveTorrent(hash torrent.InfoHash) bool {
if torr, ok := bt.torrents[hash]; ok {
torr.Close()
return torr.Close()
}
return false
}
func isPrivateIP(ip net.IP) bool {

View File

@@ -265,9 +265,9 @@ func (t *Torrent) drop() {
}
}
func (t *Torrent) Close() {
func (t *Torrent) Close() bool {
if t.cache != nil && t.cache.Readers() > 0 {
return
return false
}
t.Stat = state.TorrentClosed
@@ -276,6 +276,7 @@ func (t *Torrent) Close() {
t.bt.mu.Unlock()
t.drop()
return true
}
func (t *Torrent) Status() *state.TorrentStatus {