diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-02-14 14:16:03 +0300 |
---|---|---|
committer | Steve Francia <steve.francia@gmail.com> | 2016-03-22 02:13:29 +0300 |
commit | e5aa47749157e4c49a645d37df89fa76b0e8f952 (patch) | |
tree | 357f08c588583925d8e7a1d28e63b9f2b83a027a /helpers/path.go | |
parent | 6258d48b0220fa59edf50a32031677eb7b7944d4 (diff) |
Add support for symbolic links for content, layout, static, theme
Note: This is for the content roots only, but that should satisfy most needs.
Fixes #1855
Diffstat (limited to 'helpers/path.go')
-rw-r--r-- | helpers/path.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/helpers/path.go b/helpers/path.go index f39815b6e..1ac5a87d8 100644 --- a/helpers/path.go +++ b/helpers/path.go @@ -428,6 +428,24 @@ func FindCWD() (string, error) { return path, nil } +// SymbolicWalk is like filepath.Walk, but it supports the root being a +// 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 { + rootContent, err := afero.ReadDir(fs, root) + + if err != nil { + return walker(root, nil, err) + } + + for _, fi := range rootContent { + afero.Walk(fs, filepath.Join(root, fi.Name()), walker) + } + + return nil + +} + // Same as WriteToDisk but checks to see if file/directory already exists. func SafeWriteToDisk(inpath string, r io.Reader, fs afero.Fs) (err error) { return afero.SafeWriteReader(fs, inpath, r) |