Skip to content

Commit

Permalink
Remove occurrences of ioutil from codebase (#2514)
Browse files Browse the repository at this point in the history
ioutil is deprecated. Remove it.
  • Loading branch information
kislaykishore authored Sep 20, 2024
1 parent 781f497 commit 37b7cc3
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 126 deletions.
3 changes: 1 addition & 2 deletions internal/contentcache/contentcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package contentcache_test
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"sync"
"testing"
Expand Down Expand Up @@ -76,7 +75,7 @@ func TestReadWriteMetadataCheckpointFile(t *testing.T) {
metadataFileName, err := contentCache.WriteMetadataCheckpointFile(objectMetadata.ObjectName, &objectMetadata)
AssertEq(err, nil)
newObjectMetadata := contentcache.CacheFileObjectMetadata{}
contents, err := ioutil.ReadFile(metadataFileName)
contents, err := os.ReadFile(metadataFileName)
AssertEq(err, nil)
err = json.Unmarshal(contents, &newObjectMetadata)
AssertEq(err, nil)
Expand Down
11 changes: 5 additions & 6 deletions internal/fs/all_buckets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package fs_test

import (
"io"
"io/ioutil"
"os"
"path"

Expand Down Expand Up @@ -56,13 +55,13 @@ func (t *AllBucketsTest) SetUpTestSuite() {
////////////////////////////////////////////////////////////////////////

func (t *AllBucketsTest) BaseDir_Ls() {
_, err := ioutil.ReadDir(mntDir)
_, err := os.ReadDir(mntDir)
ExpectThat(err, Error(HasSubstr("operation not supported")))
}

func (t *AllBucketsTest) BaseDir_Write() {
filename := path.Join(mntDir, "foo")
err := ioutil.WriteFile(
err := os.WriteFile(
filename, []byte("content"), os.FileMode(0644))
ExpectThat(err, Error(HasSubstr("input/output error")))
}
Expand All @@ -72,7 +71,7 @@ func (t *AllBucketsTest) BaseDir_Rename() {
ExpectThat(err, Error(HasSubstr("operation not supported")))

filename := path.Join(mntDir + "/bucket-0/foo")
err = ioutil.WriteFile(
err = os.WriteFile(
filename, []byte("content"), os.FileMode(0644))
AssertEq(nil, err)

Expand All @@ -92,7 +91,7 @@ func (t *AllBucketsTest) SingleBucket_ReadAfterWrite() {
const contents = "tacoburritoenchilada"
AssertEq(
nil,
ioutil.WriteFile(
os.WriteFile(
filename,
[]byte(contents),
os.FileMode(0644)))
Expand Down Expand Up @@ -143,7 +142,7 @@ func (t *AllBucketsTest) SingleBucket_ReadAfterWrite() {
t.f1 = nil

// Read back its contents.
fileContents, err := ioutil.ReadFile(filename)
fileContents, err := os.ReadFile(filename)

AssertEq(nil, err)
ExpectEq("000o111ritoenchilada222", string(fileContents))
Expand Down
15 changes: 7 additions & 8 deletions internal/fs/caching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package fs_test

import (
"context"
"io/ioutil"
"os"
"path"
"time"
Expand Down Expand Up @@ -124,15 +123,15 @@ func (t *CachingTest) FileCreatedRemotely() {
ExpectEq(len(contents), fi.Size())

// And read it.
b, err := ioutil.ReadFile(path.Join(mntDir, name))
b, err := os.ReadFile(path.Join(mntDir, name))
AssertEq(nil, err)
ExpectEq(contents, string(b))

// And overwrite it, and read it back again.
err = ioutil.WriteFile(path.Join(mntDir, name), []byte("burrito"), 0500)
err = os.WriteFile(path.Join(mntDir, name), []byte("burrito"), 0500)
AssertEq(nil, err)

b, err = ioutil.ReadFile(path.Join(mntDir, name))
b, err = os.ReadFile(path.Join(mntDir, name))
AssertEq(nil, err)
ExpectEq("burrito", string(b))
}
Expand All @@ -143,7 +142,7 @@ func (t *CachingTest) FileChangedRemotely() {
var err error

// Create a file via the file system.
err = ioutil.WriteFile(path.Join(mntDir, name), []byte("taco"), 0500)
err = os.WriteFile(path.Join(mntDir, name), []byte("taco"), 0500)
AssertEq(nil, err)

// Overwrite the object in GCS.
Expand All @@ -169,7 +168,7 @@ func (t *CachingTest) FileChangedRemotely() {
ExpectEq(len("burrito"), fi.Size())

// Reading should work as expected.
b, err := ioutil.ReadFile(path.Join(mntDir, name))
b, err := os.ReadFile(path.Join(mntDir, name))
AssertEq(nil, err)
ExpectEq("burrito", string(b))
}
Expand Down Expand Up @@ -254,7 +253,7 @@ func (t *CachingTest) TypeOfNameChanges_LocalModifier() {
err = os.Remove(path.Join(mntDir, name))
AssertEq(nil, err)

err = ioutil.WriteFile(path.Join(mntDir, name), []byte("taco"), 0400)
err = os.WriteFile(path.Join(mntDir, name), []byte("taco"), 0400)
AssertEq(nil, err)

// All caches should have been updated.
Expand Down Expand Up @@ -369,7 +368,7 @@ func (t *CachingWithImplicitDirsTest) SymlinksWork() {
fileName := path.Join(mntDir, "foo")
const contents = "taco"

err = ioutil.WriteFile(fileName, []byte(contents), 0400)
err = os.WriteFile(fileName, []byte(contents), 0400)
AssertEq(nil, err)

// Create a symlink to it.
Expand Down
13 changes: 6 additions & 7 deletions internal/fs/foreign_modifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"math/rand"
"os"
"path"
Expand Down Expand Up @@ -500,7 +499,7 @@ func (t *ForeignModsTest) ReadFromFile_Small() {
defer func() { AssertEq(nil, f.Close()) }()

// Read its entire contents.
slice, err := ioutil.ReadAll(f)
slice, err := io.ReadAll(f)
AssertEq(nil, err)
ExpectEq("tacoburritoenchilada", string(slice))

Expand Down Expand Up @@ -649,11 +648,11 @@ func (t *ForeignModsTest) ObjectIsOverwritten_File() {
ExpectEq(1, fi.Sys().(*syscall.Stat_t).Nlink)

// Reading from the old file handle should give the old data.
contents, err := ioutil.ReadAll(f1)
contents, err := io.ReadAll(f1)
AssertEq(nil, err)
ExpectEq("taco", string(contents))

contents, err = ioutil.ReadAll(f2)
contents, err = io.ReadAll(f2)
AssertEq(nil, err)
ExpectEq("burrito", string(contents))
}
Expand Down Expand Up @@ -821,7 +820,7 @@ func (t *ForeignModsTest) Mtime() {
Metadata: map[string]string{
"gcsfuse_mtime": expected.UTC().Format(time.RFC3339Nano),
},
Contents: ioutil.NopCloser(strings.NewReader("")),
Contents: io.NopCloser(strings.NewReader("")),
}

_, err = bucket.CreateObject(ctx, req)
Expand All @@ -845,7 +844,7 @@ func (t *ForeignModsTest) RemoteMtimeChange() {
Metadata: map[string]string{
"gcsfuse_mtime": time.Now().UTC().Format(time.RFC3339Nano),
},
Contents: ioutil.NopCloser(strings.NewReader("")),
Contents: io.NopCloser(strings.NewReader("")),
})

AssertEq(nil, err)
Expand Down Expand Up @@ -885,7 +884,7 @@ func (t *ForeignModsTest) Symlink() {
Metadata: map[string]string{
"gcsfuse_symlink_target": "bar/baz",
},
Contents: ioutil.NopCloser(strings.NewReader("")),
Contents: io.NopCloser(strings.NewReader("")),
}

_, err = bucket.CreateObject(ctx, req)
Expand Down
3 changes: 1 addition & 2 deletions internal/fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"os/signal"
Expand Down Expand Up @@ -177,7 +176,7 @@ func (t *fsTest) SetUpTestSuite() {
t.serverCfg.DirPerms = dirPerms

// Set up a temporary directory for mounting.
mntDir, err = ioutil.TempDir("", "fs_test")
mntDir, err = os.MkdirTemp("", "fs_test")
AssertEq(nil, err)

// Create a file system server.
Expand Down
Loading

0 comments on commit 37b7cc3

Please sign in to comment.