Resolve refresh bug

This commit is contained in:
Ben Sarmiento
2024-01-31 21:26:02 +01:00
parent 4c9b54c01c
commit bee28e74cf

View File

@@ -23,7 +23,6 @@ func (t *TorrentManager) refreshTorrents() []string {
infoChan := make(chan *Torrent, len(instances)) infoChan := make(chan *Torrent, len(instances))
var wg sync.WaitGroup var wg sync.WaitGroup
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
for i := range instances { for i := range instances {
idx := i idx := i
wg.Add(1) wg.Add(1)
@@ -39,13 +38,14 @@ func (t *TorrentManager) refreshTorrents() []string {
newlyFetchedKeys := mapset.NewSet[string]() newlyFetchedKeys := mapset.NewSet[string]()
noInfoCount := 0 noInfoCount := 0
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
for info := range infoChan { for info := range infoChan {
if info == nil { if info == nil {
noInfoCount++ noInfoCount++
continue continue
} }
accessKey := t.GetKey(info) accessKey := t.GetKey(info)
if !info.AllInProgress() { if !info.AnyInProgress() {
newlyFetchedKeys.Add(accessKey) newlyFetchedKeys.Add(accessKey)
} }
@@ -261,7 +261,6 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
DownloadedIDs: newer.DownloadedIDs.Union(older.DownloadedIDs), DownloadedIDs: newer.DownloadedIDs.Union(older.DownloadedIDs),
InProgressIDs: newer.InProgressIDs.Union(older.InProgressIDs), InProgressIDs: newer.InProgressIDs.Union(older.InProgressIDs),
UnassignedLinks: newer.UnassignedLinks.Union(older.UnassignedLinks), UnassignedLinks: newer.UnassignedLinks.Union(older.UnassignedLinks),
SelectedFiles: newer.SelectedFiles,
UnrepairableReason: newer.UnrepairableReason, UnrepairableReason: newer.UnrepairableReason,
} }
@@ -281,21 +280,34 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
// the link can have the following values // the link can have the following values
// 1. https://*** - the file is available // 1. https://*** - the file is available
// 3. empty - the file is not available // 3. empty - the file is not available
mainTorrent.SelectedFiles.IterCb(func(key string, file *File) { mainTorrent.SelectedFiles = cmap.New[*File]()
if file.IsBroken { newer.SelectedFiles.IterCb(func(key string, newerFile *File) {
file, ok := older.SelectedFiles.Get(key) if !newerFile.IsBroken {
if ok { mainTorrent.SelectedFiles.Set(key, newerFile)
mainTorrent.SelectedFiles.Set(key, file) return
} }
olderFile, ok := older.SelectedFiles.Get(key)
if ok && !olderFile.IsBroken {
mainTorrent.SelectedFiles.Set(key, olderFile)
return
} }
mainTorrent.SelectedFiles.Set(key, newerFile)
}) })
older.SelectedFiles.IterCb(func(key string, file *File) { inconsistentDeletes := false
older.SelectedFiles.IterCb(func(key string, olderFile *File) {
if !mainTorrent.SelectedFiles.Has(key) { if !mainTorrent.SelectedFiles.Has(key) {
mainTorrent.SelectedFiles.Set(key, file) mainTorrent.SelectedFiles.Set(key, olderFile)
} else if file.IsDeleted { return
mainTorrent.SelectedFiles.Set(key, file) }
newerFile, _ := mainTorrent.SelectedFiles.Get(key)
if olderFile.IsDeleted && !newerFile.IsDeleted {
newerFile.IsDeleted = true
inconsistentDeletes = true
} }
}) })
if inconsistentDeletes {
t.CheckDeletedStatus(&mainTorrent)
}
return mainTorrent return mainTorrent
} }