Fix repair fsm
This commit is contained in:
@@ -63,17 +63,13 @@ func (dl *Downloader) DownloadFile(
|
||||
|
||||
unrestrict := torMgr.UnrestrictFileUntilOk(file)
|
||||
if unrestrict == nil {
|
||||
log.Warnf("File %s cannot be unrestricted (link=%s)", fileName, file.Link)
|
||||
if err := file.State.Event(context.Background(), "break_file"); err != nil {
|
||||
log.Errorf("File %s is stale: %v", fileName, err)
|
||||
http.Error(resp, "File is stale, please try again", http.StatusLocked)
|
||||
return
|
||||
}
|
||||
if cfg.EnableRepair() {
|
||||
log.Warnf("File %s cannot be unrestricted (link=%s) (repairing...)", fileName, file.Link)
|
||||
torMgr.TriggerRepair(torrent)
|
||||
} else {
|
||||
log.Warnf("Repair is disabled, skipping repair for unavailable file %s (link=%s)", fileName, file.Link)
|
||||
}
|
||||
torMgr.TriggerRepair(torrent)
|
||||
http.Error(resp, "File is not available", http.StatusNotFound)
|
||||
return
|
||||
} else {
|
||||
@@ -152,20 +148,14 @@ func (dl *Downloader) streamFileToResponse(
|
||||
// Perform the request
|
||||
downloadResp, err := dl.client.Do(dlReq)
|
||||
if err != nil {
|
||||
if file != nil && unrestrict.Streamable == 1 {
|
||||
log.Warnf("Cannot download file %s: %v", unrestrict.Download, err)
|
||||
if file != nil {
|
||||
if err := file.State.Event(context.Background(), "break_file"); err != nil {
|
||||
log.Errorf("File %s is stale: %v", file.Path, err)
|
||||
http.Error(resp, "File is stale, please try again", http.StatusLocked)
|
||||
return
|
||||
}
|
||||
if cfg.EnableRepair() && torrent != nil {
|
||||
log.Warnf("Cannot download file %s: %v (repairing...)", unrestrict.Download, err)
|
||||
torMgr.TriggerRepair(torrent)
|
||||
} else {
|
||||
log.Warnf("Repair is disabled, skipping repair for unavailable file %s (link=%s)", file.Path, file.Link)
|
||||
}
|
||||
} else {
|
||||
log.Warnf("Cannot download file %s: %v", unrestrict.Download, err)
|
||||
torMgr.TriggerRepair(torrent)
|
||||
}
|
||||
http.Error(resp, "File is not available", http.StatusNotFound)
|
||||
return
|
||||
@@ -174,20 +164,14 @@ func (dl *Downloader) streamFileToResponse(
|
||||
|
||||
// Check if the download was not successful
|
||||
if downloadResp.StatusCode/100 != 2 {
|
||||
if file != nil && unrestrict.Streamable == 1 {
|
||||
log.Warnf("Received a %s status code for file %s", downloadResp.Status, unrestrict.Filename)
|
||||
if file != nil {
|
||||
if err := file.State.Event(context.Background(), "break_file"); err != nil {
|
||||
log.Errorf("File %s is stale: %v", file.Path, err)
|
||||
http.Error(resp, "File is stale, please try again", http.StatusLocked)
|
||||
return
|
||||
}
|
||||
if cfg.EnableRepair() && torrent != nil {
|
||||
log.Warnf("Received a %s status code for file %s (repairing...)", downloadResp.Status, file.Path)
|
||||
torMgr.TriggerRepair(torrent)
|
||||
} else {
|
||||
log.Warnf("Repair is disabled, skipping repair for unavailable file %s (link=%s)", file.Path, file.Link)
|
||||
}
|
||||
} else {
|
||||
log.Warnf("Received a %s status code for file %s", downloadResp.Status, unrestrict.Download)
|
||||
torMgr.TriggerRepair(torrent)
|
||||
}
|
||||
http.Error(resp, "File is not available", http.StatusNotFound)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user