Add accidental removal fix

This commit is contained in:
Ben Adrian Sarmiento
2024-07-19 04:42:09 +02:00
parent eaabd20a83
commit d2c1e12e2c
6 changed files with 17 additions and 15 deletions

View File

@@ -56,15 +56,10 @@ func (z *ZurgConfigV1) GetVersion() string {
}
func (z *ZurgConfigV1) GetDirectories() []string {
rootDirectories := make([]string, len(z.Directories)+3)
i := 0
rootDirectories := make([]string, len(z.Directories))
for directory := range z.Directories {
rootDirectories[i] = directory
i++
rootDirectories = append(rootDirectories, directory)
}
rootDirectories[i] = ALL_TORRENTS
rootDirectories[i+1] = UNPLAYABLE_TORRENTS
rootDirectories[i+2] = DUMPED_TORRENTS
return rootDirectories
}

View File

@@ -15,6 +15,7 @@ func HandleRenameTorrent(directory, torrentName, newName string, torMgr *torrent
if !ok {
return fmt.Errorf("cannot find torrent %s", torrentName)
}
// todo: need to remove on all directories
torrents.Remove(torrentName)
torrents.Set(newName, torrent)
torrent.Rename = newName

View File

@@ -1,6 +1,7 @@
package torrent
import (
"github.com/debridmediamanager/zurg/internal/config"
cmap "github.com/orcaman/concurrent-map/v2"
)
@@ -32,8 +33,12 @@ func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) {
}
// t.log.Infof("Removing torrent %s from zurg database (not real-debrid)", accessKey)
t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) {
if directory == config.DOWNLOADS || directory == config.DUMPED_TORRENTS {
return
}
torrents.Remove(accessKey)
})
allTorrents.Remove(accessKey)
}

View File

@@ -535,8 +535,12 @@ func (t *TorrentManager) initializeDirectoryMaps() {
// create directory maps
for _, directory := range t.Config.GetDirectories() {
t.DirectoryMap.Set(directory, cmap.New[*Torrent]())
// t.RootNode.AddChild(fs.NewFileNode(directory, true))
}
// create special directories
t.DirectoryMap.Set(config.ALL_TORRENTS, cmap.New[*Torrent]())
t.DirectoryMap.Set(config.DOWNLOADS, cmap.New[*Torrent]())
t.DirectoryMap.Set(config.DUMPED_TORRENTS, cmap.New[*Torrent]())
t.DirectoryMap.Set(config.UNPLAYABLE_TORRENTS, cmap.New[*Torrent]())
}
func (t *TorrentManager) getTorrentFilename(torrent *Torrent) string {

View File

@@ -357,7 +357,7 @@ func (t *TorrentManager) assignDirectory(tor *Torrent, triggerHook bool, outputL
accessKey := t.GetKey(tor)
t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) {
if strings.HasPrefix(directory, "int__") {
if directory == config.DOWNLOADS || directory == config.DUMPED_TORRENTS {
return
}
torrents.Remove(accessKey)

View File

@@ -590,13 +590,10 @@ func (t *TorrentManager) canCapacityHandle() bool {
}
func (t *TorrentManager) markAsUnplayable(torrent *Torrent) {
// reassign to unplayable torrents directory
t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) {
if strings.HasPrefix(directory, "int__") {
return
}
for _, directory := range t.Config.GetDirectories() {
torrents, _ := t.DirectoryMap.Get(directory)
torrents.Remove(t.GetKey(torrent))
})
}
torrents, _ := t.DirectoryMap.Get(config.UNPLAYABLE_TORRENTS)
torrents.Set(t.GetKey(torrent), torrent)
}