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:
		@@ -20,7 +20,6 @@ import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"crypto/sha256"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/user"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
@@ -1644,7 +1643,7 @@ func TestAttacherUnmountDevice(t *testing.T) {
 | 
			
		||||
			// Make JSON for this object
 | 
			
		||||
			if tc.jsonFile != "" {
 | 
			
		||||
				dataPath := filepath.Join(dir, volDataFileName)
 | 
			
		||||
				if err := ioutil.WriteFile(dataPath, []byte(tc.jsonFile), 0644); err != nil {
 | 
			
		||||
				if err := os.WriteFile(dataPath, []byte(tc.jsonFile), 0644); err != nil {
 | 
			
		||||
					t.Fatalf("error creating %s: %s", dataPath, err)
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,6 @@ package csi
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"math/rand"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
@@ -1065,7 +1064,7 @@ func TestUnmounterTeardown(t *testing.T) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestIsCorruptedDir(t *testing.T) {
 | 
			
		||||
	existingMountPath, err := ioutil.TempDir(os.TempDir(), "blobfuse-csi-mount-test")
 | 
			
		||||
	existingMountPath, err := os.MkdirTemp(os.TempDir(), "blobfuse-csi-mount-test")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("failed to create tmp dir: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,6 @@ import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"flag"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"testing"
 | 
			
		||||
@@ -143,7 +142,7 @@ func TestSaveVolumeData(t *testing.T) {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// validate content
 | 
			
		||||
		data, err := ioutil.ReadFile(file)
 | 
			
		||||
		data, err := os.ReadFile(file)
 | 
			
		||||
		if !tc.shouldFail && err != nil {
 | 
			
		||||
			t.Errorf("failed to read data file: %v", err)
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,6 @@ import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
@@ -205,7 +204,7 @@ func (f *NodeClient) NodePublishVolume(ctx context.Context, req *csipb.NodePubli
 | 
			
		||||
	// "Creation of target_path is the responsibility of the SP."
 | 
			
		||||
	// Our plugin depends on it.
 | 
			
		||||
	if req.VolumeCapability.GetBlock() != nil {
 | 
			
		||||
		if err := ioutil.WriteFile(req.TargetPath, []byte{}, 0644); err != nil {
 | 
			
		||||
		if err := os.WriteFile(req.TargetPath, []byte{}, 0644); err != nil {
 | 
			
		||||
			return nil, fmt.Errorf("cannot create target path %s for block file: %s", req.TargetPath, err)
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,6 @@ limitations under the License.
 | 
			
		||||
package volume_test
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"testing"
 | 
			
		||||
@@ -60,7 +59,7 @@ func TestMetricsDuGetCapacity(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Write a file and expect Used to increase
 | 
			
		||||
	ioutil.WriteFile(filepath.Join(tmpDir, "f1"), []byte("Hello World"), os.ModeTemporary)
 | 
			
		||||
	os.WriteFile(filepath.Join(tmpDir, "f1"), []byte("Hello World"), os.ModeTemporary)
 | 
			
		||||
	actual, err = metrics.GetMetrics()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Errorf("Unexpected error when calling GetMetrics %v", err)
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,6 @@ package projected
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"reflect"
 | 
			
		||||
@@ -874,7 +873,7 @@ func TestCollectDataWithServiceAccountToken(t *testing.T) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newTestHost(t *testing.T, clientset clientset.Interface) (string, volume.VolumeHost) {
 | 
			
		||||
	tempDir, err := ioutil.TempDir("", "projected_volume_test.")
 | 
			
		||||
	tempDir, err := os.MkdirTemp("", "projected_volume_test.")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("can't make a temp rootdir: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
@@ -1139,7 +1138,7 @@ func TestPluginOptional(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
	datadirPath := filepath.Join(volumePath, datadir)
 | 
			
		||||
 | 
			
		||||
	infos, err := ioutil.ReadDir(volumePath)
 | 
			
		||||
	infos, err := os.ReadDir(volumePath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("couldn't find volume path, %s", volumePath)
 | 
			
		||||
	}
 | 
			
		||||
@@ -1151,7 +1150,7 @@ func TestPluginOptional(t *testing.T) {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	infos, err = ioutil.ReadDir(datadirPath)
 | 
			
		||||
	infos, err = os.ReadDir(datadirPath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("couldn't find volume data path, %s", datadirPath)
 | 
			
		||||
	}
 | 
			
		||||
@@ -1292,7 +1291,7 @@ func doTestSecretDataInVolume(volumePath string, secret v1.Secret, t *testing.T)
 | 
			
		||||
		if _, err := os.Stat(secretDataHostPath); err != nil {
 | 
			
		||||
			t.Fatalf("SetUp() failed, couldn't find secret data on disk: %v", secretDataHostPath)
 | 
			
		||||
		} else {
 | 
			
		||||
			actualSecretBytes, err := ioutil.ReadFile(secretDataHostPath)
 | 
			
		||||
			actualSecretBytes, err := os.ReadFile(secretDataHostPath)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				t.Fatalf("Couldn't read secret data from: %v", secretDataHostPath)
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,6 @@ package util
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
@@ -327,7 +326,7 @@ func shouldWriteFile(path string, content []byte) (bool, error) {
 | 
			
		||||
		return true, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	contentOnFs, err := ioutil.ReadFile(path)
 | 
			
		||||
	contentOnFs, err := os.ReadFile(path)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return false, err
 | 
			
		||||
	}
 | 
			
		||||
@@ -379,7 +378,7 @@ func (w *AtomicWriter) pathsToRemove(payload map[string]FileProjection, oldTsDir
 | 
			
		||||
 | 
			
		||||
// newTimestampDir creates a new timestamp directory
 | 
			
		||||
func (w *AtomicWriter) newTimestampDir() (string, error) {
 | 
			
		||||
	tsDir, err := ioutil.TempDir(w.targetDir, time.Now().UTC().Format("..2006_01_02_15_04_05."))
 | 
			
		||||
	tsDir, err := os.MkdirTemp(w.targetDir, time.Now().UTC().Format("..2006_01_02_15_04_05."))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		klog.Errorf("%s: unable to create new temp directory: %v", w.logContext, err)
 | 
			
		||||
		return "", err
 | 
			
		||||
@@ -411,11 +410,11 @@ func (w *AtomicWriter) writePayloadToDir(payload map[string]FileProjection, dir
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if err := ioutil.WriteFile(fullPath, content, mode); err != nil {
 | 
			
		||||
		if err := os.WriteFile(fullPath, content, mode); err != nil {
 | 
			
		||||
			klog.Errorf("%s: unable to write file %s with mode %v: %v", w.logContext, fullPath, mode, err)
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
		// Chmod is needed because ioutil.WriteFile() ends up calling
 | 
			
		||||
		// Chmod is needed because os.WriteFile() ends up calling
 | 
			
		||||
		// open(2) to create the file, so the final mode used is "mode &
 | 
			
		||||
		// ~umask". But we want to make sure the specified mode is used
 | 
			
		||||
		// in the file no matter what the umask is.
 | 
			
		||||
 
 | 
			
		||||
@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,6 @@ package fs
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"testing"
 | 
			
		||||
@@ -28,21 +27,21 @@ import (
 | 
			
		||||
 | 
			
		||||
func TestDiskUsage(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	dir1, err := ioutil.TempDir("", "dir_1")
 | 
			
		||||
	dir1, err := os.MkdirTemp("", "dir_1")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("TestDiskUsage failed: %s", err.Error())
 | 
			
		||||
	}
 | 
			
		||||
	defer os.RemoveAll(dir1)
 | 
			
		||||
 | 
			
		||||
	tmpfile1, err := ioutil.TempFile(dir1, "test")
 | 
			
		||||
	tmpfile1, err := os.CreateTemp(dir1, "test")
 | 
			
		||||
	if _, err = tmpfile1.WriteString("just for testing"); err != nil {
 | 
			
		||||
		t.Fatalf("TestDiskUsage failed: %s", err.Error())
 | 
			
		||||
	}
 | 
			
		||||
	dir2, err := ioutil.TempDir(dir1, "dir_2")
 | 
			
		||||
	dir2, err := os.MkdirTemp(dir1, "dir_2")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("TestDiskUsage failed: %s", err.Error())
 | 
			
		||||
	}
 | 
			
		||||
	tmpfile2, err := ioutil.TempFile(dir2, "test")
 | 
			
		||||
	tmpfile2, err := os.CreateTemp(dir2, "test")
 | 
			
		||||
	if _, err = tmpfile2.WriteString("just for testing"); err != nil {
 | 
			
		||||
		t.Fatalf("TestDiskUsage failed: %s", err.Error())
 | 
			
		||||
	}
 | 
			
		||||
@@ -92,7 +91,7 @@ func TestDiskUsage(t *testing.T) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestInfo(t *testing.T) {
 | 
			
		||||
	dir1, err := ioutil.TempDir("", "dir_1")
 | 
			
		||||
	dir1, err := os.MkdirTemp("", "dir_1")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatalf("TestInfo failed: %s", err.Error())
 | 
			
		||||
	}
 | 
			
		||||
@@ -107,7 +106,7 @@ func TestInfo(t *testing.T) {
 | 
			
		||||
	validateInfo(t, availablebytes, capacity, usage, inodesTotal, inodeUsage, inodesFree)
 | 
			
		||||
 | 
			
		||||
	// should pass for file
 | 
			
		||||
	tmpfile1, err := ioutil.TempFile(dir1, "test")
 | 
			
		||||
	tmpfile1, err := os.CreateTemp(dir1, "test")
 | 
			
		||||
	if _, err = tmpfile1.WriteString("just for testing"); err != nil {
 | 
			
		||||
		t.Fatalf("TestInfo failed: %s", err.Error())
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,6 @@ package common
 | 
			
		||||
import (
 | 
			
		||||
	"bufio"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/exec"
 | 
			
		||||
	"regexp"
 | 
			
		||||
@@ -144,7 +143,7 @@ func doRunXFSQuotaCommand(mountpoint string, mountsFile, command string) (string
 | 
			
		||||
// See https://bugzilla.redhat.com/show_bug.cgi?id=237120 for an example
 | 
			
		||||
// of the problem that could be caused if this were to happen.
 | 
			
		||||
func runXFSQuotaCommand(mountpoint string, command string) (string, error) {
 | 
			
		||||
	tmpMounts, err := ioutil.TempFile("", "mounts")
 | 
			
		||||
	tmpMounts, err := os.CreateTemp("", "mounts")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "", fmt.Errorf("cannot create temporary mount file: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,6 @@ package fsquota
 | 
			
		||||
import (
 | 
			
		||||
	"bufio"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"regexp"
 | 
			
		||||
@@ -267,7 +266,7 @@ func writeProjectFile(base *os.File, projects []projectType) (string, error) {
 | 
			
		||||
		return "", err
 | 
			
		||||
	}
 | 
			
		||||
	mode := stat.Mode() & os.ModePerm
 | 
			
		||||
	f, err := ioutil.TempFile(filepath.Dir(oname), filepath.Base(oname))
 | 
			
		||||
	f, err := os.CreateTemp(filepath.Dir(oname), filepath.Base(oname))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "", err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,6 @@ package fsquota
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"testing"
 | 
			
		||||
@@ -97,7 +96,7 @@ type mountpointTest struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func testBackingDev1(testcase backingDevTest) error {
 | 
			
		||||
	tmpfile, err := ioutil.TempFile("", "backingdev")
 | 
			
		||||
	tmpfile, err := os.CreateTemp("", "backingdev")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
@@ -502,7 +501,7 @@ var quotaTestCases = []quotaTestCase{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func compareProjectsFiles(t *testing.T, testcase quotaTestCase, projectsFile string, projidFile string, enabled bool) {
 | 
			
		||||
	bytes, err := ioutil.ReadFile(projectsFile)
 | 
			
		||||
	bytes, err := os.ReadFile(projectsFile)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Error(err.Error())
 | 
			
		||||
	} else {
 | 
			
		||||
@@ -515,7 +514,7 @@ func compareProjectsFiles(t *testing.T, testcase quotaTestCase, projectsFile str
 | 
			
		||||
			t.Errorf("Case %v /etc/projects miscompare: expected\n`%s`\ngot\n`%s`\n", testcase.path, p, s)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	bytes, err = ioutil.ReadFile(projidFile)
 | 
			
		||||
	bytes, err = os.ReadFile(projidFile)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Error(err.Error())
 | 
			
		||||
	} else {
 | 
			
		||||
@@ -598,7 +597,7 @@ func runCaseDisabled(t *testing.T, testcase quotaTestCase, seq int) bool {
 | 
			
		||||
 | 
			
		||||
func testAddRemoveQuotas(t *testing.T, enabled bool) {
 | 
			
		||||
	defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.LocalStorageCapacityIsolationFSQuotaMonitoring, enabled)()
 | 
			
		||||
	tmpProjectsFile, err := ioutil.TempFile("", "projects")
 | 
			
		||||
	tmpProjectsFile, err := os.CreateTemp("", "projects")
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		_, err = tmpProjectsFile.WriteString(projectsHeader)
 | 
			
		||||
	}
 | 
			
		||||
@@ -607,7 +606,7 @@ func testAddRemoveQuotas(t *testing.T, enabled bool) {
 | 
			
		||||
	}
 | 
			
		||||
	projectsFile = tmpProjectsFile.Name()
 | 
			
		||||
	tmpProjectsFile.Close()
 | 
			
		||||
	tmpProjidFile, err := ioutil.TempFile("", "projid")
 | 
			
		||||
	tmpProjidFile, err := os.CreateTemp("", "projid")
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		_, err = tmpProjidFile.WriteString(projidHeader)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,6 @@ limitations under the License.
 | 
			
		||||
package hostutil
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"testing"
 | 
			
		||||
@@ -193,12 +192,12 @@ func TestGetSELinuxSupport(t *testing.T) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func writeFile(content string) (string, string, error) {
 | 
			
		||||
	tempDir, err := ioutil.TempDir("", "mounter_shared_test")
 | 
			
		||||
	tempDir, err := os.MkdirTemp("", "mounter_shared_test")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "", "", err
 | 
			
		||||
	}
 | 
			
		||||
	filename := filepath.Join(tempDir, "mountinfo")
 | 
			
		||||
	err = ioutil.WriteFile(filename, []byte(content), 0600)
 | 
			
		||||
	err = os.WriteFile(filename, []byte(content), 0600)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		os.RemoveAll(tempDir)
 | 
			
		||||
		return "", "", err
 | 
			
		||||
 
 | 
			
		||||
@@ -38,7 +38,7 @@ func NewIOHandler() IoUtil {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (handler *osIOHandler) ReadFile(filename string) ([]byte, error) {
 | 
			
		||||
	return ioutil.ReadFile(filename)
 | 
			
		||||
	return os.ReadFile(filename)
 | 
			
		||||
}
 | 
			
		||||
func (handler *osIOHandler) ReadDir(dirname string) ([]os.FileInfo, error) {
 | 
			
		||||
	return ioutil.ReadDir(dirname)
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,6 @@ limitations under the License.
 | 
			
		||||
package util
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"testing"
 | 
			
		||||
@@ -202,7 +201,7 @@ func TestGetNestedMountpoints(t *testing.T) {
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	for _, test := range tc {
 | 
			
		||||
		dir, err := ioutil.TempDir("", "TestMakeNestedMountpoints.")
 | 
			
		||||
		dir, err := os.MkdirTemp("", "TestMakeNestedMountpoints.")
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			t.Errorf("Unexpected error trying to create temp directory: %v", err)
 | 
			
		||||
			return
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,6 @@ package util
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"reflect"
 | 
			
		||||
@@ -173,7 +172,7 @@ func LoadPodFromFile(filePath string) (*v1.Pod, error) {
 | 
			
		||||
	if filePath == "" {
 | 
			
		||||
		return nil, fmt.Errorf("file path not specified")
 | 
			
		||||
	}
 | 
			
		||||
	podDef, err := ioutil.ReadFile(filePath)
 | 
			
		||||
	podDef, err := os.ReadFile(filePath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("failed to read file path %s: %+v", filePath, err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,6 @@ limitations under the License.
 | 
			
		||||
package util
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"reflect"
 | 
			
		||||
	"runtime"
 | 
			
		||||
@@ -93,7 +92,7 @@ spec:
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, test := range tests {
 | 
			
		||||
		tempFile, err := ioutil.TempFile("", "podfile")
 | 
			
		||||
		tempFile, err := os.CreateTemp("", "podfile")
 | 
			
		||||
		defer os.Remove(tempFile.Name())
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			t.Fatalf("cannot create temporary file: %v", err)
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,6 @@ package volumepathhandler
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
 | 
			
		||||
@@ -279,12 +278,12 @@ func (v VolumePathHandler) IsDeviceBindMountExist(mapPath string) (bool, error)
 | 
			
		||||
// GetDeviceBindMountRefs searches bind mounts under global map path
 | 
			
		||||
func (v VolumePathHandler) GetDeviceBindMountRefs(devPath string, mapPath string) ([]string, error) {
 | 
			
		||||
	var refs []string
 | 
			
		||||
	files, err := ioutil.ReadDir(mapPath)
 | 
			
		||||
	files, err := os.ReadDir(mapPath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	for _, file := range files {
 | 
			
		||||
		if file.Mode()&os.ModeDevice != os.ModeDevice {
 | 
			
		||||
		if file.Type()&os.ModeDevice != os.ModeDevice {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		filename := file.Name()
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,6 @@ package volumepathhandler
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/exec"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
@@ -133,7 +132,7 @@ func getLoopDeviceFromSysfs(path string) (string, error) {
 | 
			
		||||
		backingFile := fmt.Sprintf("%s/loop/backing_file", device)
 | 
			
		||||
 | 
			
		||||
		// The contents of this file is the absolute path of "path".
 | 
			
		||||
		data, err := ioutil.ReadFile(backingFile)
 | 
			
		||||
		data, err := os.ReadFile(backingFile)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user