Replace deprecated ioutil with io and os

https://pkg.go.dev/io/ioutil is deprecated since Go 1.16.
This commit is contained in:
Oleksandr Redko
2023-02-19 00:43:26 +02:00
committed by Bjørn Erik Pedersen
parent 97b010f521
commit d453c12742
36 changed files with 112 additions and 191 deletions

View File

@@ -16,7 +16,7 @@ package commands
import (
"errors"
"fmt"
"io/ioutil"
"io"
"net"
"os"
"path/filepath"
@@ -201,7 +201,7 @@ func newCommandeer(mustHaveConfigFile, failOnInitErr, running bool, h *hugoBuild
rebuildDebouncer = debounce.New(4 * time.Second)
}
out := ioutil.Discard
out := io.Discard
if !h.quiet {
out = os.Stdout
}
@@ -221,7 +221,7 @@ func newCommandeer(mustHaveConfigFile, failOnInitErr, running bool, h *hugoBuild
running: running,
// This will be replaced later, but we need something to log to before the configuration is read.
logger: loggers.NewLogger(jww.LevelWarn, jww.LevelError, out, ioutil.Discard, running),
logger: loggers.NewLogger(jww.LevelWarn, jww.LevelError, out, io.Discard, running),
}
return c, c.loadConfig()

View File

@@ -15,7 +15,6 @@ package commands
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@@ -402,7 +401,7 @@ PostProcess: {{ $foo.RelPermalink }}
func writeFile(t testing.TB, filename, content string) {
must(t, os.MkdirAll(filepath.Dir(filename), os.FileMode(0755)))
must(t, ioutil.WriteFile(filename, []byte(content), os.FileMode(0755)))
must(t, os.WriteFile(filename, []byte(content), os.FileMode(0755)))
}
func must(t testing.TB, err error) {

View File

@@ -18,7 +18,7 @@ package commands
import (
"context"
"fmt"
"io/ioutil"
"io"
"os"
"os/signal"
"path/filepath"
@@ -138,10 +138,10 @@ func initializeConfig(mustHaveConfigFile, failOnInitErr, running bool,
func (c *commandeer) createLogger(cfg config.Provider) (loggers.Logger, error) {
var (
logHandle = ioutil.Discard
logHandle = io.Discard
logThreshold = jww.LevelWarn
logFile = cfg.GetString("logFile")
outHandle = ioutil.Discard
outHandle = io.Discard
stdoutThreshold = jww.LevelWarn
)
@@ -157,7 +157,7 @@ func (c *commandeer) createLogger(cfg config.Provider) (loggers.Logger, error) {
return nil, newSystemError("Failed to open log file:", logFile, err)
}
} else {
logHandle, err = ioutil.TempFile("", "hugo")
logHandle, err = os.CreateTemp("", "hugo")
if err != nil {
return nil, newSystemError(err)
}

View File

@@ -17,7 +17,7 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"regexp"
@@ -164,7 +164,7 @@ func (i *importCmd) importFromJekyll(cmd *cobra.Command, args []string) error {
func (i *importCmd) getJekyllDirInfo(fs afero.Fs, jekyllRoot string) (map[string]bool, bool) {
postDirs := make(map[string]bool)
hasAnyPost := false
if entries, err := ioutil.ReadDir(jekyllRoot); err == nil {
if entries, err := os.ReadDir(jekyllRoot); err == nil {
for _, entry := range entries {
if entry.IsDir() {
subDir := filepath.Join(jekyllRoot, entry.Name())
@@ -186,7 +186,7 @@ func (i *importCmd) retrieveJekyllPostDir(fs afero.Fs, dir string) (bool, bool)
return true, !isEmpty
}
if entries, err := ioutil.ReadDir(dir); err == nil {
if entries, err := os.ReadDir(dir); err == nil {
for _, entry := range entries {
if entry.IsDir() {
subDir := filepath.Join(dir, entry.Name())
@@ -247,7 +247,7 @@ func (i *importCmd) loadJekyllConfig(fs afero.Fs, jekyllRoot string) map[string]
defer f.Close()
b, err := ioutil.ReadAll(f)
b, err := io.ReadAll(f)
if err != nil {
return nil
}
@@ -310,7 +310,7 @@ func (i *importCmd) copyJekyllFilesAndFolders(jekyllRoot, dest string, jekyllPos
if err != nil {
return err
}
entries, err := ioutil.ReadDir(jekyllRoot)
entries, err := os.ReadDir(jekyllRoot)
if err != nil {
return err
}
@@ -386,7 +386,7 @@ func convertJekyllPost(path, relPath, targetDir string, draft bool) error {
targetParentDir := filepath.Dir(targetFile)
os.MkdirAll(targetParentDir, 0777)
contentBytes, err := ioutil.ReadFile(path)
contentBytes, err := os.ReadFile(path)
if err != nil {
jww.ERROR.Println("Read file error:", path)
return err