Skip to content

Commit b214409

Browse files
author
Eric Chen
authored
Merge pull request #30 from TRON-US/BTFS-1849
Btfs 1849
2 parents ec54a2f + 495901f commit b214409

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

file/reed_solomon_file.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,18 @@ func (f *rsDirectory) SetSize(size int64) error {
9595
return errors.New("not supported")
9696
}
9797

98+
func (f *rsDirectory) IsReedSolomon() bool {
99+
return true
100+
}
101+
98102
type rsIterator struct {
99-
state int
100-
ctx context.Context
101-
cidString string
102-
files chan interface{}
103-
dserv ipld.DAGService
104-
rsDir *rsDirectory
103+
state int
104+
ctx context.Context
105+
cidString string
106+
files chan interface{}
107+
dserv ipld.DAGService
108+
rsDir *rsDirectory
109+
breadthFirstTraversal bool
105110

106111
curName string
107112
curFile files.Node
@@ -162,7 +167,8 @@ func (it *rsIterator) Next() bool {
162167
case *uio.DirNode:
163168
it.curFile, it.err = NewReedSolomonSubDirectory(it.ctx, it.dserv, it.cidString, nd)
164169
case *uio.FileNode:
165-
it.curFile, it.err = NewReedSolomonFileUnderDirectory(it.ctx, it.dserv, it.cidString, nd)
170+
it.curFile, it.err =
171+
NewReedSolomonFileUnderDirectory(it.ctx, it.dserv, it.cidString, nd, it.breadthFirstTraversal)
166172
case *uio.SymlinkNode:
167173
it.curFile, it.err = files.NewLinkFile(nd.Data, nil), nil
168174
default:
@@ -219,7 +225,8 @@ func (it *rsIterator) Err() error {
219225
return it.err
220226
}
221227

222-
func (it *rsIterator) SetReedSolomon() {
228+
func (it *rsIterator) BreadthFirstTraversal() {
229+
it.breadthFirstTraversal = true
223230
}
224231

225232
type rsFile struct {
@@ -321,7 +328,8 @@ func NewReedSolomonSubDirectory(ctx context.Context, dserv ipld.DAGService, cid
321328
// NewReedSolomonFileUnderDirectory returns a files.Node for the given `nd` Node.
322329
// This functioon is called within the context of Reed-Solomon DAG for directory.
323330
// The given `nd` is a uio.FileNode and is used to create a reader.
324-
func NewReedSolomonFileUnderDirectory(ctx context.Context, dserv ipld.DAGService, cid string, nd uio.Node) (files.Node, error) {
331+
func NewReedSolomonFileUnderDirectory(
332+
ctx context.Context, dserv ipld.DAGService, cid string, nd uio.Node, bfs bool) (files.Node, error) {
325333
// Locking is for synchronizing write access to rsDagInstance.offset.
326334
// But rsDagInstance.offset may not be necessary. We use this field to verify the offset in `nd`.
327335
rsDagInstance := GetDag(ctx, cid)
@@ -340,7 +348,7 @@ func NewReedSolomonFileUnderDirectory(ctx context.Context, dserv ipld.DAGService
340348

341349
b := rsDagInstance.buff.Bytes()
342350
offset := fNode.StartOffset
343-
if rsDagInstance.offset != offset {
351+
if !bfs && rsDagInstance.offset != offset {
344352
return nil, errors.New("offset from the given FileNode is invalid.")
345353
}
346354
newOffset := offset + uint64(fNode.NodeSize())

file/unixfile.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (it *ufsIterator) Err() error {
9797
return it.err
9898
}
9999

100-
func (it *ufsIterator) SetReedSolomon() {
100+
func (it *ufsIterator) BreadthFirstTraversal() {
101101
}
102102

103103
func (d *ufsDirectory) Close() error {
@@ -141,6 +141,10 @@ func (f *ufsDirectory) SetSize(size int64) error {
141141
return errors.New("not supported")
142142
}
143143

144+
func (f *ufsDirectory) IsReedSolomon() bool {
145+
return false
146+
}
147+
144148
type ufsFile struct {
145149
uio.DagReader
146150
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/TRON-US/go-unixfs
33
require (
44
github.com/Stebalien/go-bitfield v0.0.1
55
github.com/TRON-US/go-btfs-chunker v0.2.8
6-
github.com/TRON-US/go-btfs-files v0.1.6
6+
github.com/TRON-US/go-btfs-files v0.1.7
77
github.com/gogo/protobuf v1.2.1
88
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c // indirect
99
github.com/ipfs/go-bitswap v0.1.2 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ github.com/TRON-US/go-btfs-chunker v0.2.8/go.mod h1:Wj0oyybAWtu5lpcAc90QQ3bhJ14J
77
github.com/TRON-US/go-btfs-files v0.1.1/go.mod h1:tD2vOKLcLCDNMn9rrA27n2VbNpHdKewGzEguIFY+EJ0=
88
github.com/TRON-US/go-btfs-files v0.1.6 h1:POR7n7UUIMNtjIDEloqqi1/pRua2Gn5asjMJZsfiSxI=
99
github.com/TRON-US/go-btfs-files v0.1.6/go.mod h1:I8LeoFulha712BW03zGgmDdNwa0qbAPwfMIglzw0fnE=
10+
github.com/TRON-US/go-btfs-files v0.1.7 h1:Yce1ycvUWPtvQ+Iv3stKqQXYymxhx/XyRZT0jJzdgVI=
11+
github.com/TRON-US/go-btfs-files v0.1.7/go.mod h1:I8LeoFulha712BW03zGgmDdNwa0qbAPwfMIglzw0fnE=
1012
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
1113
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32 h1:qkOC5Gd33k54tobS36cXdAzJbeHaduLtnLQQwNoIi78=
1214
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8=

0 commit comments

Comments
 (0)