Ditch the intermediate MetaInfo type

This commit is contained in:
Matt Joiner 2015-02-26 22:17:58 +11:00
parent fd5c0798e3
commit 22746dda23
3 changed files with 7 additions and 24 deletions

View 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

View File

@ -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
}

View 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(),