Skip to content

Commit

Permalink
Merge pull request #7 from TRON-US/BTFS-1582
Browse files Browse the repository at this point in the history
BTFS-1582
  • Loading branch information
taiyangc authored Feb 13, 2020
2 parents 8ed15fa + 2f8a632 commit c59d5af
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
3 changes: 3 additions & 0 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type DirIterator interface {

// AbsRootPath returns the absolute path of the root directory.
AbsRootPath() (string, error)

// SetReedSolomon sets the flag to indicate this Directory is used for Reed-solomon
SetReedSolomon()
}

// Directory is a special file which can link to any number of files.
Expand Down
29 changes: 19 additions & 10 deletions multipartfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ func makeRelative(child, parent string) string {
type multipartIterator struct {
f *multipartDirectory

curFile Node
curName string
err error
absRootPath string
curFile Node
curName string
err error
absRootPath string
forReedSolomon bool
}

func (it *multipartIterator) Name() string {
Expand Down Expand Up @@ -219,11 +220,12 @@ func (it *multipartIterator) Next() bool {
// Finally, advance to the next file.
it.curFile, it.err = it.f.walker.nextFile()

//
if it.absRootPath == "" && it.f.walker.currAbsPath != "" && it.f.path != "/" {
var err error
if it.absRootPath, err = getAbsRootPath(it.f.walker.currAbsPath, it.f.path); err != nil {
it.err = err
if it.forReedSolomon {
if it.absRootPath == "" && it.f.walker.currAbsPath != "" && it.f.path != "/" {
var err error
if it.absRootPath, err = getAbsRootPath(it.f.walker.currAbsPath, it.f.path); err != nil {
it.err = err
}
}
}

Expand All @@ -249,6 +251,9 @@ func (it *multipartIterator) Err() error {
}

func (it *multipartIterator) AbsRootPath() (string, error) {
if !it.forReedSolomon {
return "", errors.New("Not supported for non-Reed-Solomon directory")
}
first := true
for {
more := it.Next()
Expand All @@ -265,8 +270,12 @@ func (it *multipartIterator) AbsRootPath() (string, error) {
}
}

func (it *multipartIterator) SetReedSolomon() {
it.forReedSolomon = true
}

func (f *multipartDirectory) Entries() DirIterator {
return &multipartIterator{f: f}
return &multipartIterator{f: f, forReedSolomon: false}
}

func (f *multipartDirectory) Close() error {
Expand Down
3 changes: 3 additions & 0 deletions serialfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ func (it *serialIterator) Err() error {
return it.err
}

func (it *serialIterator) SetReedSolomon() {
}

func (it *serialIterator) AbsRootPath() (string, error) {
return "", nil
}
Expand Down
3 changes: 3 additions & 0 deletions slicedirectory.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func (it *sliceIterator) AbsRootPath() (string, error) {
return "", nil
}

func (it *sliceIterator) SetReedSolomon() {
}

// SliceFile implements Node, and provides simple directory handling.
// It contains children files, and is created from a `[]Node`.
// SliceFiles are always directories, and can't be read from or closed.
Expand Down

0 comments on commit c59d5af

Please sign in to comment.