Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for symbolic links for content, layout, static, theme #1857

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions commands/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package commands

import (
"fmt"
"github.com/spf13/hugo/hugofs"
"io/ioutil"
"net/http"
"os"
Expand All @@ -35,7 +36,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/fsync"
"github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/hugofs"
"github.com/spf13/hugo/hugolib"
"github.com/spf13/hugo/livereload"
"github.com/spf13/hugo/utils"
Expand Down Expand Up @@ -636,12 +636,12 @@ func getDirList() []string {
return nil
}

filepath.Walk(dataDir, walker)
filepath.Walk(helpers.AbsPathify(viper.GetString("ContentDir")), walker)
filepath.Walk(helpers.AbsPathify(viper.GetString("LayoutDir")), walker)
filepath.Walk(helpers.AbsPathify(viper.GetString("StaticDir")), walker)
helpers.SymbolicWalk(hugofs.SourceFs, dataDir, walker)
helpers.SymbolicWalk(hugofs.SourceFs, helpers.AbsPathify(viper.GetString("ContentDir")), walker)
helpers.SymbolicWalk(hugofs.SourceFs, helpers.AbsPathify(viper.GetString("LayoutDir")), walker)
helpers.SymbolicWalk(hugofs.SourceFs, helpers.AbsPathify(viper.GetString("StaticDir")), walker)
if helpers.ThemeSet() {
filepath.Walk(helpers.AbsPathify(viper.GetString("themesDir")+"/"+viper.GetString("theme")), walker)
helpers.SymbolicWalk(hugofs.SourceFs, helpers.AbsPathify(viper.GetString("themesDir")+"/"+viper.GetString("theme")), walker)
}

return a
Expand Down Expand Up @@ -745,7 +745,7 @@ func NewWatcher(port int) error {
// When mkdir -p is used, only the top directory triggers an event (at least on OSX)
if ev.Op&fsnotify.Create == fsnotify.Create {
if s, err := hugofs.SourceFs.Stat(ev.Name); err == nil && s.Mode().IsDir() {
afero.Walk(hugofs.SourceFs, ev.Name, walkAdder)
helpers.SymbolicWalk(hugofs.SourceFs, ev.Name, walkAdder)
}
}

Expand Down
2 changes: 1 addition & 1 deletion commands/import_jekyll.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func importFromJekyll(cmd *cobra.Command, args []string) error {
return convertJekyllPost(path, relPath, targetDir, draft)
}

err = filepath.Walk(jekyllRoot, callback)
err = helpers.SymbolicWalk(hugofs.OsFs, jekyllRoot, callback)

if err != nil {
return err
Expand Down
18 changes: 18 additions & 0 deletions helpers/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion source/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package source

import (
"github.com/spf13/hugo/hugofs"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -96,7 +97,12 @@ func (f *Filesystem) captureFiles() {
return err
}

filepath.Walk(f.Base, walker)
err := helpers.SymbolicWalk(hugofs.SourceFs, f.Base, walker)

if err != nil {
jww.ERROR.Println(err)
}

}

func (f *Filesystem) shouldRead(filePath string, fi os.FileInfo) (bool, error) {
Expand Down