]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Ditch the intermediate MetaInfo type
authorMatt Joiner <anacrolix@gmail.com>
Thu, 26 Feb 2015 11:17:58 +0000 (22:17 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 26 Feb 2015 11:17:58 +0000 (22:17 +1100)
fs/torrentfs.go
metainfo.go [deleted file]
torrent.go

index 0f448b381df20148dbdebd067ce9b2131a098be2..f17931e9990578f0ee5868ad44558348f4f13f81 100644 (file)
@@ -9,6 +9,7 @@ import (
        "sync"
        "time"
 
+       "github.com/anacrolix/libtorgo/metainfo"
        "golang.org/x/net/context"
 
        "bazil.org/fuse"
@@ -55,7 +56,7 @@ type rootNode struct {
 
 type node struct {
        path     []string
-       metadata *torrent.MetaInfo
+       metadata *metainfo.Info
        FS       *TorrentFS
        t        torrent.Torrent
 }
@@ -246,7 +247,7 @@ func (me rootNode) Lookup(ctx context.Context, name string) (_node fusefs.Node,
                        FS:       me.fs,
                        t:        t,
                }
-               if t.Info.SingleFile() {
+               if !t.Info.IsDir() {
                        _node = fileNode{__node, uint64(t.Info.Length), 0}
                } else {
                        _node = dirNode{__node}
@@ -267,7 +268,7 @@ func (me rootNode) ReadDir(ctx context.Context) (dirents []fuse.Dirent, err erro
                dirents = append(dirents, fuse.Dirent{
                        Name: t.Info.Name,
                        Type: func() fuse.DirentType {
-                               if t.Info.SingleFile() {
+                               if !t.Info.IsDir() {
                                        return fuse.DT_File
                                } else {
                                        return fuse.DT_Dir
diff --git a/metainfo.go b/metainfo.go
deleted file mode 100644 (file)
index f143402..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-package torrent
-
-import "github.com/anacrolix/libtorgo/metainfo"
-
-// A wrapper around the raw info that provides some helper methods.
-type MetaInfo struct {
-       *metainfo.Info
-}
-
-func newMetaInfo(info *metainfo.Info) *MetaInfo {
-       return &MetaInfo{
-               Info: info,
-       }
-}
-
-func (me *MetaInfo) SingleFile() bool {
-       return len(me.Info.Files) == 0
-}
index 6b2bb053a5a55533f2d89b6ce970dfd724014ea1..1a068f08c0f31307117f5ec169b4094ebd73b07a 100644 (file)
@@ -60,7 +60,7 @@ type torrent struct {
 
        data TorrentData
 
-       Info *MetaInfo
+       Info *metainfo.Info
        // Active peer connections.
        Conns []*connection
        // Set of addrs to which we're attempting to connect.
@@ -183,7 +183,7 @@ func infoPieceHashes(info *metainfo.Info) (ret []string) {
 
 // Called when metadata for a torrent becomes available.
 func (t *torrent) setMetadata(md metainfo.Info, infoBytes []byte, eventLocker sync.Locker) (err error) {
-       t.Info = newMetaInfo(&md)
+       t.Info = &md
        t.length = 0
        for _, f := range t.Info.UpvertedFiles() {
                t.length += f.Length
@@ -411,7 +411,7 @@ func (t *torrent) MetaInfo() *metainfo.MetaInfo {
        }
        return &metainfo.MetaInfo{
                Info: metainfo.InfoEx{
-                       Info:  *t.Info.Info,
+                       Info:  *t.Info,
                        Bytes: t.MetaData,
                },
                CreationDate: time.Now().Unix(),