@cryptotaxi247 / kubo / commits / 75a860ca2

refactor(unixfs) move proto to pb package

not internal since io needs it fix(fuse/ipns) use pb package fix(fuse) import protos from unixfs/pb package

Brian Tiger Chow committed Oct 22, 2014 at 04:57 UTC 75a860ca2bf7b38f6de3c8fe7e5d0f78781d222a
9 files changed +43 -38
fuse/ipns/ipns_unix.go
+5 -4
@@ -17,6 +17,7 @@ import (
17 mdag "github.com/jbenet/go-ipfs/merkledag"
18 ft "github.com/jbenet/go-ipfs/unixfs"
19 uio "github.com/jbenet/go-ipfs/unixfs/io"
20 + ftpb "github.com/jbenet/go-ipfs/unixfs/pb"
21 u "github.com/jbenet/go-ipfs/util"
22 )
23
@@ -206,11 +207,11 @@ type Node struct {
207 Ipfs *core.IpfsNode
208 Nd *mdag.Node
209 dagMod *uio.DagModifier
209 - cached *ft.PBData
210 + cached *ftpb.PBData
211 }
212
213 func (s *Node) loadData() error {
213 - s.cached = new(ft.PBData)
214 + s.cached = new(ftpb.PBData)
215 return proto.Unmarshal(s.Nd.Data, s.cached)
216 }
217
@@ -223,9 +224,9 @@ func (s *Node) Attr() fuse.Attr {
224 }
225 }
226 switch s.cached.GetType() {
226 - case ft.PBData_Directory:
227 + case ftpb.PBData_Directory:
228 return fuse.Attr{Mode: os.ModeDir | 0555}
228 - case ft.PBData_File, ft.PBData_Raw:
229 + case ftpb.PBData_File, ftpb.PBData_Raw:
230 size, err := ft.DataSize(s.Nd.Data)
231 if err != nil {
232 log.Error("Error getting size of file: %s", err)
fuse/readonly/readonly_unix.go
+5 -5
@@ -20,8 +20,8 @@ import (
20
21 core "github.com/jbenet/go-ipfs/core"
22 mdag "github.com/jbenet/go-ipfs/merkledag"
23 - ft "github.com/jbenet/go-ipfs/unixfs"
23 uio "github.com/jbenet/go-ipfs/unixfs/io"
24 + ftpb "github.com/jbenet/go-ipfs/unixfs/pb"
25 u "github.com/jbenet/go-ipfs/util"
26 )
27
@@ -81,11 +81,11 @@ type Node struct {
81 Ipfs *core.IpfsNode
82 Nd *mdag.Node
83 fd *uio.DagReader
84 - cached *ft.PBData
84 + cached *ftpb.PBData
85 }
86
87 func (s *Node) loadData() error {
88 - s.cached = new(ft.PBData)
88 + s.cached = new(ftpb.PBData)
89 return proto.Unmarshal(s.Nd.Data, s.cached)
90 }
91
@@ -96,9 +96,9 @@ func (s *Node) Attr() fuse.Attr {
96 s.loadData()
97 }
98 switch s.cached.GetType() {
99 - case ft.PBData_Directory:
99 + case ftpb.PBData_Directory:
100 return fuse.Attr{Mode: os.ModeDir | 0555}
101 - case ft.PBData_File, ft.PBData_Raw:
101 + case ftpb.PBData_File, ftpb.PBData_Raw:
102 size, _ := s.Nd.Size()
103 return fuse.Attr{
104 Mode: 0444,
unixfs/format.go
+17 -16
@@ -5,15 +5,16 @@ package unixfs
5 import (
6 "errors"
7
8 - "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
8 + proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
9 + pb "github.com/jbenet/go-ipfs/unixfs/pb"
10 )
11
12 var ErrMalformedFileFormat = errors.New("malformed data in file format")
13 var ErrInvalidDirLocation = errors.New("found directory node in unexpected place")
14 var ErrUnrecognizedType = errors.New("unrecognized node type")
15
15 -func FromBytes(data []byte) (*PBData, error) {
16 - pbdata := new(PBData)
16 +func FromBytes(data []byte) (*pb.PBData, error) {
17 + pbdata := new(pb.PBData)
18 err := proto.Unmarshal(data, pbdata)
19 if err != nil {
20 return nil, err
@@ -22,8 +23,8 @@ func FromBytes(data []byte) (*PBData, error) {
23 }
24
25 func FilePBData(data []byte, totalsize uint64) []byte {
25 - pbfile := new(PBData)
26 - typ := PBData_File
26 + pbfile := new(pb.PBData)
27 + typ := pb.PBData_File
28 pbfile.Type = &typ
29 pbfile.Data = data
30 pbfile.Filesize = proto.Uint64(totalsize)
@@ -42,8 +43,8 @@ func FilePBData(data []byte, totalsize uint64) []byte {
43
44 // Returns Bytes that represent a Directory
45 func FolderPBData() []byte {
45 - pbfile := new(PBData)
46 - typ := PBData_Directory
46 + pbfile := new(pb.PBData)
47 + typ := pb.PBData_Directory
48 pbfile.Type = &typ
49
50 data, err := proto.Marshal(pbfile)
@@ -55,8 +56,8 @@ func FolderPBData() []byte {
56 }
57
58 func WrapData(b []byte) []byte {
58 - pbdata := new(PBData)
59 - typ := PBData_Raw
59 + pbdata := new(pb.PBData)
60 + typ := pb.PBData_Raw
61 pbdata.Data = b
62 pbdata.Type = &typ
63
@@ -70,7 +71,7 @@ func WrapData(b []byte) []byte {
71 }
72
73 func UnwrapData(data []byte) ([]byte, error) {
73 - pbdata := new(PBData)
74 + pbdata := new(pb.PBData)
75 err := proto.Unmarshal(data, pbdata)
76 if err != nil {
77 return nil, err
@@ -79,18 +80,18 @@ func UnwrapData(data []byte) ([]byte, error) {
80 }
81
82 func DataSize(data []byte) (uint64, error) {
82 - pbdata := new(PBData)
83 + pbdata := new(pb.PBData)
84 err := proto.Unmarshal(data, pbdata)
85 if err != nil {
86 return 0, err
87 }
88
89 switch pbdata.GetType() {
89 - case PBData_Directory:
90 + case pb.PBData_Directory:
91 return 0, errors.New("Cant get data size of directory!")
91 - case PBData_File:
92 + case pb.PBData_File:
93 return pbdata.GetFilesize(), nil
93 - case PBData_Raw:
94 + case pb.PBData_Raw:
95 return uint64(len(pbdata.GetData())), nil
96 default:
97 return 0, errors.New("Unrecognized node data type!")
@@ -109,8 +110,8 @@ func (mb *MultiBlock) AddBlockSize(s uint64) {
110 }
111
112 func (mb *MultiBlock) GetBytes() ([]byte, error) {
112 - pbn := new(PBData)
113 - t := PBData_File
113 + pbn := new(pb.PBData)
114 + t := pb.PBData_File
115 pbn.Type = &t
116 pbn.Filesize = proto.Uint64(uint64(len(mb.Data)) + mb.subtotal)
117 pbn.Blocksizes = mb.blocksizes
unixfs/format_test.go
+3 -2
@@ -3,7 +3,8 @@ package unixfs
3 import (
4 "testing"
5
6 - "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
6 + proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
7 + pb "github.com/jbenet/go-ipfs/unixfs/pb"
8 )
9
10 func TestMultiBlock(t *testing.T) {
@@ -19,7 +20,7 @@ func TestMultiBlock(t *testing.T) {
20 t.Fatal(err)
21 }
22
22 - pbn := new(PBData)
23 + pbn := new(pb.PBData)
24 err = proto.Unmarshal(b, pbn)
25 if err != nil {
26 t.Fatal(err)
unixfs/io/dagmodifier.go
+4 -3
@@ -4,11 +4,12 @@ import (
4 "bytes"
5 "errors"
6
7 - "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
7 + proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
8
9 - "github.com/jbenet/go-ipfs/importer/chunk"
9 + chunk "github.com/jbenet/go-ipfs/importer/chunk"
10 mdag "github.com/jbenet/go-ipfs/merkledag"
11 ft "github.com/jbenet/go-ipfs/unixfs"
12 + ftpb "github.com/jbenet/go-ipfs/unixfs/pb"
13 u "github.com/jbenet/go-ipfs/util"
14 )
15
@@ -19,7 +20,7 @@ type DagModifier struct {
20 dagserv *mdag.DAGService
21 curNode *mdag.Node
22
22 - pbdata *ft.PBData
23 + pbdata *ftpb.PBData
24 splitter chunk.BlockSplitter
25 }
26
unixfs/io/dagreader.go
+9 -8
@@ -8,6 +8,7 @@ import (
8 proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
9 mdag "github.com/jbenet/go-ipfs/merkledag"
10 ft "github.com/jbenet/go-ipfs/unixfs"
11 + ftpb "github.com/jbenet/go-ipfs/unixfs/pb"
12 u "github.com/jbenet/go-ipfs/util"
13 )
14
@@ -24,23 +25,23 @@ type DagReader struct {
25 // NewDagReader creates a new reader object that reads the data represented by the given
26 // node, using the passed in DAGService for data retreival
27 func NewDagReader(n *mdag.Node, serv *mdag.DAGService) (io.Reader, error) {
27 - pb := new(ft.PBData)
28 + pb := new(ftpb.PBData)
29 err := proto.Unmarshal(n.Data, pb)
30 if err != nil {
31 return nil, err
32 }
33
34 switch pb.GetType() {
34 - case ft.PBData_Directory:
35 + case ftpb.PBData_Directory:
36 // Dont allow reading directories
37 return nil, ErrIsDir
37 - case ft.PBData_File:
38 + case ftpb.PBData_File:
39 return &DagReader{
40 node: n,
41 serv: serv,
42 buf: bytes.NewBuffer(pb.GetData()),
43 }, nil
43 - case ft.PBData_Raw:
44 + case ftpb.PBData_Raw:
45 // Raw block will just be a single level, return a byte buffer
46 return bytes.NewBuffer(pb.GetData()), nil
47 default:
@@ -63,7 +64,7 @@ func (dr *DagReader) precalcNextBuf() error {
64 }
65 nxt = nxtNode
66 }
66 - pb := new(ft.PBData)
67 + pb := new(ftpb.PBData)
68 err := proto.Unmarshal(nxt.Data, pb)
69 if err != nil {
70 return err
@@ -71,13 +72,13 @@ func (dr *DagReader) precalcNextBuf() error {
72 dr.position++
73
74 switch pb.GetType() {
74 - case ft.PBData_Directory:
75 + case ftpb.PBData_Directory:
76 return ft.ErrInvalidDirLocation
76 - case ft.PBData_File:
77 + case ftpb.PBData_File:
78 //TODO: this *should* work, needs testing first
79 //return NewDagReader(nxt, dr.serv)
80 panic("Not yet handling different layers of indirection!")
80 - case ft.PBData_Raw:
81 + case ftpb.PBData_Raw:
82 dr.buf = bytes.NewBuffer(pb.GetData())
83 return nil
84 default:
unixfs/pb/Makefile renamed
unixfs/pb/data.pb.go renamed
unixfs/pb/data.proto renamed