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

@@ -35,7 +35,7 @@ func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) {
if deleteInRD { if deleteInRD {
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE) infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
if torrent, ok := allTorrents.Get(accessKey); ok { if torrent, ok := allTorrents.Get(accessKey); ok {
torrent.DownloadedIDs.Each(func(id string) bool { torrent.DownloadedIDs.Union(torrent.InProgressIDs).Each(func(id string) bool {
t.log.Debugf("Deleting torrent %s %s in RD", id, accessKey) t.log.Debugf("Deleting torrent %s %s in RD", id, accessKey)
t.Api.DeleteTorrent(id) t.Api.DeleteTorrent(id)
infoCache.Remove(id) infoCache.Remove(id)

View File

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