Remove components, do downloaded ids ; support dumps

This commit is contained in:
Ben Sarmiento
2024-05-24 02:24:26 +02:00
parent beba993364
commit 9ecbb5d892
8 changed files with 188 additions and 107 deletions

View File

@@ -45,8 +45,8 @@ type TorrentManager struct {
repairRunning bool
repairRunningMu sync.Mutex
trashBin mapset.Set[string]
repairBin mapset.Set[string] // same as trash bin, but only if the torrent has been downloaded
immediateBin mapset.Set[string]
onceDoneBin mapset.Set[string]
}
// NewTorrentManager creates a new torrent manager
@@ -73,8 +73,8 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w
latestState: &LibraryState{log: log},
}
t.trashBin = mapset.NewSet[string]()
t.initializeDirectories()
t.initializeBins()
t.initializeDirectoryMaps()
t.workerPool.Submit(func() {
t.refreshTorrents()
t.setNewLatestState(t.getCurrentState())
@@ -139,17 +139,17 @@ func (t *TorrentManager) GetPath(file *File) string {
/// torrent functions
func (t *TorrentManager) getTorrentFiles() mapset.Set[string] {
files, err := filepath.Glob("data/*.torrent_zurg")
func (t *TorrentManager) getTorrentFiles(parentDir string) mapset.Set[string] {
files, err := filepath.Glob(parentDir + "/*.zurgtorrent")
if err != nil {
t.log.Warnf("Cannot get files in data directory: %v", err)
t.log.Warnf("Cannot get files in %s directory: %v", parentDir, err)
return nil
}
return mapset.NewSet[string](files...)
}
func (t *TorrentManager) writeTorrentToFile(torrent *Torrent) {
filePath := "data/" + torrent.Hash + ".torrent_zurg"
filePath := "data/" + torrent.Hash + ".zurgtorrent"
file, err := os.Create(filePath)
if err != nil {
t.log.Warnf("Cannot create file %s: %v", filePath, err)
@@ -173,8 +173,7 @@ func (t *TorrentManager) writeTorrentToFile(torrent *Torrent) {
t.log.Debugf("Saved torrent %s (hash=%s) to file", t.GetKey(torrent), torrent.Hash)
}
func (t *TorrentManager) readTorrentFromFile(hash string) *Torrent {
filePath := "data/" + hash + ".torrent_zurg"
func (t *TorrentManager) readTorrentFromFile(filePath string) *Torrent {
file, err := os.Open(filePath)
if err != nil {
if os.IsNotExist(err) {
@@ -198,7 +197,7 @@ func (t *TorrentManager) readTorrentFromFile(hash string) *Torrent {
}
func (t *TorrentManager) deleteTorrentFile(hash string) {
filePath := "data/" + hash + ".torrent_zurg"
filePath := "data/" + hash + ".zurgtorrent"
_ = os.Remove(filePath)
}
@@ -310,7 +309,7 @@ func (t *TorrentManager) StartDownloadsJob() {
})
}
func (t *TorrentManager) initializeDirectories() {
func (t *TorrentManager) initializeDirectoryMaps() {
// create internal directories
t.DirectoryMap.Set(INT_ALL, cmap.New[*Torrent]()) // key is GetAccessKey()
// create directory maps