From 7f18ac8f1663c6101c57c9316acaca49c5363261 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 26 Feb 2024 09:28:58 +1100 Subject: [PATCH] Add BEP 47 extended file attributes fields --- metainfo/bep47.go | 8 ++++++++ metainfo/fileinfo.go | 8 ++++++-- metainfo/info.go | 5 +++-- 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 metainfo/bep47.go diff --git a/metainfo/bep47.go b/metainfo/bep47.go new file mode 100644 index 00000000..884d88d6 --- /dev/null +++ b/metainfo/bep47.go @@ -0,0 +1,8 @@ +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"` +} diff --git a/metainfo/fileinfo.go b/metainfo/fileinfo.go index 2a5ea01d..894018c1 100644 --- a/metainfo/fileinfo.go +++ b/metainfo/fileinfo.go @@ -4,9 +4,13 @@ import "strings" // Information specific to a single file inside the MetaInfo structure. type FileInfo struct { - Length int64 `bencode:"length"` // BEP3 - Path []string `bencode:"path"` // BEP3 + // BEP3. With BEP 47 this can be optional, but we have no way to describe that without breaking + // the API. + Length int64 `bencode:"length"` + Path []string `bencode:"path"` // BEP3 PathUtf8 []string `bencode:"path.utf-8,omitempty"` + + ExtendedFileAttrs } func (fi *FileInfo) DisplayPath(info *Info) string { diff --git a/metainfo/info.go b/metainfo/info.go index 5eedfa3b..b5e4d6e1 100644 --- a/metainfo/info.go +++ b/metainfo/info.go @@ -17,8 +17,9 @@ type Info struct { Pieces []byte `bencode:"pieces"` // BEP3 Name string `bencode:"name"` // BEP3 NameUtf8 string `bencode:"name.utf-8,omitempty"` - Length int64 `bencode:"length,omitempty"` // BEP3, mutually exclusive with Files - Private *bool `bencode:"private,omitempty"` // BEP27 + Length int64 `bencode:"length,omitempty"` // BEP3, mutually exclusive with Files + ExtendedFileAttrs + Private *bool `bencode:"private,omitempty"` // BEP27 // TODO: Document this field. Source string `bencode:"source,omitempty"` Files []FileInfo `bencode:"files,omitempty"` // BEP3, mutually exclusive with Length -- 2.48.1