Create repair queue

This commit is contained in:
Ben Sarmiento
2024-01-28 03:20:58 +01:00
parent f07b65d5da
commit 30dc080dba
3 changed files with 29 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ package torrent
import (
"io"
"os"
"path/filepath"
"strings"
"sync"
@@ -33,6 +34,7 @@ type TorrentManager struct {
workerPool *ants.Pool
repairPool *ants.Pool
repairTrigger chan *Torrent
repairSet mapset.Set[*Torrent]
repairRunning bool
repairRunningMu sync.Mutex
log *logutil.Logger
@@ -105,6 +107,14 @@ func (t *TorrentManager) GetKey(torrent *Torrent) string {
}
}
func (t *TorrentManager) GetPath(file *File) string {
if t.Config.ShouldExposeFullPath() {
filename := strings.TrimPrefix(file.Path, "/")
return strings.ReplaceAll(filename, "/", " - ")
}
return filepath.Base(file.Path)
}
func (t *TorrentManager) writeTorrentToFile(instanceID string, torrent *Torrent) {
filePath := "data/" + instanceID + ".json"
file, err := os.Create(filePath)