Rewrite state machines
This commit is contained in:
@@ -30,14 +30,14 @@ func HandleDeleteFile(directory, torrentName, fileName string, torMgr *torrent.T
|
|||||||
return fmt.Errorf("cannot find torrent %s", torrentName)
|
return fmt.Errorf("cannot find torrent %s", torrentName)
|
||||||
}
|
}
|
||||||
file, ok := torrent.SelectedFiles.Get(fileName)
|
file, ok := torrent.SelectedFiles.Get(fileName)
|
||||||
if !ok || !file.State.Is("ok") {
|
if !ok || !file.State.Is("ok_file") {
|
||||||
return fmt.Errorf("cannot find file %s", fileName)
|
return fmt.Errorf("cannot find file %s", fileName)
|
||||||
}
|
}
|
||||||
dirCfg := torMgr.Config.(*config.ZurgConfigV1).GetDirectoryConfig(directory)
|
dirCfg := torMgr.Config.(*config.ZurgConfigV1).GetDirectoryConfig(directory)
|
||||||
if dirCfg.OnlyShowTheBiggestFile {
|
if dirCfg.OnlyShowTheBiggestFile {
|
||||||
torMgr.Delete(torrentName, true)
|
torMgr.Delete(torrentName, true)
|
||||||
} else {
|
} else {
|
||||||
err := file.State.Event(context.Background(), "delete")
|
err := file.State.Event(context.Background(), "delete_file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot delete file %s: %v", fileName, err)
|
return fmt.Errorf("cannot delete file %s: %v", fileName, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ func ServeFilesListForInfuse(directory, torrentName string, torMgr *torrent.Torr
|
|||||||
sort.Strings(filenames)
|
sort.Strings(filenames)
|
||||||
for _, filename := range filenames {
|
for _, filename := range filenames {
|
||||||
file, _ := tor.SelectedFiles.Get(filename)
|
file, _ := tor.SelectedFiles.Get(filename)
|
||||||
if !file.State.Is("ok") {
|
if !file.State.Is("ok_file") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
|
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManage
|
|||||||
sort.Strings(filenames)
|
sort.Strings(filenames)
|
||||||
for _, filename := range filenames {
|
for _, filename := range filenames {
|
||||||
file, _ := tor.SelectedFiles.Get(filename)
|
file, _ := tor.SelectedFiles.Get(filename)
|
||||||
if !file.State.Is("ok") {
|
if !file.State.Is("ok_file") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
|
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
|
||||||
@@ -107,7 +107,7 @@ func HandleSingleFile(directory, torrentName, fileName string, torMgr *torrent.T
|
|||||||
return nil, fmt.Errorf("cannot find torrent %s", torrentName)
|
return nil, fmt.Errorf("cannot find torrent %s", torrentName)
|
||||||
}
|
}
|
||||||
file, ok := tor.SelectedFiles.Get(fileName)
|
file, ok := tor.SelectedFiles.Get(fileName)
|
||||||
if !ok || !file.State.Is("ok") {
|
if !ok || !file.State.Is("ok_file") {
|
||||||
return nil, fmt.Errorf("cannot find file %s", fileName)
|
return nil, fmt.Errorf("cannot find file %s", fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func HandleRenameFile(directory, torrentName, fileName, newName string, torMgr *
|
|||||||
return fmt.Errorf("cannot find torrent %s", torrentName)
|
return fmt.Errorf("cannot find torrent %s", torrentName)
|
||||||
}
|
}
|
||||||
file, ok := torrent.SelectedFiles.Get(fileName)
|
file, ok := torrent.SelectedFiles.Get(fileName)
|
||||||
if !ok || !file.State.Is("ok") {
|
if !ok || !file.State.Is("ok_file") {
|
||||||
return fmt.Errorf("cannot find file %s", fileName)
|
return fmt.Errorf("cannot find file %s", fileName)
|
||||||
}
|
}
|
||||||
oldName := torMgr.GetPath(file)
|
oldName := torMgr.GetPath(file)
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ func ServeFilesList(directory, torrentName string, torMgr *torrent.TorrentManage
|
|||||||
sort.Strings(filenames)
|
sort.Strings(filenames)
|
||||||
for _, filename := range filenames {
|
for _, filename := range filenames {
|
||||||
file, _ := tor.SelectedFiles.Get(filename)
|
file, _ := tor.SelectedFiles.Get(filename)
|
||||||
if !file.State.Is("ok") {
|
if !file.State.Is("ok_file") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
|
if dirCfg.OnlyShowTheBiggestFile && file.Bytes < biggestFileSize {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import cmap "github.com/orcaman/concurrent-map/v2"
|
|||||||
func (t *TorrentManager) CheckDeletedStatus(torrent *Torrent) bool {
|
func (t *TorrentManager) CheckDeletedStatus(torrent *Torrent) bool {
|
||||||
var deletedIDs []int
|
var deletedIDs []int
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
if file.State.Is("deleted") {
|
if file.State.Is("deleted_file") {
|
||||||
deletedIDs = append(deletedIDs, file.ID)
|
deletedIDs = append(deletedIDs, file.ID)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ func (t *TorrentManager) UnrestrictLinkUntilOk(link string) *realdebrid.Download
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TorrentManager) UnrestrictFileUntilOk(file *File) *realdebrid.Download {
|
func (t *TorrentManager) UnrestrictFileUntilOk(file *File) *realdebrid.Download {
|
||||||
if !file.State.Is("ok") {
|
if !file.State.Is("ok_file") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return t.UnrestrictLinkUntilOk(file.Link)
|
return t.UnrestrictLinkUntilOk(file.Link)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package torrent
|
package torrent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -130,13 +131,11 @@ func (t *TorrentManager) refreshTorrents(isInitialRun bool) []string {
|
|||||||
if t.Config.EnableRepair() {
|
if t.Config.EnableRepair() {
|
||||||
if isInitialRun {
|
if isInitialRun {
|
||||||
t.removeExpiredFixers(instances)
|
t.removeExpiredFixers(instances)
|
||||||
t.processFixers(instances)
|
}
|
||||||
} else {
|
|
||||||
t.workerPool.Submit(func() {
|
t.workerPool.Submit(func() {
|
||||||
t.processFixers(instances)
|
t.processFixers(instances)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return updatedPaths
|
return updatedPaths
|
||||||
}
|
}
|
||||||
@@ -198,7 +197,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
|||||||
OriginalName: info.OriginalName,
|
OriginalName: info.OriginalName,
|
||||||
Added: info.Added,
|
Added: info.Added,
|
||||||
Hash: info.Hash,
|
Hash: info.Hash,
|
||||||
State: NewTorrentState("ok"),
|
State: NewTorrentState("broken_torrent"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectedFiles is a subset of Files with only the selected ones
|
// SelectedFiles is a subset of Files with only the selected ones
|
||||||
@@ -214,16 +213,23 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
|||||||
File: file,
|
File: file,
|
||||||
Ended: info.Ended,
|
Ended: info.Ended,
|
||||||
Link: "", // no link yet, consider it broken
|
Link: "", // no link yet, consider it broken
|
||||||
State: NewFileState("broken"),
|
State: NewFileState("broken_file"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if len(selectedFiles) == len(info.Links) {
|
if len(selectedFiles) == len(info.Links) {
|
||||||
// all links are still intact! good!
|
// all links are still intact! good!
|
||||||
for i, file := range selectedFiles {
|
for i, file := range selectedFiles {
|
||||||
file.Link = info.Links[i]
|
file.Link = info.Links[i]
|
||||||
file.State.SetState("ok")
|
err := file.State.Event(context.Background(), "repair_file")
|
||||||
|
if err != nil {
|
||||||
|
t.log.Warnf("Cannot repair file %s: %v", file.Path, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
torrent.UnassignedLinks = mapset.NewSet[string]()
|
torrent.UnassignedLinks = mapset.NewSet[string]()
|
||||||
|
err := torrent.State.Event(context.Background(), "repair_torrent")
|
||||||
|
if err != nil {
|
||||||
|
t.log.Warnf("Cannot repair torrent %s: %v", torrent.Hash, err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
torrent.UnassignedLinks = mapset.NewSet[string](info.Links...)
|
torrent.UnassignedLinks = mapset.NewSet[string](info.Links...)
|
||||||
}
|
}
|
||||||
@@ -315,9 +321,12 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) *Torrent {
|
|||||||
older.SelectedFiles.IterCb(func(key string, olderFile *File) {
|
older.SelectedFiles.IterCb(func(key string, olderFile *File) {
|
||||||
if !mainTorrent.SelectedFiles.Has(key) {
|
if !mainTorrent.SelectedFiles.Has(key) {
|
||||||
mainTorrent.SelectedFiles.Set(key, olderFile)
|
mainTorrent.SelectedFiles.Set(key, olderFile)
|
||||||
} else if olderFile.State.Is("deleted") {
|
} else if olderFile.State.Is("deleted_file") {
|
||||||
newerFile, _ := mainTorrent.SelectedFiles.Get(key)
|
newerFile, _ := mainTorrent.SelectedFiles.Get(key)
|
||||||
newerFile.State.SetState("deleted")
|
err := newerFile.State.Event(context.Background(), "delete_file")
|
||||||
|
if err != nil {
|
||||||
|
t.log.Warnf("Cannot delete file %s: %v", key, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.CheckDeletedStatus(&mainTorrent)
|
t.CheckDeletedStatus(&mainTorrent)
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ func (t *TorrentManager) repairAll(torrent *Torrent) {
|
|||||||
// check 1: for broken files
|
// check 1: for broken files
|
||||||
brokenFileIDs := mapset.NewSet[int]()
|
brokenFileIDs := mapset.NewSet[int]()
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
if file.State.Is("broken") {
|
if file.State.Is("broken_file") {
|
||||||
brokenFileIDs.Add(file.ID)
|
brokenFileIDs.Add(file.ID)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -257,7 +257,6 @@ func (t *TorrentManager) assignUnassignedLinks(torrent *Torrent) bool {
|
|||||||
unrestrict := t.UnrestrictLinkUntilOk(link)
|
unrestrict := t.UnrestrictLinkUntilOk(link)
|
||||||
if unrestrict == nil {
|
if unrestrict == nil {
|
||||||
expiredCount++
|
expiredCount++
|
||||||
// newUnassignedLinks.Set(link, nil)
|
|
||||||
return false // next
|
return false // next
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,9 +264,13 @@ func (t *TorrentManager) assignUnassignedLinks(torrent *Torrent) bool {
|
|||||||
assigned := false
|
assigned := false
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
// base it on size because why not?
|
// base it on size because why not?
|
||||||
if (unrestrict.Filesize > 1_000_000 && file.Bytes == unrestrict.Filesize) || strings.HasSuffix(strings.ToLower(file.Path), strings.ToLower(unrestrict.Filename)) {
|
if !assigned && file.State.Is("broken_file") && ((unrestrict.Filesize > 1_000_000 && file.Bytes == unrestrict.Filesize) || strings.HasSuffix(strings.ToLower(file.Path), strings.ToLower(unrestrict.Filename))) {
|
||||||
file.Link = link
|
file.Link = link
|
||||||
file.State.SetState("ok")
|
err := file.State.Event(context.Background(), "repair_done_file")
|
||||||
|
if err != nil {
|
||||||
|
t.log.Errorf("Failed to mark file %s as repaired: %v", file.Path, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
assigned = true
|
assigned = true
|
||||||
assignedCount++
|
assignedCount++
|
||||||
}
|
}
|
||||||
@@ -290,6 +293,10 @@ func (t *TorrentManager) assignUnassignedLinks(torrent *Torrent) bool {
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
t.log.Debugf("Assigned %d links to the %d selected files of torrent %s", assignedCount, torrent.SelectedFiles.Count(), t.GetKey(torrent))
|
||||||
|
t.log.Debugf("Expired %d links to the %d selected files of torrent %s", expiredCount, torrent.SelectedFiles.Count(), t.GetKey(torrent))
|
||||||
|
t.log.Debugf("Rar'ed %d links to the %d selected files of torrent %s", rarCount, torrent.SelectedFiles.Count(), t.GetKey(torrent))
|
||||||
|
t.log.Debugf("Unassigned %d links to the %d selected files of torrent %s", newUnassignedLinks.Count(), torrent.SelectedFiles.Count(), t.GetKey(torrent))
|
||||||
|
|
||||||
if assignedCount == 0 && rarCount == 1 {
|
if assignedCount == 0 && rarCount == 1 {
|
||||||
// this is a rar'ed torrent, nothing we can do
|
// this is a rar'ed torrent, nothing we can do
|
||||||
@@ -311,7 +318,7 @@ func (t *TorrentManager) assignUnassignedLinks(torrent *Torrent) bool {
|
|||||||
},
|
},
|
||||||
Ended: torrent.Added,
|
Ended: torrent.Added,
|
||||||
Link: unassigned.Link,
|
Link: unassigned.Link,
|
||||||
State: NewFileState("ok"),
|
State: NewFileState("ok_file"),
|
||||||
}
|
}
|
||||||
torrent.SelectedFiles.Set(unassigned.Filename, newFile)
|
torrent.SelectedFiles.Set(unassigned.Filename, newFile)
|
||||||
})
|
})
|
||||||
@@ -473,11 +480,11 @@ func (t *TorrentManager) canCapacityHandle() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TorrentManager) markAsUnplayable(torrent *Torrent, reason string) {
|
func (t *TorrentManager) markAsUnplayable(torrent *Torrent, reason string) {
|
||||||
if torrent.State.Is("unplayable") {
|
if torrent.State.Is("unplayable_torrent") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.log.Warnf("Marking torrent %s as unplayable - %s", t.GetKey(torrent), reason)
|
t.log.Warnf("Marking torrent %s as unplayable - %s", t.GetKey(torrent), reason)
|
||||||
err := torrent.State.Event(context.Background(), "mark_as_unplayable")
|
err := torrent.State.Event(context.Background(), "mark_as_unplayable_torrent")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.log.Errorf("Failed to mark torrent %s as unplayable: %v", t.GetKey(torrent), err)
|
t.log.Errorf("Failed to mark torrent %s as unplayable: %v", t.GetKey(torrent), err)
|
||||||
return
|
return
|
||||||
@@ -500,7 +507,7 @@ func getBrokenFiles(torrent *Torrent) ([]*File, bool) {
|
|||||||
var brokenFiles []*File
|
var brokenFiles []*File
|
||||||
allBroken := true
|
allBroken := true
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
if file.State.Is("broken") {
|
if file.State.Is("broken_file") {
|
||||||
brokenFiles = append(brokenFiles, file)
|
brokenFiles = append(brokenFiles, file)
|
||||||
} else {
|
} else {
|
||||||
allBroken = false
|
allBroken = false
|
||||||
@@ -520,18 +527,22 @@ func (t *TorrentManager) isStillBroken(info *realdebrid.TorrentInfo, brokenFiles
|
|||||||
selectedFiles = append(selectedFiles, &File{
|
selectedFiles = append(selectedFiles, &File{
|
||||||
File: file,
|
File: file,
|
||||||
Ended: info.Ended,
|
Ended: info.Ended,
|
||||||
Link: "", // no link yet
|
Link: "",
|
||||||
State: NewFileState("broken"),
|
State: NewFileState("broken_file"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if len(selectedFiles) == len(info.Links) {
|
if len(selectedFiles) == len(info.Links) {
|
||||||
// all links are still intact! good!
|
// all links are still intact! good!
|
||||||
for i, file := range selectedFiles {
|
for i, file := range selectedFiles {
|
||||||
file.Link = info.Links[i]
|
file.Link = info.Links[i]
|
||||||
file.State.SetState("ok")
|
err := file.State.Event(context.Background(), "repair_file")
|
||||||
|
if err != nil {
|
||||||
|
t.log.Errorf("Failed to mark file %s as repaired: %v", file.Path, err)
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if we can't assign links, it's still broken
|
// if we can't assign links then it's still broken
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,36 +5,30 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewTorrentState(initial string) *fsm.FSM {
|
func NewTorrentState(initial string) *fsm.FSM {
|
||||||
// ok
|
// ok_torrent 1
|
||||||
// broken
|
// broken_torrent 1
|
||||||
// under_repair
|
// unplayable_torrent 1
|
||||||
// deleted
|
|
||||||
// unplayable
|
|
||||||
return fsm.NewFSM(
|
return fsm.NewFSM(
|
||||||
initial,
|
initial,
|
||||||
fsm.Events{
|
fsm.Events{
|
||||||
{Name: "break", Src: []string{"ok", "unplayable"}, Dst: "broken"},
|
{Name: "break_torrent", Src: []string{"ok_torrent", "unplayable_torrent"}, Dst: "broken_torrent"},
|
||||||
{Name: "repair", Src: []string{"broken"}, Dst: "under_repair"},
|
{Name: "repair_torrent", Src: []string{"broken_torrent"}, Dst: "ok_torrent"},
|
||||||
{Name: "repair_done", Src: []string{"under_repair"}, Dst: "ok"},
|
{Name: "mark_as_unplayable_torrent", Src: []string{"ok_torrent"}, Dst: "unplayable_torrent"},
|
||||||
{Name: "delete", Src: []string{"ok", "broken", "under_repair", "unplayable"}, Dst: "deleted"},
|
|
||||||
{Name: "mark_as_unplayable", Src: []string{"ok", "under_repair"}, Dst: "unplayable"},
|
|
||||||
},
|
},
|
||||||
fsm.Callbacks{},
|
fsm.Callbacks{},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFileState(initial string) *fsm.FSM {
|
func NewFileState(initial string) *fsm.FSM {
|
||||||
// ok
|
// ok_file 13
|
||||||
// broken
|
// broken_file 5
|
||||||
// under_repair
|
// deleted_file 3
|
||||||
// deleted
|
|
||||||
return fsm.NewFSM(
|
return fsm.NewFSM(
|
||||||
initial,
|
initial,
|
||||||
fsm.Events{
|
fsm.Events{
|
||||||
{Name: "break", Src: []string{"ok"}, Dst: "broken"},
|
{Name: "break_file", Src: []string{"ok_file"}, Dst: "broken_file"},
|
||||||
{Name: "repair", Src: []string{"broken"}, Dst: "under_repair"},
|
{Name: "repair_file", Src: []string{"broken_file"}, Dst: "ok_file"},
|
||||||
{Name: "repair_done", Src: []string{"under_repair"}, Dst: "ok"},
|
{Name: "delete_file", Src: []string{"ok_file", "broken_file"}, Dst: "deleted_file"},
|
||||||
{Name: "delete", Src: []string{"ok", "broken", "under_repair"}, Dst: "deleted"},
|
|
||||||
},
|
},
|
||||||
fsm.Callbacks{},
|
fsm.Callbacks{},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func CheckFile(directory, torrentName, fileName string, w http.ResponseWriter, r
|
|||||||
}
|
}
|
||||||
|
|
||||||
file, ok := torrent.SelectedFiles.Get(fileName)
|
file, ok := torrent.SelectedFiles.Get(fileName)
|
||||||
if !ok || !file.State.Is("ok") {
|
if !ok || !file.State.Is("ok_file") {
|
||||||
log.Warnf("Cannot find file %s from path %s", fileName, req.URL.Path)
|
log.Warnf("Cannot find file %s from path %s", fileName, req.URL.Path)
|
||||||
http.Error(w, "File not found", http.StatusNotFound)
|
http.Error(w, "File not found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -50,20 +50,20 @@ func (dl *Downloader) DownloadFile(
|
|||||||
}
|
}
|
||||||
|
|
||||||
file, ok := torrent.SelectedFiles.Get(fileName)
|
file, ok := torrent.SelectedFiles.Get(fileName)
|
||||||
if !ok || !file.State.Is("ok") {
|
if !ok || !file.State.Is("ok_file") {
|
||||||
log.Warnf("Cannot find file %s from path %s", fileName, req.URL.Path)
|
log.Warnf("Cannot find file %s from path %s", fileName, req.URL.Path)
|
||||||
http.Error(resp, "File not found", http.StatusNotFound)
|
http.Error(resp, "File not found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !file.State.Is("ok") {
|
if !file.State.Is("ok_file") {
|
||||||
http.Error(resp, "File is not available", http.StatusNotFound)
|
http.Error(resp, "File is not available", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
unrestrict := torMgr.UnrestrictFileUntilOk(file)
|
unrestrict := torMgr.UnrestrictFileUntilOk(file)
|
||||||
if unrestrict == nil {
|
if unrestrict == nil {
|
||||||
err := file.State.Event(context.Background(), "break")
|
err := file.State.Event(context.Background(), "break_file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("File %s is stale: %v", fileName, err)
|
log.Errorf("File %s is stale: %v", fileName, err)
|
||||||
http.Error(resp, "File is stale, please try again", http.StatusLocked)
|
http.Error(resp, "File is stale, please try again", http.StatusLocked)
|
||||||
@@ -154,7 +154,7 @@ func (dl *Downloader) streamFileToResponse(
|
|||||||
downloadResp, err := dl.client.Do(dlReq)
|
downloadResp, err := dl.client.Do(dlReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if file != nil && unrestrict.Streamable == 1 {
|
if file != nil && unrestrict.Streamable == 1 {
|
||||||
err := file.State.Event(context.Background(), "break")
|
err := file.State.Event(context.Background(), "break_file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("File %s is stale: %v", file.Path, err)
|
log.Errorf("File %s is stale: %v", file.Path, err)
|
||||||
http.Error(resp, "File is stale, please try again", http.StatusLocked)
|
http.Error(resp, "File is stale, please try again", http.StatusLocked)
|
||||||
@@ -177,7 +177,7 @@ func (dl *Downloader) streamFileToResponse(
|
|||||||
// Check if the download was not successful
|
// Check if the download was not successful
|
||||||
if downloadResp.StatusCode/100 != 2 {
|
if downloadResp.StatusCode/100 != 2 {
|
||||||
if file != nil && unrestrict.Streamable == 1 {
|
if file != nil && unrestrict.Streamable == 1 {
|
||||||
err := file.State.Event(context.Background(), "break")
|
err := file.State.Event(context.Background(), "break_file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("File %s is stale: %v", file.Path, err)
|
log.Errorf("File %s is stale: %v", file.Path, err)
|
||||||
http.Error(resp, "File is stale, please try again", http.StatusLocked)
|
http.Error(resp, "File is stale, please try again", http.StatusLocked)
|
||||||
|
|||||||
Reference in New Issue
Block a user