From 2f8a632b6d32b326df44b7a38e61e22bea7cb9ce Mon Sep 17 00:00:00 2001 From: Steve Yeom Date: Thu, 13 Feb 2020 15:50:09 -0800 Subject: [PATCH] BTFS-1582 --- file.go | 3 +++ multipartfile.go | 29 +++++++++++++++++++---------- serialfile.go | 3 +++ slicedirectory.go | 3 +++ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/file.go b/file.go index 0c13014..52c779f 100644 --- a/file.go +++ b/file.go @@ -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. diff --git a/multipartfile.go b/multipartfile.go index d2caa6c..16a216f 100644 --- a/multipartfile.go +++ b/multipartfile.go @@ -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 { @@ -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 + } } } @@ -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() @@ -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 { diff --git a/serialfile.go b/serialfile.go index 8a0cb29..4ca7aaa 100644 --- a/serialfile.go +++ b/serialfile.go @@ -105,6 +105,9 @@ func (it *serialIterator) Err() error { return it.err } +func (it *serialIterator) SetReedSolomon() { +} + func (it *serialIterator) AbsRootPath() (string, error) { return "", nil } diff --git a/slicedirectory.go b/slicedirectory.go index ef3d6e7..6682d32 100644 --- a/slicedirectory.go +++ b/slicedirectory.go @@ -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.