From: Matt Joiner Date: Mon, 19 May 2025 04:50:28 +0000 (+1000) Subject: Improve metainfo pprinting since BT v2 support X-Git-Tag: v1.59.0~135 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=09d8fe7a4113da13ef813ec520582bd61f11f427;p=btrtrc.git Improve metainfo pprinting since BT v2 support --- diff --git a/file.go b/file.go index 26c38123..e3739724 100644 --- a/file.go +++ b/file.go @@ -1,13 +1,12 @@ package torrent import ( - "crypto/sha256" - "github.com/RoaringBitmap/roaring" g "github.com/anacrolix/generics" "github.com/anacrolix/missinggo/v2/bitmap" "github.com/anacrolix/torrent/metainfo" + infohash_v2 "github.com/anacrolix/torrent/types/infohash-v2" ) // Provides access to regions of torrent data that correspond to its files. @@ -19,7 +18,7 @@ type File struct { fi metainfo.FileInfo displayPath string prio PiecePriority - piecesRoot g.Option[[sha256.Size]byte] + piecesRoot g.Option[infohash_v2.T] } func (f *File) String() string { diff --git a/iter.go b/iter.go new file mode 100644 index 00000000..10cbafc7 --- /dev/null +++ b/iter.go @@ -0,0 +1 @@ +package torrent diff --git a/metainfo/bep47.go b/metainfo/bep47.go index 884d88d6..e8f04c8c 100644 --- a/metainfo/bep47.go +++ b/metainfo/bep47.go @@ -2,7 +2,7 @@ package metainfo // See BEP 47. This is common to both Info and FileInfo. type ExtendedFileAttrs struct { - Attr string `bencode:"attr,omitempty"` - SymlinkPath []string `bencode:"symlink path,omitempty"` - Sha1 string `bencode:"sha1,omitempty"` + Attr string `bencode:"attr,omitempty" json:"attr,omitempty"` + SymlinkPath []string `bencode:"symlink path,omitempty" json:"symlink path,omitempty"` + Sha1 string `bencode:"sha1,omitempty" json:"sha1,omitempty"` } diff --git a/metainfo/file-tree.go b/metainfo/file-tree.go index 08039e6d..27c87d2c 100644 --- a/metainfo/file-tree.go +++ b/metainfo/file-tree.go @@ -8,6 +8,7 @@ import ( g "github.com/anacrolix/generics" "github.com/anacrolix/torrent/bencode" + infohash_v2 "github.com/anacrolix/torrent/types/infohash-v2" ) const FileTreePropertiesKey = "" @@ -144,7 +145,7 @@ func (ft *FileTree) Walk(path []string, f func(path []string, ft *FileTree)) { } } -func (ft *FileTree) PiecesRootAsByteArray() (ret g.Option[[32]byte]) { +func (ft *FileTree) PiecesRootAsByteArray() (ret g.Option[infohash_v2.T]) { if ft.File.PiecesRoot == "" { return } diff --git a/metainfo/fileinfo.go b/metainfo/fileinfo.go index 867a56d0..9b501fde 100644 --- a/metainfo/fileinfo.go +++ b/metainfo/fileinfo.go @@ -4,6 +4,8 @@ import ( "strings" g "github.com/anacrolix/generics" + + infohash_v2 "github.com/anacrolix/torrent/types/infohash-v2" ) // Information specific to a single file inside the MetaInfo structure. @@ -14,14 +16,14 @@ type FileInfo struct { Path []string `bencode:"path"` // BEP3 // Unofficial extension by BiglyBT? https://github.com/BiglySoftware/BiglyBT/issues/1274. Might // be a safer bet when available: https://github.com/anacrolix/torrent/pull/915. - PathUtf8 []string `bencode:"path.utf-8,omitempty"` + PathUtf8 []string `bencode:"path.utf-8,omitempty" json:"path.utf-8,omitempty"` - ExtendedFileAttrs + ExtendedFileAttrs `json:",omitempty"` // BEP 52. This isn't encoded in a v1 FileInfo, but is exposed here for APIs that expect to deal // v1 files. - PiecesRoot g.Option[[32]byte] `bencode:"-"` - TorrentOffset int64 `bencode:"-"` + PiecesRoot g.Option[infohash_v2.T] `bencode:"-" json:"-"` + TorrentOffset int64 `bencode:"-" json:"-"` } func (fi *FileInfo) DisplayPath(info *Info) string {