Repair check is now sync

This commit is contained in:
Ben Sarmiento
2024-01-20 03:11:01 +01:00
parent ccd260db6a
commit d906230514
2 changed files with 13 additions and 16 deletions

View File

@@ -117,6 +117,7 @@ func (t *TorrentManager) Repair(torrent *Torrent) {
return
}
t.repairs.Add(t.GetKey(torrent))
// save the broken files to the file cache
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
torrent.DownloadedIDs.Each(func(id string) bool {
@@ -132,13 +133,7 @@ func (t *TorrentManager) Repair(torrent *Torrent) {
t.writeTorrentToFile(id, info)
return false
})
_ = t.workerPool.Submit(func() {
t.repair(torrent)
t.repairs.Remove(t.GetKey(torrent))
})
}
func (t *TorrentManager) repair(torrent *Torrent) {
t.log.Infof("Attempting repair for torrent %s", t.GetKey(torrent))
if torrent.AnyInProgress() {
t.log.Infof("Torrent %s is in progress, skipping repair until download is done", t.GetKey(torrent))
@@ -151,6 +146,15 @@ func (t *TorrentManager) repair(torrent *Torrent) {
return
}
_ = t.workerPool.Submit(func() {
t.repair(torrent)
t.repairs.Remove(t.GetKey(torrent))
})
}
func (t *TorrentManager) repair(torrent *Torrent) {
t.log.Infof("Started repair process for torrent %s", t.GetKey(torrent))
// handle torrents with incomplete links for selected files
assignedCount := 0
@@ -287,7 +291,6 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
}
return nil, fmt.Errorf("cannot redownload torrent: %v", err)
}
time.Sleep(1 * time.Second)
// select files
newTorrentID := resp.ID
@@ -296,7 +299,6 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
t.Api.DeleteTorrent(newTorrentID)
return nil, fmt.Errorf("cannot start redownloading: %v", err)
}
time.Sleep(1 * time.Second)
// see if the torrent is ready
info, err := t.Api.GetTorrentInfo(newTorrentID)
@@ -323,10 +325,7 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
if info.Progress != 100 {
t.log.Infof("Torrent %s (id=%s) is not cached anymore so we have to wait until completion (this should fix the issue already)", t.GetKey(torrent), info.ID)
if len(oldTorrentIDs) > 0 {
// only triggered when brokenFiles == ""
for _, id := range oldTorrentIDs {
t.Api.DeleteTorrent(id)
}
t.Delete(t.GetKey(torrent), true)
} else {
t.fixers.Set(newTorrentID, torrent)
}
@@ -341,9 +340,7 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, brokenFiles string)
if len(oldTorrentIDs) > 0 {
// only triggered when brokenFiles == ""
for _, id := range oldTorrentIDs {
t.Api.DeleteTorrent(id)
}
t.Delete(t.GetKey(torrent), true)
} else {
t.fixers.Set(newTorrentID, torrent)
}