Fix repairs for rared torrents
This commit is contained in:
@@ -20,7 +20,7 @@ func inProgressStatus(status string) bool {
|
||||
return status == "downloading" || status == "uploading" || status == "queued" || status == "compressing"
|
||||
}
|
||||
|
||||
func (t *TorrentManager) refreshTorrents() {
|
||||
func (t *TorrentManager) refreshTorrents(initialRun bool) {
|
||||
t.inProgressHashes = mapset.NewSet[string]()
|
||||
instances, _, err := t.api.GetTorrents(false)
|
||||
if err != nil {
|
||||
@@ -62,7 +62,7 @@ func (t *TorrentManager) refreshTorrents() {
|
||||
if !exists {
|
||||
allTorrents.Set(accessKey, torrent)
|
||||
t.writeTorrentToFile(torrent)
|
||||
t.assignDirectory(torrent, true)
|
||||
t.assignDirectory(torrent, !initialRun)
|
||||
} else if !mainTorrent.DownloadedIDs.Contains(tInfo.ID) {
|
||||
forMerging = torrent
|
||||
}
|
||||
@@ -94,7 +94,7 @@ func (t *TorrentManager) refreshTorrents() {
|
||||
mainTorrent := t.mergeTorrents(existing, torrent)
|
||||
allTorrents.Set(accessKey, mainTorrent)
|
||||
t.writeTorrentToFile(mainTorrent)
|
||||
t.assignDirectory(mainTorrent, true)
|
||||
t.assignDirectory(mainTorrent, !initialRun)
|
||||
}
|
||||
|
||||
// removed torrents
|
||||
@@ -106,19 +106,17 @@ func (t *TorrentManager) refreshTorrents() {
|
||||
|
||||
t.log.Infof("Compiled into %d unique torrents", allTorrents.Count())
|
||||
|
||||
t.workerPool.Submit(func() {
|
||||
// delete info files that are no longer present
|
||||
t.getInfoFiles().Each(func(path string) bool {
|
||||
path = filepath.Base(path)
|
||||
torrentID := strings.TrimSuffix(path, ".zurginfo")
|
||||
// if binOnceDone returns true, it means the info file is deleted
|
||||
// if false, then we check if it's one of the torrents we just fetched
|
||||
// if not, then we delete the info file
|
||||
if !t.binOnceDone(torrentID) && !freshIDs.Contains(torrentID) {
|
||||
t.deleteInfoFile(torrentID)
|
||||
}
|
||||
return false
|
||||
})
|
||||
// delete info files that are no longer present
|
||||
t.getInfoFiles().Each(func(path string) bool {
|
||||
path = filepath.Base(path)
|
||||
torrentID := strings.TrimSuffix(path, ".zurginfo")
|
||||
// if binOnceDone returns true, it means the info file is deleted
|
||||
// if false, then we check if it's one of the torrents we just fetched
|
||||
// if not (both are false), then we delete the info file
|
||||
if !t.binOnceDone(torrentID, false) && !freshIDs.Contains(torrentID) {
|
||||
t.deleteInfoFile(torrentID)
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
t.workerPool.Submit(func() {
|
||||
@@ -152,7 +150,7 @@ func (t *TorrentManager) StartRefreshJob() {
|
||||
}
|
||||
t.setNewLatestState(checksum)
|
||||
|
||||
t.refreshTorrents()
|
||||
t.refreshTorrents(false)
|
||||
t.log.Info("Finished refreshing torrents")
|
||||
case <-t.RefreshKillSwitch:
|
||||
t.log.Info("Stopping periodic refresh job")
|
||||
@@ -293,6 +291,8 @@ func (t *TorrentManager) mergeTorrents(existing, toMerge *Torrent) *Torrent {
|
||||
if !ok || !f.State.Is("ok_file") {
|
||||
mergedTorrent.SelectedFiles.Set(key, file)
|
||||
}
|
||||
// get the file again, set the media info
|
||||
f, ok = mergedTorrent.SelectedFiles.Get(key)
|
||||
if ok && f.MediaInfo == nil && mediaInfo != nil {
|
||||
f.MediaInfo = mediaInfo
|
||||
}
|
||||
@@ -328,6 +328,8 @@ func (t *TorrentManager) mergeTorrents(existing, toMerge *Torrent) *Torrent {
|
||||
mergedTorrent.State.Event(context.Background(), "mark_as_repaired")
|
||||
}
|
||||
|
||||
t.log.Debugf("Merged torrent %s has %d broken files", t.GetKey(mergedTorrent), brokenCount)
|
||||
|
||||
return mergedTorrent
|
||||
}
|
||||
|
||||
@@ -366,6 +368,7 @@ func (t *TorrentManager) assignDirectory(tor *Torrent, triggerHook bool) {
|
||||
// Map torrents to directories
|
||||
switch t.Config.GetVersion() {
|
||||
case "v1":
|
||||
updatedPaths := make([]string, 0)
|
||||
configV1 := t.Config.(*config.ZurgConfigV1)
|
||||
for _, directories := range configV1.GetGroupMap() {
|
||||
for _, directory := range directories {
|
||||
@@ -374,12 +377,15 @@ func (t *TorrentManager) assignDirectory(tor *Torrent, triggerHook bool) {
|
||||
listing.Set(accessKey, tor)
|
||||
|
||||
if triggerHook {
|
||||
t.TriggerHookOnLibraryUpdate([]string{fmt.Sprintf("%s/%s", directory, accessKey)})
|
||||
updatedPaths = append(updatedPaths, fmt.Sprintf("%s/%s", directory, accessKey))
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if triggerHook {
|
||||
OnLibraryUpdateHook(updatedPaths, t.Config, t.log)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user