Prevent double repairs
This commit is contained in:
@@ -12,7 +12,9 @@ func (t *TorrentManager) CheckDeletedStatus(torrent *Torrent) bool {
|
|||||||
if len(unselectedIDs) == torrent.SelectedFiles.Count() && len(unselectedIDs) > 0 {
|
if len(unselectedIDs) == torrent.SelectedFiles.Count() && len(unselectedIDs) > 0 {
|
||||||
return true
|
return true
|
||||||
} else if len(unselectedIDs) > 0 {
|
} else if len(unselectedIDs) > 0 {
|
||||||
|
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
||||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||||
|
infoCache.Set(id, torrent)
|
||||||
t.writeTorrentToFile(id, torrent)
|
t.writeTorrentToFile(id, torrent)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -23,12 +23,12 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
for i := range instances {
|
for i := range instances {
|
||||||
wg.Add(1)
|
idx := i
|
||||||
idx := i // capture the loop variable
|
|
||||||
_ = t.workerPool.Submit(func() {
|
_ = t.workerPool.Submit(func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
infoChan <- t.getMoreInfo(instances[idx])
|
infoChan <- t.getMoreInfo(instances[idx])
|
||||||
})
|
})
|
||||||
|
wg.Add(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
@@ -43,7 +43,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
|||||||
noInfoCount++
|
noInfoCount++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !info.AllInProgress() {
|
if !info.AnyInProgress() {
|
||||||
freshKeys.Add(info.AccessKey)
|
freshKeys.Add(info.AccessKey)
|
||||||
}
|
}
|
||||||
if torrent, exists := allTorrents.Get(info.AccessKey); !exists {
|
if torrent, exists := allTorrents.Get(info.AccessKey); !exists {
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ func (t *TorrentManager) repairAll() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TorrentManager) Repair(torrent *Torrent) {
|
func (t *TorrentManager) Repair(torrent *Torrent) {
|
||||||
|
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
||||||
|
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||||
|
infoCache.Set(id, torrent)
|
||||||
|
t.writeTorrentToFile(id, torrent)
|
||||||
|
return true
|
||||||
|
})
|
||||||
_ = t.repairWorker.Submit(func() {
|
_ = t.repairWorker.Submit(func() {
|
||||||
t.log.Infof("Repairing torrent %s", torrent.AccessKey)
|
t.log.Infof("Repairing torrent %s", torrent.AccessKey)
|
||||||
t.repair(torrent)
|
t.repair(torrent)
|
||||||
@@ -73,8 +79,9 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
|||||||
// second solution: add only the missing files
|
// second solution: add only the missing files
|
||||||
var missingFiles []File
|
var missingFiles []File
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
if !strings.HasPrefix(file.Link, "http") {
|
if file.Link == "repair" || file.Link == "" {
|
||||||
missingFiles = append(missingFiles, *file)
|
missingFiles = append(missingFiles, *file)
|
||||||
|
file.Link = "repairing"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.log.Debugf("During repair, zurg found %d broken files for torrent %s", len(missingFiles), torrent.AccessKey)
|
t.log.Debugf("During repair, zurg found %d broken files for torrent %s", len(missingFiles), torrent.AccessKey)
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ func (gf *GetFile) HandleGetRequest(directory, torrentName, fileName string, res
|
|||||||
if unrestrict == nil {
|
if unrestrict == nil {
|
||||||
log.Warnf("File %s cannot be unrestricted (link=%s)", fileName, link)
|
log.Warnf("File %s cannot be unrestricted (link=%s)", fileName, link)
|
||||||
if cfg.EnableRepair() {
|
if cfg.EnableRepair() {
|
||||||
file.Link = "repairing"
|
file.Link = "repair"
|
||||||
torMgr.Repair(torrent)
|
torMgr.Repair(torrent)
|
||||||
} else {
|
} else {
|
||||||
log.Infof("Repair is disabled, skipping repair for unavailable file %s (link=%s)", fileName, link)
|
log.Infof("Repair is disabled, skipping repair for unavailable file %s (link=%s)", fileName, link)
|
||||||
@@ -169,7 +169,7 @@ func (gf *GetFile) streamFileToResponse(torrent *intTor.Torrent, file *intTor.Fi
|
|||||||
if file != nil && unrestrict.Streamable == 1 {
|
if file != nil && unrestrict.Streamable == 1 {
|
||||||
log.Warnf("Cannot download file %s: %v", file.Path, err)
|
log.Warnf("Cannot download file %s: %v", file.Path, err)
|
||||||
if cfg.EnableRepair() {
|
if cfg.EnableRepair() {
|
||||||
file.Link = "repairing"
|
file.Link = "repair"
|
||||||
torMgr.Repair(torrent)
|
torMgr.Repair(torrent)
|
||||||
} else {
|
} else {
|
||||||
log.Infof("Repair is disabled, skipping repair for unavailable file %s (link=%s)", file.Path, file.Link)
|
log.Infof("Repair is disabled, skipping repair for unavailable file %s (link=%s)", file.Path, file.Link)
|
||||||
@@ -184,7 +184,7 @@ func (gf *GetFile) streamFileToResponse(torrent *intTor.Torrent, file *intTor.Fi
|
|||||||
if file != nil && unrestrict.Streamable == 1 {
|
if file != nil && unrestrict.Streamable == 1 {
|
||||||
log.Warnf("Received a %s status code for file %s", download.Status, file.Path)
|
log.Warnf("Received a %s status code for file %s", download.Status, file.Path)
|
||||||
if cfg.EnableRepair() {
|
if cfg.EnableRepair() {
|
||||||
file.Link = "repairing"
|
file.Link = "repair"
|
||||||
torMgr.Repair(torrent)
|
torMgr.Repair(torrent)
|
||||||
} else {
|
} else {
|
||||||
log.Infof("Repair is disabled, skipping repair for unavailable file %s (link=%s)", file.Path, file.Link)
|
log.Infof("Repair is disabled, skipping repair for unavailable file %s (link=%s)", file.Path, file.Link)
|
||||||
|
|||||||
Reference in New Issue
Block a user