add search folder .tsc for cache

This commit is contained in:
YouROK
2021-06-17 10:10:05 +03:00
parent 1de3050cdc
commit 108975774a

View File

@@ -2,6 +2,10 @@ package settings
import (
"encoding/json"
"io"
"io/fs"
"path/filepath"
"strings"
"server/log"
)
@@ -62,6 +66,23 @@ func SetBTSets(sets *BTSets) {
if sets.TorrentsSavePath == "" {
sets.UseDisk = false
} else if sets.UseDisk {
BTsets = sets
go filepath.WalkDir(sets.TorrentsSavePath, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() && strings.ToLower(d.Name()) == ".tsc" {
BTsets.TorrentsSavePath = path
log.TLogln("Find directory \"" + BTsets.TorrentsSavePath + "\", use as cache dir")
return io.EOF
}
if d.IsDir() && strings.HasPrefix(d.Name(), ".") {
return filepath.SkipDir
}
return nil
})
}
BTsets = sets