Skip to content

Commit

Permalink
Merge pull request #4315 from justinsb/clarify_readtree
Browse files Browse the repository at this point in the history
ReadTree: clarify that returns only files
  • Loading branch information
k8s-ci-robot authored Jan 24, 2018
2 parents a070823 + e2f9191 commit 151574b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
3 changes: 0 additions & 3 deletions upup/pkg/fi/vfs_castore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ func TestVFSCAStoreRoundTrip(t *testing.T) {

pathMap := make(map[string]vfs.Path)
for _, p := range paths {
if p.(*vfs.MemFSPath).HasChildren() {
continue
}
pathMap[p.Path()] = p
}

Expand Down
5 changes: 4 additions & 1 deletion util/pkg/vfs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,22 @@ func (p *FSPath) ReadTree() ([]Path, error) {
return paths, nil
}

// readTree recursively finds files and adds them to dest
// It excludes directories.
func readTree(base string, dest *[]Path) error {
files, err := ioutil.ReadDir(base)
if err != nil {
return err
}
for _, f := range files {
p := path.Join(base, f.Name())
*dest = append(*dest, NewFSPath(p))
if f.IsDir() {
err = readTree(p, dest)
if err != nil {
return err
}
} else {
*dest = append(*dest, NewFSPath(p))
}
}
return nil
Expand Down
4 changes: 3 additions & 1 deletion util/pkg/vfs/memfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ func (p *MemFSPath) ReadTree() ([]Path, error) {

func (p *MemFSPath) readTree(dest *[]Path) {
for _, f := range p.children {
*dest = append(*dest, f)
if !f.HasChildren() {
*dest = append(*dest, f)
}
f.readTree(dest)
}
}
Expand Down
1 change: 1 addition & 0 deletions util/pkg/vfs/vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Path interface {
ReadDir() ([]Path, error)

// ReadTree lists all files (recursively) in the subtree rooted at the current Path
/// Note: returns only files, not directories
ReadTree() ([]Path, error)
}

Expand Down

0 comments on commit 151574b

Please sign in to comment.