ERROR-log on symbolic links
authorbep <bjorn.erik.pedersen@gmail.com>
Wed, 10 Dec 2014 15:48:51 +0000 (16:48 +0100)
committerbep <bjorn.erik.pedersen@gmail.com>
Wed, 10 Dec 2014 19:32:39 +0000 (20:32 +0100)
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 #283

commands/hugo.go
source/filesystem.go
tpl/template.go

index 6fd7fa2bd2f7c39e18295d91ce9c5b45748a4d8e..45eed3e28d69373b2f82f2ba83a63396cad1266e 100644 (file)
@@ -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)
                }
index d89149dc6c000469e491661e616d1bb82030301e..df0a4989cd98f36c3371980ef4dfbc7392139ad0 100644 (file)
@@ -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 {
@@ -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
index 5010af9ae5664095980552c6471e4d114357e302..d057f174d91ee9ad5a8487189464dd71f9319ee8 100644 (file)
@@ -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"
@@ -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
@@ -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 {
@@ -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