Skip to content

Commit

Permalink
Replace deprecated ioutil calls.
Browse files Browse the repository at this point in the history
Change-Id: I212ad658ec642bfc76daf8ea578196015c72f40e
  • Loading branch information
hanwen committed Oct 4, 2024
1 parent f829e36 commit a442e49
Show file tree
Hide file tree
Showing 38 changed files with 129 additions and 165 deletions.
9 changes: 4 additions & 5 deletions benchmark/stat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package benchmark

import (
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -68,7 +67,7 @@ func TestNewStatFs(t *testing.T) {

wd := setupFS(fs, 1, t)

names, err := ioutil.ReadDir(wd)
names, err := os.ReadDir(wd)
if err != nil {
t.Fatalf("failed: %v", err)
}
Expand All @@ -83,14 +82,14 @@ func TestNewStatFs(t *testing.T) {
if !fi.IsDir() {
t.Error("mode", fi)
}
names, err = ioutil.ReadDir(wd + "/sub")
names, err = os.ReadDir(wd + "/sub")
if err != nil {
t.Fatalf("failed: %v", err)
}
if len(names) != 2 {
t.Error("readdir /sub", names)
}
names, err = ioutil.ReadDir(wd + "/sub/dir")
names, err = os.ReadDir(wd + "/sub/dir")
if err != nil {
t.Fatalf("failed: %v", err)
}
Expand Down Expand Up @@ -237,7 +236,7 @@ func BenchmarkCFuseThreadedStat(b *testing.B) {
out = append(out, k)
}

f, err := ioutil.TempFile("", "")
f, err := os.CreateTemp("", "")
if err != nil {
b.Fatalf("failed: %v", err)
}
Expand Down
11 changes: 5 additions & 6 deletions fs/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"log"
"os"
"sync"
Expand Down Expand Up @@ -98,12 +97,12 @@ func TestKeepCache(t *testing.T) {
root := &keepCacheRoot{}
mntDir, _ := testMount(t, root, nil)

c1, err := ioutil.ReadFile(mntDir + "/keep")
c1, err := os.ReadFile(mntDir + "/keep")
if err != nil {
t.Fatalf("read keep 1: %v", err)
}

c2, err := ioutil.ReadFile(mntDir + "/keep")
c2, err := os.ReadFile(mntDir + "/keep")
if err != nil {
t.Fatalf("read keep 2: %v", err)
}
Expand All @@ -116,20 +115,20 @@ func TestKeepCache(t *testing.T) {
t.Errorf("NotifyContent: %v", s)
}

c3, err := ioutil.ReadFile(mntDir + "/keep")
c3, err := os.ReadFile(mntDir + "/keep")
if err != nil {
t.Fatalf("read keep 3: %v", err)
}
if bytes.Compare(c2, c3) == 0 {
t.Errorf("keep read 3 got %q want different", c3)
}

nc1, err := ioutil.ReadFile(mntDir + "/nokeep")
nc1, err := os.ReadFile(mntDir + "/nokeep")
if err != nil {
t.Fatalf("read keep 1: %v", err)
}

nc2, err := ioutil.ReadFile(mntDir + "/nokeep")
nc2, err := os.ReadFile(mntDir + "/nokeep")
if err != nil {
t.Fatalf("read keep 2: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions fs/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package fs_test

import (
"fmt"
"io/ioutil"
"log"
"os"

Expand All @@ -17,7 +16,7 @@ import (
// ExampleMount shows how to create a loopback file system, and
// mounting it onto a directory
func Example_mount() {
mntDir, _ := ioutil.TempDir("", "")
mntDir, _ := os.MkdirTemp("", "")
home := os.Getenv("HOME")
// Make $HOME available on a mount dir under /tmp/ . Caution:
// write operations are also mirrored.
Expand Down
3 changes: 1 addition & 2 deletions fs/forget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package fs
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -97,7 +96,7 @@ func TestForget(t *testing.T) {
}

log.Println("dropping cache")
if err := ioutil.WriteFile("/proc/sys/vm/drop_caches", []byte("2"), 0644); err != nil {
if err := os.WriteFile("/proc/sys/vm/drop_caches", []byte("2"), 0644); err != nil {

}
time.Sleep(time.Second)
Expand Down
4 changes: 2 additions & 2 deletions fs/inmemory_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package fs_test

import (
"context"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"syscall"
Expand Down Expand Up @@ -75,7 +75,7 @@ func (root *inMemoryFS) OnAdd(ctx context.Context) {
// read/write logic for the file is provided by the MemRegularFile type.
func Example() {
// This is where we'll mount the FS
mntDir, _ := ioutil.TempDir("", "")
mntDir, _ := os.MkdirTemp("", "")

root := &inMemoryFS{}
server, err := fs.Mount(mntDir, root, &fs.Options{
Expand Down
5 changes: 2 additions & 3 deletions fs/loopback_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package fs

import (
"bytes"
"io/ioutil"
"os"
"sync"
"syscall"
Expand Down Expand Up @@ -115,7 +114,7 @@ func TestCopyFileRange(t *testing.T) {
if err != nil {
t.Fatalf("Close dst: %v", err)
}
c, err := ioutil.ReadFile(tc.mntDir + "/dst")
c, err := os.ReadFile(tc.mntDir + "/dst")
if err != nil {
t.Fatalf("ReadFile: %v", err)
}
Expand Down Expand Up @@ -153,7 +152,7 @@ func waitMount(mnt string) error {
if err != nil {
return err
}
content, err := ioutil.ReadFile("/proc/self/mounts")
content, err := os.ReadFile("/proc/self/mounts")
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions fs/maxwrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package fs
import (
"context"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -245,7 +245,7 @@ func bdiReadahead(mnt string) int {
panic(err)
}
path := fmt.Sprintf("/sys/class/bdi/%d:%d/read_ahead_kb", unix.Major(uint64(st.Dev)), unix.Minor(uint64(st.Dev)))
buf, err := ioutil.ReadFile(path)
buf, err := os.ReadFile(path)
if err != nil {
panic(err)
}
Expand Down
7 changes: 3 additions & 4 deletions fs/mem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"math/rand"
"os"
"reflect"
Expand Down Expand Up @@ -166,11 +165,11 @@ func TestDataFile(t *testing.T) {
}

replace := []byte("replaced!")
if err := ioutil.WriteFile(mntDir+"/file", replace, 0644); err != nil {
if err := os.WriteFile(mntDir+"/file", replace, 0644); err != nil {
t.Fatalf("WriteFile: %v", err)
}

if gotBytes, err := ioutil.ReadFile(mntDir + "/file"); err != nil {
if gotBytes, err := os.ReadFile(mntDir + "/file"); err != nil {
t.Fatalf("ReadFile: %v", err)
} else if bytes.Compare(replace, gotBytes) != 0 {
t.Fatalf("read: got %q want %q", gotBytes, replace)
Expand Down Expand Up @@ -198,7 +197,7 @@ func TestDataFileLargeRead(t *testing.T) {
n.AddChild("file", ch, false)
},
})
got, err := ioutil.ReadFile(mntDir + "/file")
got, err := os.ReadFile(mntDir + "/file")
if err != nil {
t.Fatalf("ReadFile: %v", err)
}
Expand Down
7 changes: 3 additions & 4 deletions fs/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package fs
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -42,7 +41,7 @@ type testCase struct {

// writeOrig writes a file into the backing directory of the loopback mount
func (tc *testCase) writeOrig(path, content string, mode os.FileMode) {
if err := ioutil.WriteFile(filepath.Join(tc.origDir, path), []byte(content), mode); err != nil {
if err := os.WriteFile(filepath.Join(tc.origDir, path), []byte(content), mode); err != nil {
tc.Fatal(err)
}
}
Expand Down Expand Up @@ -219,7 +218,7 @@ func TestReadDirStress(t *testing.T) {
// Create 110 entries
for i := 0; i < 110; i++ {
name := fmt.Sprintf("file%036x", i)
if err := ioutil.WriteFile(filepath.Join(tc.mntDir, name), []byte("hello"), 0644); err != nil {
if err := os.WriteFile(filepath.Join(tc.mntDir, name), []byte("hello"), 0644); err != nil {
t.Fatalf("WriteFile %q: %v", name, err)
}
}
Expand Down Expand Up @@ -394,7 +393,7 @@ func TestPosix(t *testing.T) {
func TestOpenDirectIO(t *testing.T) {
// Apparently, tmpfs does not allow O_DIRECT, so try to create
// a test temp directory in /var/tmp.
ext4Dir, err := ioutil.TempDir("/var/tmp", "go-fuse.TestOpenDirectIO")
ext4Dir, err := os.MkdirTemp("/var/tmp", "go-fuse.TestOpenDirectIO")
if err != nil {
t.Fatalf("MkdirAll: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions fs/windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package fs_test

import (
"bytes"
"io/ioutil"
"os"
"syscall"
"testing"
Expand Down Expand Up @@ -34,11 +33,11 @@ func TestWindowsEmulations(t *testing.T) {

data := []byte("hello")
nm := mntDir + "/file"
if err := ioutil.WriteFile(nm, data, 0644); err != nil {
if err := os.WriteFile(nm, data, 0644); err != nil {
t.Fatal(err)
}

if got, err := ioutil.ReadFile(nm); err != nil {
if got, err := os.ReadFile(nm); err != nil {
t.Fatal(err)
} else if bytes.Compare(got, data) != 0 {
t.Fatalf("got %q want %q", got, data)
Expand Down
7 changes: 3 additions & 4 deletions fs/zip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"archive/zip"
"bytes"
"context"
"io/ioutil"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -88,7 +87,7 @@ func TestZipFS(t *testing.T) {
}
continue
}
c, err := ioutil.ReadFile(filepath.Join(mntDir, k))
c, err := os.ReadFile(filepath.Join(mntDir, k))
if err != nil {
t.Fatal(err)
}
Expand All @@ -97,7 +96,7 @@ func TestZipFS(t *testing.T) {
}
}

entries, err := ioutil.ReadDir(mntDir)
entries, err := os.ReadDir(mntDir)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -138,7 +137,7 @@ func TestZipFSOnAdd(t *testing.T) {
}
defer server.Unmount()

c, err := ioutil.ReadFile(mnt + "/sub/dir/subdir/subfile")
c, err := os.ReadFile(mnt + "/sub/dir/subdir/subfile")
if err != nil {
t.Fatal("ReadFile", err)
}
Expand Down
4 changes: 2 additions & 2 deletions fs/zipfs_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -51,7 +51,7 @@ func (zf *zipFile) Open(ctx context.Context, flags uint32) (fs.FileHandle, uint3
if err != nil {
return nil, 0, syscall.EIO
}
content, err := ioutil.ReadAll(rc)
content, err := io.ReadAll(rc)
if err != nil {
return nil, 0, syscall.EIO
}
Expand Down
17 changes: 3 additions & 14 deletions fuse/mount_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package fuse

import (
"fmt"
"io/ioutil"
"os"
"syscall"
"testing"
Expand All @@ -17,11 +16,7 @@ import (
// In this test, we simulate a privileged parent by using the `fusermount` suid
// helper.
func TestMountDevFd(t *testing.T) {
realMountPoint, err := ioutil.TempDir("", t.Name())
if err != nil {
t.Fatal(err)
}
defer syscall.Rmdir(realMountPoint)
realMountPoint := t.TempDir()

// Call the fusermount suid helper to obtain the file descriptor in place
// of a privileged parent.
Expand Down Expand Up @@ -87,10 +82,7 @@ func TestMountMaxWrite(t *testing.T) {
for _, o := range opts {
name := fmt.Sprintf("MaxWrite%d", o.MaxWrite)
t.Run(name, func(t *testing.T) {
mnt, err := ioutil.TempDir("", name)
if err != nil {
t.Fatal(err)
}
mnt := t.TempDir()
fs := NewDefaultRawFileSystem()
srv, err := NewServer(fs, mnt, &o)
if err != nil {
Expand All @@ -108,10 +100,7 @@ func TestMountMaxWrite(t *testing.T) {
// The mount options are a comma-separated string like this:
// rw,nosuid,nodev,relatime,user_id=1026,group_id=1026
func mountCheckOptions(t *testing.T, opts MountOptions) (info mountinfo.Info) {
mnt, err := ioutil.TempDir("", t.Name())
if err != nil {
t.Fatal(err)
}
mnt := t.TempDir()
fs := NewDefaultRawFileSystem()
srv, err := NewServer(fs, mnt, &opts)
if err != nil {
Expand Down
Loading

0 comments on commit a442e49

Please sign in to comment.