Reimplement deletes and marking files as broken

This commit is contained in:
Ben Sarmiento
2024-01-29 22:28:27 +01:00
parent 1615c9e121
commit b505400f60
12 changed files with 64 additions and 112 deletions

View File

@@ -24,10 +24,8 @@ func (t *TorrentManager) refreshTorrents() []string {
var wg sync.WaitGroup
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
doesNotExist := t.deleteOnceDone.Clone()
for i := range instances {
idx := i
doesNotExist.Remove(instances[idx].ID) // remove if existing
wg.Add(1)
_ = t.workerPool.Submit(func() {
defer wg.Done()
@@ -48,30 +46,6 @@ func (t *TorrentManager) refreshTorrents() []string {
close(infoChan)
t.log.Infof("Fetched info for %d torrents", len(instances))
// delete expired fixers
doesNotExist.Each(func(fixerID string) bool {
t.fixers.Remove(fixerID)
t.deleteOnceDone.Remove(fixerID)
return false
})
// ensure delete
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
for {
fixerToDel, ok := t.deleteOnceDone.Pop()
if !ok {
break
}
torrent, exists := infoCache.Get(fixerToDel)
if exists && torrent.AnyInProgress() {
continue
}
t.log.Debugf("Ensuring that torrent id=%s is deleted", fixerToDel)
t.Delete(t.GetKey(torrent), true)
t.Api.DeleteTorrent(fixerToDel)
infoCache.Remove(fixerToDel)
}
newlyFetchedKeys := mapset.NewSet[string]()
noInfoCount := 0
for info := range infoChan {
@@ -169,7 +143,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
hasBrokenFiles := false
torrentFromFile.SelectedFiles.IterCb(func(filepath string, file *File) {
if !strings.HasPrefix(file.Link, "http") && file.Link != "unselect" {
if file.IsBroken && !file.IsDeleted {
hasBrokenFiles = true
}
})
@@ -307,7 +281,6 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
// the link can have the following values
// 1. https://*** - the file is available
// 2. unselect - the file is deleted
// 3. empty - the file is not available
mainTorrent.SelectedFiles.IterCb(func(key string, file *File) {
if file.Link == "" {
@@ -320,7 +293,7 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
older.SelectedFiles.IterCb(func(key string, file *File) {
if !mainTorrent.SelectedFiles.Has(key) {
mainTorrent.SelectedFiles.Set(key, file)
} else if file.Link == "unselect" {
} else if file.IsDeleted {
mainTorrent.SelectedFiles.Set(key, file)
}
})