summaryrefslogtreecommitdiffstats
path: root/helpers/path.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-03-25 12:47:57 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-03-25 12:49:23 +0100
commitbfe800941538316ef213e9f3d2a7555a6dcff651 (patch)
treed91abe451b5fd6e04ece6e573ebdc6cd7cb3cdfc /helpers/path.go
parent977b0e342c82f54a34e8612ea187101abc92d9ec (diff)
helpers: Fix SymbolicWalk for the root folder
handle the root folders themselves. This commit fixes that. Fixes #2018
Diffstat (limited to 'helpers/path.go')
-rw-r--r--helpers/path.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/helpers/path.go b/helpers/path.go
index 34b7675fc..5f1e83398 100644
--- a/helpers/path.go
+++ b/helpers/path.go
@@ -449,6 +449,22 @@ func FindCWD() (string, error) {
// symbolic link. It will still not follow symbolic links deeper down in
// the file structure
func SymbolicWalk(fs afero.Fs, root string, walker filepath.WalkFunc) error {
+
+ // Handle the root first
+ fileInfo, err := lstatIfOs(fs, root)
+
+ if err != nil || !fileInfo.IsDir() {
+ return nil
+ }
+
+ if err != nil {
+ return walker(root, nil, err)
+ }
+
+ if err := walker(root, fileInfo, err); err != nil && err != filepath.SkipDir {
+ return err
+ }
+
rootContent, err := afero.ReadDir(fs, root)
if err != nil {
@@ -463,6 +479,18 @@ func SymbolicWalk(fs afero.Fs, root string, walker filepath.WalkFunc) error {
}
+// Code copied from Afero's path.go
+// if the filesystem is OsFs use Lstat, else use fs.Stat
+func lstatIfOs(fs afero.Fs, path string) (info os.FileInfo, err error) {
+ _, ok := fs.(*afero.OsFs)
+ if ok {
+ info, err = os.Lstat(path)
+ } else {
+ info, err = fs.Stat(path)
+ }
+ return
+}
+
// SafeWriteToDisk is the same as WriteToDisk
// but it also checks to see if file/directory already exists.
func SafeWriteToDisk(inpath string, r io.Reader, fs afero.Fs) (err error) {