storage: stop using deprecated io/ioutil

This replaces deprecated ioutil variables and functions as follows:

* ioutil.ReadDir -> os.ReadDir
* ioutil.ReadFile -> os.ReadFile
* ioutil.TempDir -> os.MkdirTemp
* ioutil.TempFile -> os.CreateTemp
* ioutil.WriteFile -> os.WriteFile

The ReadDir conversion involves an API change, the replacement
function returns a slice of fs.DirEntry instead of fs.FileInfo.
Where appropriate, the surrounding code has been adjusted; mostly,
that means using DirEntry.Type() instead of FileInfo.Mode().
Applying this change to the IoUtil interface would mean changing its
API, so this is left for later.

Signed-off-by: Stephen Kitt <skitt@redhat.com>
This commit is contained in:
Stephen Kitt
2023-05-02 17:02:27 +02:00
parent 2e93c65eff
commit ab75e48494
19 changed files with 38 additions and 56 deletions

View File

@@ -22,7 +22,6 @@ package util
import (
"encoding/base64"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect"
@@ -766,7 +765,7 @@ func checkVolumeContents(targetDir, tcName string, payload map[string]FileProjec
return nil
}
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
return err
}
@@ -781,7 +780,7 @@ func checkVolumeContents(targetDir, tcName string, payload map[string]FileProjec
return nil
}
d, err := ioutil.ReadDir(targetDir)
d, err := os.ReadDir(targetDir)
if err != nil {
t.Errorf("Unable to read dir %v: %v", targetDir, err)
return
@@ -790,7 +789,7 @@ func checkVolumeContents(targetDir, tcName string, payload map[string]FileProjec
if strings.HasPrefix(info.Name(), "..") {
continue
}
if info.Mode()&os.ModeSymlink != 0 {
if info.Type()&os.ModeSymlink != 0 {
p := filepath.Join(targetDir, info.Name())
actual, err := os.Readlink(p)
if err != nil {