]> Sergey Matveev's repositories - btrtrc.git/blobdiff - metainfo/fileinfo.go
Drop support for go 1.20
[btrtrc.git] / metainfo / fileinfo.go
index 4b72d12d81edbae8879edd1ac9794b6e1b0ed0b2..2a5ea01d1f88d476d80a9622b4fb6d601243bbd9 100644 (file)
@@ -4,15 +4,16 @@ import "strings"
 
 // Information specific to a single file inside the MetaInfo structure.
 type FileInfo struct {
-       Length int64    `bencode:"length"`
-       Path   []string `bencode:"path"`
+       Length   int64    `bencode:"length"` // BEP3
+       Path     []string `bencode:"path"`   // BEP3
+       PathUtf8 []string `bencode:"path.utf-8,omitempty"`
 }
 
 func (fi *FileInfo) DisplayPath(info *Info) string {
        if info.IsDir() {
-               return strings.Join(fi.Path, "/")
+               return strings.Join(fi.BestPath(), "/")
        } else {
-               return info.Name
+               return info.BestName()
        }
 }
 
@@ -25,3 +26,10 @@ func (me FileInfo) Offset(info *Info) (ret int64) {
        }
        panic("not found")
 }
+
+func (fi FileInfo) BestPath() []string {
+       if len(fi.PathUtf8) != 0 {
+               return fi.PathUtf8
+       }
+       return fi.Path
+}