mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
Replace deprecated ioutil with io and os
https://pkg.go.dev/io/ioutil is deprecated since Go 1.16.
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
97b010f521
commit
d453c12742
@@ -23,7 +23,6 @@ import (
|
||||
_ "image/gif"
|
||||
_ "image/png"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -92,7 +91,7 @@ func (i *imageResource) getExif() *exif.ExifInfo {
|
||||
|
||||
read := func(info filecache.ItemInfo, r io.ReadSeeker) error {
|
||||
meta := &imageMeta{}
|
||||
data, err := ioutil.ReadAll(r)
|
||||
data, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@ import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/gif"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"os"
|
||||
@@ -750,9 +749,9 @@ func TestImageOperationsGolden(t *testing.T) {
|
||||
func assetGoldenDirs(c *qt.C, dir1, dir2 string) {
|
||||
|
||||
// The two dirs above should now be the same.
|
||||
dirinfos1, err := ioutil.ReadDir(dir1)
|
||||
dirinfos1, err := os.ReadDir(dir1)
|
||||
c.Assert(err, qt.IsNil)
|
||||
dirinfos2, err := ioutil.ReadDir(dir2)
|
||||
dirinfos2, err := os.ReadDir(dir2)
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(len(dirinfos1), qt.Equals, len(dirinfos2))
|
||||
|
||||
|
@@ -17,7 +17,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -370,7 +369,7 @@ func (l *genericResource) initContent() error {
|
||||
defer r.Close()
|
||||
|
||||
var b []byte
|
||||
b, err = ioutil.ReadAll(r)
|
||||
b, err = io.ReadAll(r)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
@@ -48,7 +47,7 @@ type HTTPError struct {
|
||||
func responseToData(res *http.Response, readBody bool) map[string]any {
|
||||
var body []byte
|
||||
if readBody {
|
||||
body, _ = ioutil.ReadAll(res.Body)
|
||||
body, _ = io.ReadAll(res.Body)
|
||||
}
|
||||
|
||||
m := map[string]any{
|
||||
@@ -157,7 +156,7 @@ func (c *Client) FromRemote(uri string, optionsm map[string]any) (resource.Resou
|
||||
// A response to a HEAD method should not have a body. If it has one anyway, that body must be ignored.
|
||||
// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD
|
||||
if !isHeadMethod && res.Body != nil {
|
||||
body, err = ioutil.ReadAll(res.Body)
|
||||
body, err = io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read remote resource %q: %w", uri, err)
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -162,7 +161,7 @@ func (t *babelTransformation) Transform(ctx *resources.ResourceTransformationCtx
|
||||
// Create compile into a real temp file:
|
||||
// 1. separate stdout/stderr messages from babel (https://github.com/gohugoio/hugo/issues/8136)
|
||||
// 2. allow generation and retrieval of external source map.
|
||||
compileOutput, err := ioutil.TempFile("", "compileOut-*.js")
|
||||
compileOutput, err := os.CreateTemp("", "compileOut-*.js")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -206,7 +205,7 @@ func (t *babelTransformation) Transform(ctx *resources.ResourceTransformationCtx
|
||||
return fmt.Errorf(errBuf.String()+": %w", err)
|
||||
}
|
||||
|
||||
content, err := ioutil.ReadAll(compileOutput)
|
||||
content, err := io.ReadAll(compileOutput)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -214,7 +213,7 @@ func (t *babelTransformation) Transform(ctx *resources.ResourceTransformationCtx
|
||||
mapFile := compileOutput.Name() + ".map"
|
||||
if _, err := os.Stat(mapFile); err == nil {
|
||||
defer os.Remove(mapFile)
|
||||
sourceMap, err := ioutil.ReadFile(mapFile)
|
||||
sourceMap, err := os.ReadFile(mapFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ package js
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -77,7 +77,7 @@ func (t *buildTransformation) Transform(ctx *resources.ResourceTransformationCtx
|
||||
ctx.ReplaceOutPathExtension(".js")
|
||||
}
|
||||
|
||||
src, err := ioutil.ReadAll(ctx.From)
|
||||
src, err := io.ReadAll(ctx.From)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -98,7 +98,7 @@ func (t *buildTransformation) Transform(ctx *resources.ResourceTransformationCtx
|
||||
}
|
||||
|
||||
if buildOptions.Sourcemap == api.SourceMapExternal && buildOptions.Outdir == "" {
|
||||
buildOptions.Outdir, err = ioutil.TempDir(os.TempDir(), "compileOutput")
|
||||
buildOptions.Outdir, err = os.MkdirTemp(os.TempDir(), "compileOutput")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ package js
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -260,7 +260,7 @@ func createBuildPlugins(c *Client, opts Options) ([]api.Plugin, error) {
|
||||
})
|
||||
build.OnLoad(api.OnLoadOptions{Filter: `.*`, Namespace: nsImportHugo},
|
||||
func(args api.OnLoadArgs) (api.OnLoadResult, error) {
|
||||
b, err := ioutil.ReadFile(args.Path)
|
||||
b, err := os.ReadFile(args.Path)
|
||||
if err != nil {
|
||||
return api.OnLoadResult{}, fmt.Errorf("failed to read %q: %w", args.Path, err)
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
@@ -365,7 +364,7 @@ func (imp *importResolver) importRecursive(
|
||||
func (imp *importResolver) resolve() (io.Reader, error) {
|
||||
const importIdentifier = "@import"
|
||||
|
||||
content, err := ioutil.ReadAll(imp.r)
|
||||
content, err := io.ReadAll(imp.r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@ package resources
|
||||
import (
|
||||
"image"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -106,7 +105,7 @@ func newTestResourceOsFs(c *qt.C) (*Spec, string) {
|
||||
cfg := createTestCfg()
|
||||
cfg.Set("baseURL", "https://example.com")
|
||||
|
||||
workDir, err := ioutil.TempDir("", "hugores")
|
||||
workDir, err := os.MkdirTemp("", "hugores")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(workDir, qt.Not(qt.Equals), "")
|
||||
|
||||
|
Reference in New Issue
Block a user