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