Fix bugs
This commit is contained in:
@@ -21,8 +21,8 @@ func (t *TorrentManager) CheckDeletedState(torrent *Torrent) bool {
|
||||
}
|
||||
|
||||
func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) {
|
||||
if deleteInRD {
|
||||
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
|
||||
if deleteInRD {
|
||||
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
||||
if torrent, ok := allTorrents.Get(accessKey); ok {
|
||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||
@@ -34,8 +34,10 @@ func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) {
|
||||
})
|
||||
}
|
||||
}
|
||||
t.allAccessKeys.Remove(accessKey)
|
||||
t.log.Infof("Removing torrent %s from zurg database", accessKey)
|
||||
t.DirectoryMap.IterCb(func(directory string, torrents cmap.ConcurrentMap[string, *Torrent]) {
|
||||
torrents.Remove(accessKey)
|
||||
})
|
||||
allTorrents.Remove(accessKey)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ type TorrentManager struct {
|
||||
Api *realdebrid.RealDebrid
|
||||
DirectoryMap cmap.ConcurrentMap[string, cmap.ConcurrentMap[string, *Torrent]] // directory -> accessKey -> Torrent
|
||||
DownloadCache cmap.ConcurrentMap[string, *realdebrid.Download]
|
||||
accessKeySet *strset.Set
|
||||
allAccessKeys *strset.Set
|
||||
latestState *LibraryState
|
||||
requiredVersion string
|
||||
workerPool *ants.Pool
|
||||
@@ -42,7 +42,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
||||
t := &TorrentManager{
|
||||
Config: cfg,
|
||||
Api: api,
|
||||
accessKeySet: set.NewStringSet(),
|
||||
allAccessKeys: set.NewStringSet(),
|
||||
latestState: &initialSate,
|
||||
requiredVersion: "06.12.2023",
|
||||
workerPool: p,
|
||||
|
||||
@@ -43,6 +43,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
||||
}
|
||||
freshKeys.Add(info.AccessKey)
|
||||
if torrent, exists := allTorrents.Get(info.AccessKey); !exists {
|
||||
t.allAccessKeys.Add(info.AccessKey)
|
||||
allTorrents.Set(info.AccessKey, info)
|
||||
} else if !strset.Difference(info.DownloadedIDs, torrent.DownloadedIDs).IsEmpty() {
|
||||
mainTorrent := t.mergeToMain(torrent, info)
|
||||
@@ -50,17 +51,10 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
||||
}
|
||||
}
|
||||
t.log.Infof("Compiled into %d torrents, %d were missing info", allTorrents.Count(), noInfoCount)
|
||||
|
||||
// removed
|
||||
strset.Difference(t.accessKeySet, freshKeys).Each(func(accessKey string) bool {
|
||||
t.accessKeySet.Remove(accessKey)
|
||||
t.Delete(accessKey, false)
|
||||
return true
|
||||
})
|
||||
// new
|
||||
var updatedPaths []string
|
||||
strset.Difference(freshKeys, t.accessKeySet).Each(func(accessKey string) bool {
|
||||
t.accessKeySet.Add(accessKey)
|
||||
// torrents yet to be assigned in a directory
|
||||
strset.Difference(freshKeys, t.allAccessKeys).Each(func(accessKey string) bool {
|
||||
// assign to directories
|
||||
tor, _ := allTorrents.Get(accessKey)
|
||||
t.assignedDirectoryCb(tor, func(directory string) {
|
||||
if strings.HasPrefix(directory, "int__") {
|
||||
@@ -72,6 +66,11 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
||||
})
|
||||
return true
|
||||
})
|
||||
// removed torrents
|
||||
strset.Difference(t.allAccessKeys, freshKeys).Each(func(accessKey string) bool {
|
||||
t.Delete(accessKey, false)
|
||||
return true
|
||||
})
|
||||
|
||||
t.SetNewLatestState(t.getCurrentState())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user