Ensure data dir is present
This commit is contained in:
@@ -20,7 +20,10 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const ALL_TORRENTS = "__all__"
|
||||
const (
|
||||
ALL_TORRENTS = "__all__"
|
||||
DATA_DIR = "data"
|
||||
)
|
||||
|
||||
type TorrentManager struct {
|
||||
DirectoryMap cmap.ConcurrentMap[string, cmap.ConcurrentMap[string, *Torrent]] // directory -> accessKey -> Torrent
|
||||
@@ -47,6 +50,8 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
||||
mu: &sync.Mutex{},
|
||||
}
|
||||
|
||||
ensureDir(DATA_DIR)
|
||||
|
||||
// create special directory
|
||||
t.DirectoryMap.Set("__all__", cmap.New[*Torrent]()) // key is AccessKey
|
||||
// create directory maps
|
||||
@@ -414,7 +419,7 @@ func (t *TorrentManager) getName(name, originalName string) string {
|
||||
}
|
||||
|
||||
func (t *TorrentManager) writeToFile(torrent *realdebrid.TorrentInfo) error {
|
||||
filePath := "data/" + torrent.ID + ".bin"
|
||||
filePath := DATA_DIR + "/" + torrent.ID + ".bin"
|
||||
file, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed creating file: %w", err)
|
||||
@@ -433,7 +438,7 @@ func (t *TorrentManager) writeToFile(torrent *realdebrid.TorrentInfo) error {
|
||||
}
|
||||
|
||||
func (t *TorrentManager) readFromFile(torrentID string) *realdebrid.TorrentInfo {
|
||||
filePath := "data/" + torrentID + ".bin"
|
||||
filePath := DATA_DIR + "/" + torrentID + ".bin"
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
|
||||
Reference in New Issue
Block a user