From d2c1e12e2ce603df81b49951f2daa90e61452613 Mon Sep 17 00:00:00 2001 From: Ben Adrian Sarmiento Date: Fri, 19 Jul 2024 04:42:09 +0200 Subject: [PATCH] Add accidental removal fix --- internal/config/v1.go | 9 ++------- internal/dav/rename.go | 1 + internal/torrent/delete.go | 5 +++++ internal/torrent/manager.go | 6 +++++- internal/torrent/refresh.go | 2 +- internal/torrent/repair.go | 9 +++------ 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/internal/config/v1.go b/internal/config/v1.go index 8346154..56ee87c 100644 --- a/internal/config/v1.go +++ b/internal/config/v1.go @@ -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 } diff --git a/internal/dav/rename.go b/internal/dav/rename.go index b8cd752..e5a8a8a 100644 --- a/internal/dav/rename.go +++ b/internal/dav/rename.go @@ -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 diff --git a/internal/torrent/delete.go b/internal/torrent/delete.go index 282179c..3867667 100644 --- a/internal/torrent/delete.go +++ b/internal/torrent/delete.go @@ -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) } diff --git a/internal/torrent/manager.go b/internal/torrent/manager.go index ad461dd..dfb6901 100644 --- a/internal/torrent/manager.go +++ b/internal/torrent/manager.go @@ -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 { diff --git a/internal/torrent/refresh.go b/internal/torrent/refresh.go index 05a952e..06cc63f 100644 --- a/internal/torrent/refresh.go +++ b/internal/torrent/refresh.go @@ -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) diff --git a/internal/torrent/repair.go b/internal/torrent/repair.go index 86f09b4..bec70b7 100644 --- a/internal/torrent/repair.go +++ b/internal/torrent/repair.go @@ -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) }