Skip to content

Commit

Permalink
fs/fsutil: Extend Control with Readdirnames member function
Browse files Browse the repository at this point in the history
  • Loading branch information
rjeczalik committed Aug 10, 2014
1 parent e95d122 commit 678c49b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
32 changes: 25 additions & 7 deletions fs/fsutil/fsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@ import (
"github.com/rjeczalik/tools/fs"
)

// Readpaths reads names of all the files and directories of the 'dir' directory.
// Readpaths reads paths of all the files and directories of the 'dir' directory.
// If none files were found, the 'files' slice will be nil. If none directories
// were found, the 'dirs' slice will be nil. If the 'dir' was empty or error
// occured, both slice will be empty.
// occured during accessing the filesystem, both slice will be empty.
func Readpaths(dir string) (files, dirs []string) {
return defaultControl.Readpaths(dir)
}

// Readdirpaths reads all names of all subdirectories of the 'dir', except
// Readdirpaths reads all paths of all subdirectories of the 'dir', except
// the ones which begin with a dot.
func Readdirpaths(dir string) []string {
return defaultControl.Readdirpaths(dir)
}

// Readdirpaths reads all names of all subdirectories of the 'dir', except
// the ones which begin with a dot.
func Readdirnames(dir string) []string {
return Default.Readdirnames(dir)
}

// Intersect returns a collection of paths which are the longest intersection
// between two directory trees - those trees have roots in 'src' and 'dir' directories.
// It does not glob into directories, which names begin with a dot.
Expand Down Expand Up @@ -76,21 +82,33 @@ type Control struct {
Hidden bool
}

// Readpaths reads names of all the files and directories of the 'dir' directory.
// Readpaths reads paths of all the files and directories of the 'dir' directory.
// If none files were found, the 'files' slice will be nil. If none directories
// were found, the 'dirs' slice will be nil. If the 'dir' was empty or error
// occured, both slice will be empty.
// occured during accessing the underlying filesystem, both slice will be empty.
func (c Control) Readpaths(dir string) (files, dirs []string) {
return c.readall(dir)
}

// Readdirpaths reads names of all the subdirectories of the 'dir' directory.
// If none were found or error occured, returned slice is nil.
// Readdirpaths reads paths of all the subdirectories of the 'dir' directory.
// If none were found or error occured during accessing the underlying filesystem,
// returned slice is nil.
func (c Control) Readdirpaths(dir string) []string {
_, d := c.readall(dir)
return d
}

// Readdirnames reads names of all the subdirectories of the 'dir' directory.
// If none were found or error occured during accessing the underlying filesystem,
// returned slice is nil.
func (c Control) Readdirnames(dir string) []string {
_, d := c.readall(dir)
for i := range d {
d[i] = filepath.Base(d[i])
}
return d
}

func catchspy(fs fs.Filesystem) (spy memfs.FS, ok bool) {
var t teefs
if t, ok = fs.(teefs); ok {
Expand Down
4 changes: 4 additions & 0 deletions fs/fsutil/fsutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ func TestReaddirpaths(t *testing.T) {
}
}

func TestReaddirnames(t *testing.T) {
t.Skip("TODO(rjeczalik)")
}

func TestCatchSpy(t *testing.T) {
cases := [...]struct {
c Control
Expand Down

0 comments on commit 678c49b

Please sign in to comment.