Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-07-30 16:37:03 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-07-30 16:37:03 +0300
commit4ddd5361c1ee9b8abbd1f1cb60395d0979127f03 (patch)
tree2ceafdbf7d459b7f12bafcbc69e401f7e454116f
parenta0859dc67284988a397e265f7e83ea07357e9eb8 (diff)
Use the Afero source fs where relevant
Fixes #2319
-rw-r--r--commands/hugo.go15
-rw-r--r--commands/undraft.go5
-rw-r--r--source/lazy_file_reader_test.go11
-rw-r--r--tpl/template_resources.go16
4 files changed, 13 insertions, 34 deletions
diff --git a/commands/hugo.go b/commands/hugo.go
index f05b3da65..1b2b3b3c7 100644
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -17,7 +17,6 @@ package commands
import (
"fmt"
- "io/ioutil"
"net/http"
"os"
"path/filepath"
@@ -971,19 +970,7 @@ func isThemeVsHugoVersionMismatch() (mismatch bool, requiredMinVersion string) {
return
}
- f, err := fs.Open(path)
-
- if err != nil {
- return
- }
-
- defer f.Close()
-
- b, err := ioutil.ReadAll(f)
-
- if err != nil {
- return
- }
+ b, err := afero.ReadFile(fs, path)
c, err := parser.HandleTOMLMetaData(b)
diff --git a/commands/undraft.go b/commands/undraft.go
index c9f2b24d7..c7a248a71 100644
--- a/commands/undraft.go
+++ b/commands/undraft.go
@@ -20,6 +20,7 @@ import (
"time"
"github.com/spf13/cobra"
+ "github.com/spf13/hugo/hugofs"
"github.com/spf13/hugo/parser"
)
@@ -46,7 +47,7 @@ func Undraft(cmd *cobra.Command, args []string) error {
location := args[0]
// open the file
- f, err := os.Open(location)
+ f, err := hugofs.Source().Open(location)
if err != nil {
return err
}
@@ -63,7 +64,7 @@ func Undraft(cmd *cobra.Command, args []string) error {
return newSystemErrorF("an error occurred while undrafting %q: %s", location, err)
}
- f, err = os.OpenFile(location, os.O_WRONLY|os.O_TRUNC, 0644)
+ f, err = hugofs.Source().OpenFile(location, os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return newSystemErrorF("%q not be undrafted due to error opening file to save changes: %q\n", location, err)
}
diff --git a/source/lazy_file_reader_test.go b/source/lazy_file_reader_test.go
index 5522c9f1b..778a9513b 100644
--- a/source/lazy_file_reader_test.go
+++ b/source/lazy_file_reader_test.go
@@ -16,7 +16,6 @@ package source
import (
"bytes"
"io"
- "io/ioutil"
"os"
"testing"
@@ -60,7 +59,7 @@ func TestRead(t *testing.T) {
b, err := afero.ReadFile(fs, filename)
if err != nil {
- t.Fatalf("ioutil.ReadFile: %v", err)
+ t.Fatalf("afero.ReadFile: %v", err)
}
rd, err := NewLazyFileReader(fs, filename)
@@ -101,7 +100,7 @@ func TestSeek(t *testing.T) {
filename := "lazy_file_reader_test.go"
b, err := afero.ReadFile(fs, filename)
if err != nil {
- t.Fatalf("ioutil.ReadFile: %v", err)
+ t.Fatalf("afero.ReadFile: %v", err)
}
// no cache case
@@ -192,14 +191,14 @@ func TestSeek(t *testing.T) {
func TestWriteTo(t *testing.T) {
fs := afero.NewOsFs()
filename := "lazy_file_reader_test.go"
- fi, err := os.Stat(filename)
+ fi, err := fs.Stat(filename)
if err != nil {
t.Fatalf("os.Stat: %v", err)
}
- b, err := ioutil.ReadFile(filename)
+ b, err := afero.ReadFile(fs, filename)
if err != nil {
- t.Fatalf("ioutil.ReadFile: %v", err)
+ t.Fatalf("afero.ReadFile: %v", err)
}
rd, err := NewLazyFileReader(fs, filename)
diff --git a/tpl/template_resources.go b/tpl/template_resources.go
index 07451734d..eb470b3db 100644
--- a/tpl/template_resources.go
+++ b/tpl/template_resources.go
@@ -83,12 +83,8 @@ func resGetCache(id string, fs afero.Fs, ignoreCache bool) ([]byte, error) {
return nil, nil
}
- f, err := fs.Open(fID)
- if err != nil {
- return nil, err
- }
- defer f.Close()
- return ioutil.ReadAll(f)
+ return afero.ReadFile(fs, fID)
+
}
// resWriteCache writes bytes to an ID into the file cache
@@ -165,12 +161,8 @@ func resGetLocal(url string, fs afero.Fs) ([]byte, error) {
return nil, err
}
- f, err := fs.Open(filename)
- if err != nil {
- return nil, err
- }
- defer f.Close()
- return ioutil.ReadAll(f)
+ return afero.ReadFile(fs, filename)
+
}
// resGetResource loads the content of a local or remote file