internal/states: deprecate io/ioutil (#320)

This commit is contained in:
Adrian Mester 2023-09-07 12:18:43 +03:00 committed by GitHub
parent 6334237a46
commit 408470481e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 13 deletions

View File

@ -8,7 +8,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
version "github.com/hashicorp/go-version" 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 // 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 // generally not huge and we need to do be able to sniff for a version
// number before full parsing. // number before full parsing.
src, err := ioutil.ReadAll(r) src, err := io.ReadAll(r)
if err != nil { if err != nil {
diags = diags.Append(tfdiags.Sourceless( diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error, tfdiags.Error,

View File

@ -5,7 +5,6 @@ package statefile
import ( import (
"bytes" "bytes"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
@ -17,7 +16,7 @@ import (
func TestRoundtrip(t *testing.T) { func TestRoundtrip(t *testing.T) {
const dir = "testdata/roundtrip" const dir = "testdata/roundtrip"
entries, err := ioutil.ReadDir(dir) entries, err := os.ReadDir(dir)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -37,7 +36,7 @@ func TestRoundtrip(t *testing.T) {
outName := name + outSuffix outName := name + outSuffix
t.Run(name, func(t *testing.T) { 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -8,7 +8,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
@ -514,7 +513,7 @@ func (s *Filesystem) lockInfoPath() string {
// lockInfo returns the data in a lock info file // lockInfo returns the data in a lock info file
func (s *Filesystem) lockInfo() (*LockInfo, error) { func (s *Filesystem) lockInfo() (*LockInfo, error) {
path := s.lockInfoPath() path := s.lockInfoPath()
infoData, err := ioutil.ReadFile(path) infoData, err := os.ReadFile(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -534,7 +533,7 @@ func (s *Filesystem) writeLockInfo(info *LockInfo) error {
info.Created = time.Now().UTC() info.Created = time.Now().UTC()
log.Printf("[TRACE] statemgr.Filesystem: writing lock metadata to %s", path) 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 { if err != nil {
return fmt.Errorf("could not write lock info for %q: %s", s.readPath, err) return fmt.Errorf("could not write lock info for %q: %s", s.readPath, err)
} }

View File

@ -4,7 +4,6 @@
package statemgr package statemgr
import ( import (
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -133,7 +132,7 @@ func TestFilesystem_writeWhileLocked(t *testing.T) {
func TestFilesystem_pathOut(t *testing.T) { func TestFilesystem_pathOut(t *testing.T) {
defer testOverrideVersion(t, "1.2.3")() defer testOverrideVersion(t, "1.2.3")()
f, err := ioutil.TempFile("", "tf") f, err := os.CreateTemp("", "tf")
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -149,7 +148,7 @@ func TestFilesystem_pathOut(t *testing.T) {
func TestFilesystem_backup(t *testing.T) { func TestFilesystem_backup(t *testing.T) {
defer testOverrideVersion(t, "1.2.3")() defer testOverrideVersion(t, "1.2.3")()
f, err := ioutil.TempFile("", "tf") f, err := os.CreateTemp("", "tf")
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -344,7 +343,7 @@ func TestFilesystem_impl(t *testing.T) {
} }
func testFilesystem(t *testing.T) *Filesystem { func testFilesystem(t *testing.T) *Filesystem {
f, err := ioutil.TempFile("", "tf") f, err := os.CreateTemp("", "tf")
if err != nil { if err != nil {
t.Fatalf("failed to create temporary file %s", err) 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 // Make sure we can refresh while the state is locked
func TestFilesystem_refreshWhileLocked(t *testing.T) { func TestFilesystem_refreshWhileLocked(t *testing.T) {
defer testOverrideVersion(t, "1.2.3")() defer testOverrideVersion(t, "1.2.3")()
f, err := ioutil.TempFile("", "tf") f, err := os.CreateTemp("", "tf")
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }