From e2f91917d9d08734d9853737ee527ca107e11695 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Sun, 21 Jan 2018 23:26:25 -0500 Subject: [PATCH] ReadTree: clarify that returns only files Because the primary use-case is S3-style stores, we haven't really used directories. If we have a use-case, we can always pass a boolean parameter or create an alternative function. --- upup/pkg/fi/vfs_castore_test.go | 3 --- util/pkg/vfs/fs.go | 5 ++++- util/pkg/vfs/memfs.go | 4 +++- util/pkg/vfs/vfs.go | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/upup/pkg/fi/vfs_castore_test.go b/upup/pkg/fi/vfs_castore_test.go index 9d73270e77ea7..86588b588b3bd 100644 --- a/upup/pkg/fi/vfs_castore_test.go +++ b/upup/pkg/fi/vfs_castore_test.go @@ -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 } diff --git a/util/pkg/vfs/fs.go b/util/pkg/vfs/fs.go index 703e23a70c900..3aa3e7f612100 100644 --- a/util/pkg/vfs/fs.go +++ b/util/pkg/vfs/fs.go @@ -152,6 +152,8 @@ 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 { @@ -159,12 +161,13 @@ func readTree(base string, dest *[]Path) error { } 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 diff --git a/util/pkg/vfs/memfs.go b/util/pkg/vfs/memfs.go index c691806b7c405..2f0934871250c 100644 --- a/util/pkg/vfs/memfs.go +++ b/util/pkg/vfs/memfs.go @@ -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) } } diff --git a/util/pkg/vfs/vfs.go b/util/pkg/vfs/vfs.go index 448e98658d6a2..24892e798f278 100644 --- a/util/pkg/vfs/vfs.go +++ b/util/pkg/vfs/vfs.go @@ -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) }