Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(torrent): add helper to detect missing files #11

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ The following helper functions are available for usage while filtering, usage ex
IsUnregistered() bool // Evaluates to true if torrent is unregistered in the tracker
HasAllTags(tags ...string) bool // True if torrent has ALL tags specified
HasAnyTag(tags ...string) bool // True if torrent has at least one tag specified
HasMissingFiles() bool // True if any of the torrent's files are missing from disk
Log(n float64) float64 // The natural logarithm function
```

Expand Down
27 changes: 27 additions & 0 deletions config/torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package config

import (
"math"
"os"
"strings"

"github.com/autobrr/tqm/logger"
"github.com/autobrr/tqm/regex"
"github.com/autobrr/tqm/sliceutils"
"github.com/autobrr/tqm/tracker"
Expand Down Expand Up @@ -142,6 +144,31 @@ func (t *Torrent) HasAnyTag(tags ...string) bool {
return false
}

func (t *Torrent) HasMissingFiles() bool {
if !t.Downloaded {
return false
}

log := logger.GetLogger("torrent")

for _, f := range t.Files {
if f == "" {
log.Tracef("Skipping empty path for torrent: %s", t.Name)
continue
}

if _, err := os.Stat(f); err != nil {
if os.IsNotExist(err) {
return true
}
log.Warnf("error checking file '%s' for torrent '%s': %v", f, t.Name, err)
continue
}
}

return false
}

func (t *Torrent) Log(n float64) float64 {
return math.Log(n)
}
Expand Down
2 changes: 1 addition & 1 deletion logger/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

var (
prefixLen = 14
prefixLen = 15
loggingFilePath string
)

Expand Down
Loading