Remove fixer concept
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
cmap "github.com/orcaman/concurrent-map/v2"
|
||||
)
|
||||
|
||||
func (t *TorrentManager) refreshTorrents(isInitialRun bool) []string {
|
||||
func (t *TorrentManager) refreshTorrents() []string {
|
||||
instances, _, err := t.api.GetTorrents(false)
|
||||
if err != nil {
|
||||
t.log.Warnf("Cannot get torrents: %v", err)
|
||||
@@ -26,6 +26,11 @@ func (t *TorrentManager) refreshTorrents(isInitialRun bool) []string {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
for i := range instances {
|
||||
if t.trashBin.Contains(instances[i].ID) {
|
||||
t.api.DeleteTorrent(instances[i].ID)
|
||||
t.log.Infof("Skipping trashed torrent %s", instances[i].Name)
|
||||
torChan <- nil
|
||||
}
|
||||
idx := i
|
||||
wg.Add(1)
|
||||
_ = t.workerPool.Submit(func() {
|
||||
@@ -128,15 +133,6 @@ func (t *TorrentManager) refreshTorrents(isInitialRun bool) []string {
|
||||
return false
|
||||
})
|
||||
|
||||
if t.Config.EnableRepair() {
|
||||
if isInitialRun {
|
||||
t.removeExpiredFixers(instances)
|
||||
}
|
||||
t.workerPool.Submit(func() {
|
||||
t.processFixers(instances)
|
||||
})
|
||||
}
|
||||
|
||||
return updatedPaths
|
||||
}
|
||||
|
||||
@@ -157,7 +153,7 @@ func (t *TorrentManager) StartRefreshJob() {
|
||||
t.log.Infof("Detected changes! Refreshing %d torrents", checksum.TotalCount)
|
||||
t.setNewLatestState(checksum)
|
||||
|
||||
updatedPaths := t.refreshTorrents(false)
|
||||
updatedPaths := t.refreshTorrents()
|
||||
t.log.Info("Finished refreshing torrents")
|
||||
|
||||
t.TriggerHookOnLibraryUpdate(updatedPaths)
|
||||
@@ -294,36 +290,26 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) *Torrent {
|
||||
Rename: newer.Rename,
|
||||
Hash: newer.Hash,
|
||||
Added: newer.Added,
|
||||
|
||||
Components: mergedComponents,
|
||||
UnrepairableReason: newer.UnrepairableReason,
|
||||
Components: mergedComponents,
|
||||
|
||||
State: older.State,
|
||||
}
|
||||
|
||||
// unrepairable reason
|
||||
if mainTorrent.UnrepairableReason != "" && older.UnrepairableReason != "" && mainTorrent.UnrepairableReason != older.UnrepairableReason {
|
||||
mainTorrent.UnrepairableReason = fmt.Sprintf("%s, %s", mainTorrent.UnrepairableReason, older.UnrepairableReason)
|
||||
} else if older.UnrepairableReason != "" {
|
||||
mainTorrent.UnrepairableReason = older.UnrepairableReason
|
||||
}
|
||||
reasons := mapset.NewSet[string]()
|
||||
reasons.Add(older.UnrepairableReason)
|
||||
reasons.Add(newer.UnrepairableReason)
|
||||
mainTorrent.UnrepairableReason = strings.Join(reasons.ToSlice(), ", ")
|
||||
|
||||
// the link can have the following values
|
||||
// 1. https://*** - the file is available
|
||||
// 3. empty - the file is not available
|
||||
mainTorrent.SelectedFiles = cmap.New[*File]()
|
||||
newer.SelectedFiles.IterCb(func(key string, newerFile *File) {
|
||||
mainTorrent.SelectedFiles.Set(key, newerFile)
|
||||
})
|
||||
older.SelectedFiles.IterCb(func(key string, olderFile *File) {
|
||||
if !mainTorrent.SelectedFiles.Has(key) {
|
||||
mainTorrent.SelectedFiles.Set(key, olderFile)
|
||||
} else if olderFile.State.Is("deleted_file") {
|
||||
newerFile, _ := mainTorrent.SelectedFiles.Get(key)
|
||||
if err := newerFile.State.Event(context.Background(), "delete_file"); err != nil {
|
||||
t.log.Errorf("Cannot delete file %s: %v", key, err)
|
||||
}
|
||||
mainTorrent.SelectedFiles.Set(key, olderFile)
|
||||
})
|
||||
newer.SelectedFiles.IterCb(func(key string, newerFile *File) {
|
||||
if f, ok := mainTorrent.SelectedFiles.Get(key); ok && f.State.Is("deleted_file") {
|
||||
return
|
||||
}
|
||||
mainTorrent.SelectedFiles.Set(key, newerFile)
|
||||
})
|
||||
t.CheckDeletedStatus(&mainTorrent)
|
||||
|
||||
@@ -393,3 +379,8 @@ func (t *TorrentManager) IsPlayable(filePath string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *TorrentManager) trash(torrentId string) {
|
||||
t.log.Debugf("Trash: %s", torrentId)
|
||||
t.trashBin.Add(torrentId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user