From 408470481ea28cb7ba73102d4d02b76de701c96b Mon Sep 17 00:00:00 2001 From: Adrian Mester <33199+adrianmester@users.noreply.github.com> Date: Thu, 7 Sep 2023 12:18:43 +0300 Subject: [PATCH] internal/states: deprecate io/ioutil (#320) --- internal/states/statefile/read.go | 3 +-- internal/states/statefile/roundtrip_test.go | 5 ++--- internal/states/statemgr/filesystem.go | 5 ++--- internal/states/statemgr/filesystem_test.go | 9 ++++----- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/internal/states/statefile/read.go b/internal/states/statefile/read.go index 19b2cb7238..8a09dd42d0 100644 --- a/internal/states/statefile/read.go +++ b/internal/states/statefile/read.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" version "github.com/hashicorp/go-version" @@ -60,7 +59,7 @@ func Read(r io.Reader) (*File, error) { // We actually just buffer the whole thing in memory, because states are // generally not huge and we need to do be able to sniff for a version // number before full parsing. - src, err := ioutil.ReadAll(r) + src, err := io.ReadAll(r) if err != nil { diags = diags.Append(tfdiags.Sourceless( tfdiags.Error, diff --git a/internal/states/statefile/roundtrip_test.go b/internal/states/statefile/roundtrip_test.go index 208310b22a..a74e9aba06 100644 --- a/internal/states/statefile/roundtrip_test.go +++ b/internal/states/statefile/roundtrip_test.go @@ -5,7 +5,6 @@ package statefile import ( "bytes" - "io/ioutil" "os" "path/filepath" "sort" @@ -17,7 +16,7 @@ import ( func TestRoundtrip(t *testing.T) { const dir = "testdata/roundtrip" - entries, err := ioutil.ReadDir(dir) + entries, err := os.ReadDir(dir) if err != nil { t.Fatal(err) } @@ -37,7 +36,7 @@ func TestRoundtrip(t *testing.T) { outName := name + outSuffix t.Run(name, func(t *testing.T) { - oSrcWant, err := ioutil.ReadFile(filepath.Join(dir, outName)) + oSrcWant, err := os.ReadFile(filepath.Join(dir, outName)) if err != nil { t.Fatal(err) } diff --git a/internal/states/statemgr/filesystem.go b/internal/states/statemgr/filesystem.go index ddc5ebb1d9..b658504ade 100644 --- a/internal/states/statemgr/filesystem.go +++ b/internal/states/statemgr/filesystem.go @@ -8,7 +8,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" "os" "path/filepath" @@ -514,7 +513,7 @@ func (s *Filesystem) lockInfoPath() string { // lockInfo returns the data in a lock info file func (s *Filesystem) lockInfo() (*LockInfo, error) { path := s.lockInfoPath() - infoData, err := ioutil.ReadFile(path) + infoData, err := os.ReadFile(path) if err != nil { return nil, err } @@ -534,7 +533,7 @@ func (s *Filesystem) writeLockInfo(info *LockInfo) error { info.Created = time.Now().UTC() log.Printf("[TRACE] statemgr.Filesystem: writing lock metadata to %s", path) - err := ioutil.WriteFile(path, info.Marshal(), 0600) + err := os.WriteFile(path, info.Marshal(), 0600) if err != nil { return fmt.Errorf("could not write lock info for %q: %s", s.readPath, err) } diff --git a/internal/states/statemgr/filesystem_test.go b/internal/states/statemgr/filesystem_test.go index 4ead41764a..25859a86bc 100644 --- a/internal/states/statemgr/filesystem_test.go +++ b/internal/states/statemgr/filesystem_test.go @@ -4,7 +4,6 @@ package statemgr import ( - "io/ioutil" "os" "os/exec" "path/filepath" @@ -133,7 +132,7 @@ func TestFilesystem_writeWhileLocked(t *testing.T) { func TestFilesystem_pathOut(t *testing.T) { defer testOverrideVersion(t, "1.2.3")() - f, err := ioutil.TempFile("", "tf") + f, err := os.CreateTemp("", "tf") if err != nil { t.Fatalf("err: %s", err) } @@ -149,7 +148,7 @@ func TestFilesystem_pathOut(t *testing.T) { func TestFilesystem_backup(t *testing.T) { defer testOverrideVersion(t, "1.2.3")() - f, err := ioutil.TempFile("", "tf") + f, err := os.CreateTemp("", "tf") if err != nil { t.Fatalf("err: %s", err) } @@ -344,7 +343,7 @@ func TestFilesystem_impl(t *testing.T) { } func testFilesystem(t *testing.T) *Filesystem { - f, err := ioutil.TempFile("", "tf") + f, err := os.CreateTemp("", "tf") if err != nil { t.Fatalf("failed to create temporary file %s", err) } @@ -372,7 +371,7 @@ func testFilesystem(t *testing.T) *Filesystem { // Make sure we can refresh while the state is locked func TestFilesystem_refreshWhileLocked(t *testing.T) { defer testOverrideVersion(t, "1.2.3")() - f, err := ioutil.TempFile("", "tf") + f, err := os.CreateTemp("", "tf") if err != nil { t.Fatalf("err: %s", err) }