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

@@ -35,6 +35,29 @@ jobs:
- name: Cross-compile with xgo - name: Cross-compile with xgo
uses: crazy-max/ghaction-xgo@v3 uses: crazy-max/ghaction-xgo@v3
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
with:
xgo_version: latest
go_version: 1.21
pkg: cmd/zurg
targets: linux/amd64
dest: artifacts
prefix: zurg
v: false
x: false
race: false
ldflags: >
-s -w
-X 'github.com/debridmediamanager/zurg/internal.BuiltAt=${{ steps.prep.outputs.built_at }}'
-X 'github.com/debridmediamanager/zurg/internal.GoVersion=${{ steps.prep.outputs.go_version }}'
-X 'github.com/debridmediamanager/zurg/internal.GitCommit=${{ steps.prep.outputs.git_commit }}'
-X 'github.com/debridmediamanager/zurg/internal.Version=${{ steps.version.outputs.version }}'
buildmode: default
trimpath: true
- name: Cross-compile with xgo
uses: crazy-max/ghaction-xgo@v3
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
with: with:
xgo_version: latest xgo_version: latest
go_version: 1.21 go_version: 1.21

View File

@@ -56,7 +56,7 @@ jobs:
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
with: with:
context: . context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7 platforms: linux/amd64
push: true push: true
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}

View File

@@ -38,13 +38,13 @@ func (t *TorrentManager) Repair(torrent *Torrent) {
t.log.Infof("Repairing torrent %s", torrent.AccessKey) t.log.Infof("Repairing torrent %s", torrent.AccessKey)
t.repair(torrent) t.repair(torrent)
t.log.Infof("Finished repairing torrent %s", torrent.AccessKey) t.log.Infof("Finished repairing torrent %s", torrent.AccessKey)
})
var updatedPaths []string var updatedPaths []string
t.assignedDirectoryCb(torrent, func(directory string) { t.assignedDirectoryCb(torrent, func(directory string) {
updatedPaths = append(updatedPaths, fmt.Sprintf("%s/%s", directory, torrent.AccessKey)) updatedPaths = append(updatedPaths, fmt.Sprintf("%s/%s", directory, torrent.AccessKey))
}) })
t.TriggerHookOnLibraryUpdate(updatedPaths) t.TriggerHookOnLibraryUpdate(updatedPaths)
})
} }
func (t *TorrentManager) repair(torrent *Torrent) { func (t *TorrentManager) repair(torrent *Torrent) {

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) log.Debugf("Opening file %s from torrent %s (%s)", fileName, torrentName, link)
unrestrict := torMgr.UnrestrictUntilOk(link) unrestrict := torMgr.UnrestrictUntilOk(link)
if unrestrict == nil { if unrestrict == nil {
// log.Warnf("File %s is no longer available, link %s", filepath.Base(file.Path), link) log.Warnf("File %s cannot be unrestricted (link=%s)", fileName, link)
if cfg.EnableRepair() {
file.Link = "repairing" file.Link = "repairing"
torMgr.Repair(torrent) torMgr.Repair(torrent)
} else {
log.Info("Repair is disabled, skipping repair for unavailable file")
}
http.Error(resp, "File is not available", http.StatusNotFound) http.Error(resp, "File is not available", http.StatusNotFound)
return return
} else { } else {
@@ -150,8 +154,12 @@ func (gf *GetFile) streamFileToResponse(torrent *intTor.Torrent, file *intTor.Fi
if err != nil { if err != nil {
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() {
file.Link = "repairing" file.Link = "repairing"
torMgr.Repair(torrent) torMgr.Repair(torrent)
} else {
log.Info("Repair is disabled, skipping repair for unavailable file")
}
} }
http.Error(resp, "File is not available", http.StatusNotFound) http.Error(resp, "File is not available", http.StatusNotFound)
return 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 download.StatusCode != http.StatusOK && download.StatusCode != http.StatusPartialContent {
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() {
file.Link = "repairing" file.Link = "repairing"
torMgr.Repair(torrent) torMgr.Repair(torrent)
} else {
log.Info("Repair is disabled, skipping repair for unavailable file")
}
} }
http.Error(resp, "File is not available", http.StatusNotFound) http.Error(resp, "File is not available", http.StatusNotFound)
return return