mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
remove locks
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/anacrolix/torrent"
|
"github.com/anacrolix/torrent"
|
||||||
@@ -17,8 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
bts *BTServer
|
bts *BTServer
|
||||||
lockApi sync.Mutex
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitApiHelper(bt *BTServer) {
|
func InitApiHelper(bt *BTServer) {
|
||||||
@@ -26,8 +24,6 @@ func InitApiHelper(bt *BTServer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func LoadTorrent(tor *Torrent) *Torrent {
|
func LoadTorrent(tor *Torrent) *Torrent {
|
||||||
lockApi.Lock()
|
|
||||||
defer lockApi.Unlock()
|
|
||||||
if tor.TorrentSpec == nil {
|
if tor.TorrentSpec == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -45,8 +41,6 @@ func LoadTorrent(tor *Torrent) *Torrent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AddTorrent(spec *torrent.TorrentSpec, title, poster string, data string) (*Torrent, error) {
|
func AddTorrent(spec *torrent.TorrentSpec, title, poster string, data string) (*Torrent, error) {
|
||||||
lockApi.Lock()
|
|
||||||
defer lockApi.Unlock()
|
|
||||||
torr, err := NewTorrent(spec, bts)
|
torr, err := NewTorrent(spec, bts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.TLogln("error add torrent:", err)
|
log.TLogln("error add torrent:", err)
|
||||||
@@ -86,8 +80,6 @@ func SaveTorrentToDB(torr *Torrent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetTorrent(hashHex string) *Torrent {
|
func GetTorrent(hashHex string) *Torrent {
|
||||||
lockApi.Lock()
|
|
||||||
defer lockApi.Unlock()
|
|
||||||
hash := metainfo.NewHashFromHex(hashHex)
|
hash := metainfo.NewHashFromHex(hashHex)
|
||||||
tor := bts.GetTorrent(hash)
|
tor := bts.GetTorrent(hash)
|
||||||
if tor != nil {
|
if tor != nil {
|
||||||
@@ -99,8 +91,6 @@ func GetTorrent(hashHex string) *Torrent {
|
|||||||
if tr != nil {
|
if tr != nil {
|
||||||
tor = tr
|
tor = tr
|
||||||
go func() {
|
go func() {
|
||||||
lockApi.Lock()
|
|
||||||
defer lockApi.Unlock()
|
|
||||||
log.TLogln("New torrent", tor.Hash())
|
log.TLogln("New torrent", tor.Hash())
|
||||||
tr, _ := NewTorrent(tor.TorrentSpec, bts)
|
tr, _ := NewTorrent(tor.TorrentSpec, bts)
|
||||||
if tr != nil {
|
if tr != nil {
|
||||||
@@ -117,9 +107,6 @@ func GetTorrent(hashHex string) *Torrent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetTorrent(hashHex, title, poster, data string) *Torrent {
|
func SetTorrent(hashHex, title, poster, data string) *Torrent {
|
||||||
lockApi.Lock()
|
|
||||||
defer lockApi.Unlock()
|
|
||||||
|
|
||||||
hash := metainfo.NewHashFromHex(hashHex)
|
hash := metainfo.NewHashFromHex(hashHex)
|
||||||
torr := bts.GetTorrent(hash)
|
torr := bts.GetTorrent(hash)
|
||||||
torrDb := GetTorrentDB(hash)
|
torrDb := GetTorrentDB(hash)
|
||||||
@@ -155,8 +142,6 @@ func SetTorrent(hashHex, title, poster, data string) *Torrent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RemTorrent(hashHex string) {
|
func RemTorrent(hashHex string) {
|
||||||
lockApi.Lock()
|
|
||||||
defer lockApi.Unlock()
|
|
||||||
hash := metainfo.NewHashFromHex(hashHex)
|
hash := metainfo.NewHashFromHex(hashHex)
|
||||||
if sets.BTsets.UseDisk && hashHex != "" && hashHex != "/" {
|
if sets.BTsets.UseDisk && hashHex != "" && hashHex != "/" {
|
||||||
name := filepath.Join(sets.BTsets.TorrentsSavePath, hashHex)
|
name := filepath.Join(sets.BTsets.TorrentsSavePath, hashHex)
|
||||||
@@ -174,8 +159,6 @@ func RemTorrent(hashHex string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ListTorrent() []*Torrent {
|
func ListTorrent() []*Torrent {
|
||||||
lockApi.Lock()
|
|
||||||
defer lockApi.Unlock()
|
|
||||||
btlist := bts.ListTorrents()
|
btlist := bts.ListTorrents()
|
||||||
dblist := ListTorrentsDB()
|
dblist := ListTorrentsDB()
|
||||||
|
|
||||||
@@ -202,8 +185,6 @@ func ListTorrent() []*Torrent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DropTorrent(hashHex string) {
|
func DropTorrent(hashHex string) {
|
||||||
lockApi.Lock()
|
|
||||||
defer lockApi.Unlock()
|
|
||||||
hash := metainfo.NewHashFromHex(hashHex)
|
hash := metainfo.NewHashFromHex(hashHex)
|
||||||
bts.RemoveTorrent(hash)
|
bts.RemoveTorrent(hash)
|
||||||
}
|
}
|
||||||
@@ -212,8 +193,6 @@ func SetSettings(set *sets.BTSets) {
|
|||||||
if sets.ReadOnly {
|
if sets.ReadOnly {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lockApi.Lock()
|
|
||||||
defer lockApi.Unlock()
|
|
||||||
log.TLogln("drop all torrents")
|
log.TLogln("drop all torrents")
|
||||||
dropAllTorrent()
|
dropAllTorrent()
|
||||||
time.Sleep(time.Second * 2)
|
time.Sleep(time.Second * 2)
|
||||||
@@ -230,8 +209,6 @@ func SetDefSettings() {
|
|||||||
if sets.ReadOnly {
|
if sets.ReadOnly {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lockApi.Lock()
|
|
||||||
defer lockApi.Unlock()
|
|
||||||
log.TLogln("drop all torrents")
|
log.TLogln("drop all torrents")
|
||||||
dropAllTorrent()
|
dropAllTorrent()
|
||||||
time.Sleep(time.Second * 2)
|
time.Sleep(time.Second * 2)
|
||||||
@@ -252,8 +229,6 @@ func dropAllTorrent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Shutdown() {
|
func Shutdown() {
|
||||||
lockApi.Lock()
|
|
||||||
defer lockApi.Unlock()
|
|
||||||
bts.Disconnect()
|
bts.Disconnect()
|
||||||
sets.CloseDB()
|
sets.CloseDB()
|
||||||
log.TLogln("Received shutdown. Quit")
|
log.TLogln("Received shutdown. Quit")
|
||||||
@@ -265,8 +240,6 @@ func WriteStatus(w io.Writer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Preload(torr *Torrent, index int) {
|
func Preload(torr *Torrent, index int) {
|
||||||
lockApi.Lock()
|
|
||||||
lockApi.Unlock()
|
|
||||||
cache := float32(sets.BTsets.CacheSize)
|
cache := float32(sets.BTsets.CacheSize)
|
||||||
preload := float32(sets.BTsets.PreloadCache)
|
preload := float32(sets.BTsets.PreloadCache)
|
||||||
size := int64((cache / 100.0) * preload)
|
size := int64((cache / 100.0) * preload)
|
||||||
|
|||||||
Reference in New Issue
Block a user