aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/spf13/afero/path.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/spf13/afero/path.go')
-rw-r--r--vendor/github.com/spf13/afero/path.go18
1 files changed, 8 insertions, 10 deletions
diff --git a/vendor/github.com/spf13/afero/path.go b/vendor/github.com/spf13/afero/path.go
index 1d90e46..18f60a0 100644
--- a/vendor/github.com/spf13/afero/path.go
+++ b/vendor/github.com/spf13/afero/path.go
@@ -60,7 +60,7 @@ func walk(fs Fs, path string, info os.FileInfo, walkFn filepath.WalkFunc) error
for _, name := range names {
filename := filepath.Join(path, name)
- fileInfo, err := lstatIfOs(fs, filename)
+ fileInfo, err := lstatIfPossible(fs, filename)
if err != nil {
if err := walkFn(filename, fileInfo, err); err != nil && err != filepath.SkipDir {
return err
@@ -77,15 +77,13 @@ func walk(fs Fs, path string, info os.FileInfo, walkFn filepath.WalkFunc) error
return nil
}
-// if the filesystem is OsFs use Lstat, else use fs.Stat
-func lstatIfOs(fs Fs, path string) (info os.FileInfo, err error) {
- _, ok := fs.(*OsFs)
- if ok {
- info, err = os.Lstat(path)
- } else {
- info, err = fs.Stat(path)
+// if the filesystem supports it, use Lstat, else use fs.Stat
+func lstatIfPossible(fs Fs, path string) (os.FileInfo, error) {
+ if lfs, ok := fs.(Lstater); ok {
+ fi, _, err := lfs.LstatIfPossible(path)
+ return fi, err
}
- return
+ return fs.Stat(path)
}
// Walk walks the file tree rooted at root, calling walkFn for each file or
@@ -100,7 +98,7 @@ func (a Afero) Walk(root string, walkFn filepath.WalkFunc) error {
}
func Walk(fs Fs, root string, walkFn filepath.WalkFunc) error {
- info, err := lstatIfOs(fs, root)
+ info, err := lstatIfPossible(fs, root)
if err != nil {
return walkFn(root, nil, err)
}