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 { func (z *ZurgConfigV1) GetDirectories() []string {
rootDirectories := make([]string, len(z.Directories)+3) rootDirectories := make([]string, len(z.Directories))
i := 0
for directory := range z.Directories { for directory := range z.Directories {
rootDirectories[i] = directory rootDirectories = append(rootDirectories, directory)
i++
} }
rootDirectories[i] = ALL_TORRENTS
rootDirectories[i+1] = UNPLAYABLE_TORRENTS
rootDirectories[i+2] = DUMPED_TORRENTS
return rootDirectories return rootDirectories
} }

View File

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

View File

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

View File

@@ -535,8 +535,12 @@ func (t *TorrentManager) initializeDirectoryMaps() {
// create directory maps // create directory maps
for _, directory := range t.Config.GetDirectories() { for _, directory := range t.Config.GetDirectories() {
t.DirectoryMap.Set(directory, cmap.New[*Torrent]()) 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 { 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) accessKey := t.GetKey(tor)
t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) { 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 return
} }
torrents.Remove(accessKey) torrents.Remove(accessKey)

View File

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