Use the Afero source fs where relevant

Fixes #2319
This commit is contained in:
Bjørn Erik Pedersen
2016-07-30 15:37:03 +02:00
parent a0859dc672
commit 4ddd5361c1
4 changed files with 13 additions and 34 deletions

View File

@@ -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)

View File

@@ -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)
}