]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add BEP 47 extended file attributes fields
authorMatt Joiner <anacrolix@gmail.com>
Sun, 25 Feb 2024 22:28:58 +0000 (09:28 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 28 Feb 2024 05:30:24 +0000 (16:30 +1100)
metainfo/bep47.go [new file with mode: 0644]
metainfo/fileinfo.go
metainfo/info.go

diff --git a/metainfo/bep47.go b/metainfo/bep47.go
new file mode 100644 (file)
index 0000000..884d88d
--- /dev/null
@@ -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"`
+}
index 2a5ea01d1f88d476d80a9622b4fb6d601243bbd9..894018c10815a32a74be61291a48d05fea0c07e7 100644 (file)
@@ -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 {
index 5eedfa3b4c41730ddb92543abfb855ad635e27e4..b5e4d6e179595574c143778469d245b2b2438805 100644 (file)
@@ -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