From: Matt Joiner Date: Thu, 26 Feb 2015 11:17:58 +0000 (+1100) Subject: Ditch the intermediate MetaInfo type X-Git-Tag: v1.0.0~1310 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=22746dda232f546e8c230a3b335d06d857d46788;p=btrtrc.git Ditch the intermediate MetaInfo type --- diff --git a/fs/torrentfs.go b/fs/torrentfs.go index 0f448b38..f17931e9 100644 --- a/fs/torrentfs.go +++ b/fs/torrentfs.go @@ -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 index f1434020..00000000 --- a/metainfo.go +++ /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 -} diff --git a/torrent.go b/torrent.go index 6b2bb053..1a068f08 100644 --- a/torrent.go +++ b/torrent.go @@ -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(),