Skip to content

Commit

Permalink
fix: check if arg is glob pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
ludviglundgren committed Aug 19, 2024
1 parent 393cd06 commit 01b46a1
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions cmd/torrent_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -154,14 +155,20 @@ func RunTorrentAdd() *cobra.Command {
return
} else {
var files []string
_, err := os.Lstat(filePath)
if err == nil {
files = []string{filePath}
} else {
var err error

if IsGlobPattern(filePath) {
files, err = filepath.Glob(filePath)
if err != nil {
log.Fatalf("could not find files matching: %s err: %q\n", filePath, err)
}
} else {
_, err := os.Lstat(filePath)
if err != nil {
log.Fatalf("could not stat file: %q\n", err)
}

files = []string{filePath}
}

if len(files) == 0 {
Expand Down Expand Up @@ -225,6 +232,16 @@ func RunTorrentAdd() *cobra.Command {
return command
}

// IsGlobPattern reports whether path contains any of the magic characters
// recognized by Match.
func IsGlobPattern(path string) bool {
magicChars := `*?[`
if runtime.GOOS != "windows" {
magicChars = `*?[\`
}
return strings.ContainsAny(path, magicChars)
}

func checkTrackerStatus(ctx context.Context, qb *qbittorrent.Client, removeStalled bool, hash string) error {
announceOK := false
attempts := 0
Expand Down

0 comments on commit 01b46a1

Please sign in to comment.