Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
ERROR-log on symbolic links
Browse files Browse the repository at this point in the history
filepath.Walk does not follow symbolic links.
There's no easy fix for that outside of Go, so the best we can do for now is to give notice to the end user by ERROR log statements.

This commit also fixes a related panic situation in GenerateTemplateNameFrom when the layout dir was a symbolic link.

Fixes gohugoio#283
  • Loading branch information
bep committed Dec 10, 2014
1 parent 9f77f93 commit e6541c4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
5 changes: 5 additions & 0 deletions commands/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ func getDirList() []string {
return nil
}

if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
jww.ERROR.Printf("Symbolic links not supported, skipping '%s'", path)
return nil
}

if fi.IsDir() {
a = append(a, path)
}
Expand Down
9 changes: 7 additions & 2 deletions source/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ package source

import (
"bytes"
"github.com/spf13/hugo/helpers"
jww "github.com/spf13/jwalterweatherman"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/spf13/hugo/helpers"
)

type Input interface {
Expand Down Expand Up @@ -84,6 +84,11 @@ func (f *Filesystem) captureFiles() {
return nil
}

if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
jww.ERROR.Printf("Symbolic links not supported, skipping '%s'", filePath)
return nil
}

if fi.IsDir() {
if f.avoid(filePath) || isNonProcessablePath(filePath) {
return filepath.SkipDir
Expand Down
19 changes: 12 additions & 7 deletions tpl/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ package tpl
import (
"bytes"
"errors"
"github.com/eknkc/amber"
"github.com/spf13/cast"
"github.com/spf13/hugo/helpers"
jww "github.com/spf13/jwalterweatherman"
"github.com/yosssi/ace"
"html"
"html/template"
"io"
Expand All @@ -25,12 +30,6 @@ import (
"reflect"
"strconv"
"strings"

"github.com/eknkc/amber"
"github.com/spf13/cast"
"github.com/spf13/hugo/helpers"
jww "github.com/spf13/jwalterweatherman"
"github.com/yosssi/ace"
)

var localTemplates *template.Template
Expand Down Expand Up @@ -703,7 +702,8 @@ func (t *GoHtmlTemplate) AddTemplateFile(name, path string) error {
}

func (t *GoHtmlTemplate) GenerateTemplateNameFrom(base, path string) string {
return filepath.ToSlash(path[len(base)+1:])
name, _ := filepath.Rel(base, path)
return filepath.ToSlash(name)
}

func ignoreDotFile(path string) bool {
Expand All @@ -716,6 +716,11 @@ func (t *GoHtmlTemplate) loadTemplates(absPath string, prefix string) {
return nil
}

if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
jww.ERROR.Printf("Symbolic links not supported, skipping '%s'", absPath)
return nil
}

if !fi.IsDir() {
if ignoreDotFile(path) {
return nil
Expand Down

0 comments on commit e6541c4

Please sign in to comment.