From 48ad2bc3bf06af5d17189e30479cfa08b153202f Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Tue, 21 Nov 2023 14:16:53 +0100 Subject: [PATCH] Delete if everything is unselected --- .github/workflows/build.yml | 16 +++++++++++----- internal/dav/delete.go | 3 ++- internal/net/router.go | 2 +- internal/torrent/manager.go | 21 ++++++++++++++++----- internal/torrent/types.go | 7 +++---- internal/universal/get.go | 9 +++------ 6 files changed, 36 insertions(+), 22 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4ea1fc3..cd46616 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,13 +26,18 @@ jobs: - name: Prepare artifacts run: | mkdir artifacts - mv zurg-* artifacts/ + mv github.com/debridmediamanager.com/zurg/cmd/zurg-* artifacts/ + + # New step for compressing artifacts + - name: Compress artifacts + run: | + tar -czvf artifacts.tar.gz -C artifacts . - name: Upload artifacts to workflow uses: actions/upload-artifact@v3 with: name: compiled-binaries - path: artifacts/ + path: artifacts.tar.gz release: needs: build @@ -54,12 +59,13 @@ jobs: draft: false prerelease: false + # Ensure the asset_path matches the compressed file name - name: Upload binaries to release uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./zurg-* - asset_name: zurg-${{ github.run_number }}-${{ github.sha }} - asset_content_type: application/octet-stream + asset_path: ./artifacts.tar.gz + asset_name: zurg-${{ github.run_number }}-${{ github.sha }}.tar.gz + asset_content_type: application/gzip diff --git a/internal/dav/delete.go b/internal/dav/delete.go index c3efa6e..c3c31c8 100644 --- a/internal/dav/delete.go +++ b/internal/dav/delete.go @@ -82,7 +82,8 @@ func handleDeleteFile(w http.ResponseWriter, segments []string, t *torrent.Torre return fmt.Errorf("cannot find file %s", filepath) } - file.Link = "-" + file.Link = "unselect" + t.SetChecksum("") w.WriteHeader(http.StatusNoContent) return nil } diff --git a/internal/net/router.go b/internal/net/router.go index 1868800..a663303 100644 --- a/internal/net/router.go +++ b/internal/net/router.go @@ -43,7 +43,7 @@ func Router(mux *http.ServeMux, c config.ConfigInterface, t *torrent.TorrentMana case "PROPFIND": dav.HandlePropfindRequest(w, r, t, davlog) - case "DELETE": + case http.MethodDelete: dav.HandleDeleteRequest(w, r, t, davlog) case http.MethodGet: diff --git a/internal/torrent/manager.go b/internal/torrent/manager.go index 773bbff..28a9220 100644 --- a/internal/torrent/manager.go +++ b/internal/torrent/manager.go @@ -535,16 +535,24 @@ func (t *TorrentManager) repairAll() { return } forRepair := false + unselected := 0 torrent.SelectedFiles.IterCb(func(_ string, file *File) { - if file.Link == "@" || file.ForRepair { + if file.Link == "repair" { t.log.Debugf("Found a file to repair for torrent %s", torrent.AccessKey) forRepair = true } + if file.Link == "unselect" { + unselected++ + } }) if forRepair { t.log.Infof("Repairing %s", torrent.AccessKey) t.Repair(torrent.AccessKey) } + if unselected == torrent.SelectedFiles.Count() && unselected > 0 { + t.log.Infof("Deleting %s", torrent.AccessKey) + t.Delete(torrent.AccessKey) + } }) } @@ -756,14 +764,17 @@ func (t *TorrentManager) canCapacityHandle() bool { return true } - if retryCount >= maxRetries { - t.log.Error("Max retries reached, exiting") - return false - } delay := time.Duration(math.Pow(2, float64(retryCount))) * baseDelay if delay > maxDelay { delay = maxDelay } + t.log.Infof("We have reached the max number of active torrents, waiting for %s seconds before retrying", delay) + + if retryCount >= maxRetries { + t.log.Error("Max retries reached, exiting") + return false + } + time.Sleep(delay) retryCount++ } diff --git a/internal/torrent/types.go b/internal/torrent/types.go index 08ec225..1ed2045 100644 --- a/internal/torrent/types.go +++ b/internal/torrent/types.go @@ -24,8 +24,7 @@ func (t *Torrent) InProgress() bool { type File struct { realdebrid.File - Added string - Link string - ZurgFS uint64 - ForRepair bool + Added string + Link string + ZurgFS uint64 } diff --git a/internal/universal/get.go b/internal/universal/get.go index 7d8a3ad..e3ba402 100644 --- a/internal/universal/get.go +++ b/internal/universal/get.go @@ -81,8 +81,7 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *intTor.TorrentM resp := t.UnrestrictUntilOk(link) if resp == nil { log.Warnf("File %s is no longer available", file.Path) - file.Link = "@" - file.ForRepair = true + file.Link = "repair" t.SetChecksum("") // force a recheck streamErrorVideo("https://www.youtube.com/watch?v=gea_FJrtFVA", w, r, t, c, log) } else { @@ -127,8 +126,7 @@ func streamFileToResponse(file *intTor.File, url string, w http.ResponseWriter, if err != nil { if file != nil { log.Warnf("Cannot download file %s: %v", file.Path, err) - file.Link = "@" - file.ForRepair = true + file.Link = "repair" torMgr.SetChecksum("") // force a recheck } streamErrorVideo("https://www.youtube.com/watch?v=FSSd8cponAA", w, r, torMgr, cfg, log) @@ -139,8 +137,7 @@ func streamFileToResponse(file *intTor.File, url string, w http.ResponseWriter, if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent { if file != nil { log.Warnf("Received a %s status code for file %s", resp.Status, file.Path) - file.Link = "@" - file.ForRepair = true + file.Link = "repair" torMgr.SetChecksum("") // force a recheck } streamErrorVideo("https://www.youtube.com/watch?v=BcseUxviVqE", w, r, torMgr, cfg, log)