Fix repairs

This commit is contained in:
Ben Sarmiento
2023-12-07 11:53:35 +01:00
parent 35bffc12f5
commit caa42822ac
4 changed files with 48 additions and 13 deletions

View File

@@ -68,9 +68,13 @@ func (gf *GetFile) HandleGetRequest(directory, torrentName, fileName string, res
log.Debugf("Opening file %s from torrent %s (%s)", fileName, torrentName, link)
unrestrict := torMgr.UnrestrictUntilOk(link)
if unrestrict == nil {
// log.Warnf("File %s is no longer available, link %s", filepath.Base(file.Path), link)
file.Link = "repairing"
torMgr.Repair(torrent)
log.Warnf("File %s cannot be unrestricted (link=%s)", fileName, link)
if cfg.EnableRepair() {
file.Link = "repairing"
torMgr.Repair(torrent)
} else {
log.Info("Repair is disabled, skipping repair for unavailable file")
}
http.Error(resp, "File is not available", http.StatusNotFound)
return
} else {
@@ -150,8 +154,12 @@ func (gf *GetFile) streamFileToResponse(torrent *intTor.Torrent, file *intTor.Fi
if err != nil {
if file != nil && unrestrict.Streamable == 1 {
log.Warnf("Cannot download file %s: %v", file.Path, err)
file.Link = "repairing"
torMgr.Repair(torrent)
if cfg.EnableRepair() {
file.Link = "repairing"
torMgr.Repair(torrent)
} else {
log.Info("Repair is disabled, skipping repair for unavailable file")
}
}
http.Error(resp, "File is not available", http.StatusNotFound)
return
@@ -161,8 +169,12 @@ func (gf *GetFile) streamFileToResponse(torrent *intTor.Torrent, file *intTor.Fi
if download.StatusCode != http.StatusOK && download.StatusCode != http.StatusPartialContent {
if file != nil && unrestrict.Streamable == 1 {
log.Warnf("Received a %s status code for file %s", download.Status, file.Path)
file.Link = "repairing"
torMgr.Repair(torrent)
if cfg.EnableRepair() {
file.Link = "repairing"
torMgr.Repair(torrent)
} else {
log.Info("Repair is disabled, skipping repair for unavailable file")
}
}
http.Error(resp, "File is not available", http.StatusNotFound)
return