From 20a70d7f9109bc085c60a924ea94eaedd306f801 Mon Sep 17 00:00:00 2001 From: Levi Date: Mon, 29 Sep 2025 22:52:06 +0800 Subject: [PATCH] fix: certain special single-file torrent downloads (#1136) --- internal/protocol/bt/fetcher_test.go | 11 ++++++----- internal/protocol/bt/file.go | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/protocol/bt/fetcher_test.go b/internal/protocol/bt/fetcher_test.go index 9e09856d..5975681f 100644 --- a/internal/protocol/bt/fetcher_test.go +++ b/internal/protocol/bt/fetcher_test.go @@ -3,17 +3,18 @@ package bt import ( "encoding/base64" "encoding/json" - "github.com/GopeedLab/gopeed/internal/controller" - "github.com/GopeedLab/gopeed/internal/fetcher" - "github.com/GopeedLab/gopeed/internal/test" - "github.com/GopeedLab/gopeed/pkg/base" - "github.com/GopeedLab/gopeed/pkg/protocol/bt" gohttp "net/http" "net/url" "os" "path/filepath" "reflect" "testing" + + "github.com/GopeedLab/gopeed/internal/controller" + "github.com/GopeedLab/gopeed/internal/fetcher" + "github.com/GopeedLab/gopeed/internal/test" + "github.com/GopeedLab/gopeed/pkg/base" + "github.com/GopeedLab/gopeed/pkg/protocol/bt" ) func TestFetcher_Resolve_Torrent(t *testing.T) { diff --git a/internal/protocol/bt/file.go b/internal/protocol/bt/file.go index 5b2a1e26..8d63864c 100644 --- a/internal/protocol/bt/file.go +++ b/internal/protocol/bt/file.go @@ -5,11 +5,12 @@ package bt import ( "context" "fmt" - "github.com/anacrolix/torrent/storage" "io" "os" "path/filepath" + "github.com/anacrolix/torrent/storage" + "github.com/anacrolix/missinggo/v2" "github.com/anacrolix/torrent/common" @@ -34,7 +35,7 @@ func newFileOpts(opts newFileClientOpts) storage.ClientImplCloser { if opts.FilePathMaker == nil { opts.FilePathMaker = func(opts storage.FilePathMakerOpts) string { var parts []string - if opts.Info.Length == 0 { + if opts.Info.Length == 0 || opts.File.Path == nil { parts = append(parts, opts.Info.Name) } return filepath.Join(append(parts, opts.File.Path...)...)