import (
"fmt"
- "io/ioutil"
"net/http"
"os"
"path/filepath"
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)
"time"
"github.com/spf13/cobra"
+ "github.com/spf13/hugo/hugofs"
"github.com/spf13/hugo/parser"
)
location := args[0]
// open the file
- f, err := os.Open(location)
+ f, err := hugofs.Source().Open(location)
if err != nil {
return err
}
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)
}
import (
"bytes"
"io"
- "io/ioutil"
"os"
"testing"
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)
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
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)
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
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