summaryrefslogtreecommitdiffstats
path: root/source/filesystem.go
diff options
context:
space:
mode:
authorSteve Francia <steve.francia@gmail.com>2016-01-07 21:48:13 -0500
committerSteve Francia <steve.francia@gmail.com>2016-01-26 14:26:23 -0500
commit9f3796a31dc217b2b8094f948266b23ac3808aa6 (patch)
treee31b0061e7ed687276c1811e211a5892c288bbb4 /source/filesystem.go
parentca6ca4f4fc29906e491b5ac6b63fb65125c9c9e4 (diff)
Read/reread individual source content files
next is incremental conversion
Diffstat (limited to 'source/filesystem.go')
-rw-r--r--source/filesystem.go71
1 files changed, 39 insertions, 32 deletions
diff --git a/source/filesystem.go b/source/filesystem.go
index 75cf09d56..09118c27a 100644
--- a/source/filesystem.go
+++ b/source/filesystem.go
@@ -14,13 +14,14 @@
package source
import (
- "github.com/spf13/viper"
"io"
"os"
"path/filepath"
"regexp"
"strings"
+ "github.com/spf13/viper"
+
"github.com/spf13/hugo/helpers"
jww "github.com/spf13/jwalterweatherman"
)
@@ -59,14 +60,11 @@ func (f *Filesystem) Files() []*File {
return f.files
}
+// add populates a file in the Filesystem.files
func (f *Filesystem) add(name string, reader io.Reader) (err error) {
var file *File
- //if f.Base == "" {
- //file = NewFileWithContents(name, reader)
- //} else {
file, err = NewFileFromAbs(f.Base, name, reader)
- //}
if err == nil {
f.files = append(f.files, file)
@@ -79,48 +77,57 @@ func (f *Filesystem) getRelativePath(name string) (final string, err error) {
}
func (f *Filesystem) captureFiles() {
-
walker := func(filePath string, fi os.FileInfo, err error) error {
if err != nil {
return nil
}
- if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
- link, err := filepath.EvalSymlinks(filePath)
- if err != nil {
- jww.ERROR.Printf("Cannot read symbolic link '%s', error was: %s", filePath, err)
- return nil
- }
- linkfi, err := os.Stat(link)
+ b, err := f.shouldRead(filePath, fi)
+ if err != nil {
+ return err
+ }
+ if b {
+ rd, err := NewLazyFileReader(filePath)
if err != nil {
- jww.ERROR.Printf("Cannot stat '%s', error was: %s", link, err)
- return nil
- }
- if !linkfi.Mode().IsRegular() {
- jww.ERROR.Printf("Symbolic links for directories not supported, skipping '%s'", filePath)
+ return err
}
- return nil
+ f.add(filePath, rd)
}
+ return err
+ }
- if fi.IsDir() {
- if f.avoid(filePath) || isNonProcessablePath(filePath) {
- return filepath.SkipDir
- }
- return nil
- }
+ filepath.Walk(f.Base, walker)
+}
- if isNonProcessablePath(filePath) {
- return nil
+func (f *Filesystem) shouldRead(filePath string, fi os.FileInfo) (bool, error) {
+ if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
+ link, err := filepath.EvalSymlinks(filePath)
+ if err != nil {
+ jww.ERROR.Printf("Cannot read symbolic link '%s', error was: %s", filePath, err)
+ return false, nil
}
- rd, err := NewLazyFileReader(filePath)
+ linkfi, err := os.Stat(link)
if err != nil {
- return err
+ jww.ERROR.Printf("Cannot stat '%s', error was: %s", link, err)
+ return false, nil
}
- f.add(filePath, rd)
- return nil
+ if !linkfi.Mode().IsRegular() {
+ jww.ERROR.Printf("Symbolic links for directories not supported, skipping '%s'", filePath)
+ }
+ return false, nil
}
- filepath.Walk(f.Base, walker)
+ if fi.IsDir() {
+ if f.avoid(filePath) || isNonProcessablePath(filePath) {
+ return false, filepath.SkipDir
+ }
+ return false, nil
+ }
+
+ if isNonProcessablePath(filePath) {
+ return false, nil
+ }
+ return true, nil
}
func (f *Filesystem) avoid(filePath string) bool {