aboutsummaryrefslogtreecommitdiff
path: root/filesystem
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2022-12-04 13:27:43 -0800
committerEric Biggers <ebiggers3@gmail.com>2022-12-04 14:07:39 -0800
commit02875cef9010633b6689cfd1e2ceec9107b756b4 (patch)
tree9f310eac398e99dd12f42d94967b2e1bf1c7fe83 /filesystem
parent5373b314473b08f13372ab55b551738307a85fbd (diff)
Stop using deprecated package io/ioutil
Since Go 1.16 (which recently became the minimum supported Go version for this project), the package io/ioutil is deprecated in favor of equivalent functionality in the io and os packages. staticcheck warns about this. Address all the warnings by switching to the non-deprecated replacement functions.
Diffstat (limited to 'filesystem')
-rw-r--r--filesystem/filesystem.go7
-rw-r--r--filesystem/filesystem_test.go7
-rw-r--r--filesystem/mountpoint.go9
-rw-r--r--filesystem/mountpoint_test.go9
-rw-r--r--filesystem/path_test.go3
5 files changed, 17 insertions, 18 deletions
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go
index 7852abb..0e1f0c8 100644
--- a/filesystem/filesystem.go
+++ b/filesystem/filesystem.go
@@ -35,7 +35,6 @@ package filesystem
import (
"fmt"
"io"
- "io/ioutil"
"log"
"os"
"os/user"
@@ -335,7 +334,7 @@ func (m *Mount) PolicyPath(descriptor string) string {
// directory and returns a temporary Mount which represents this temporary
// directory. The caller is responsible for removing this temporary directory.
func (m *Mount) tempMount() (*Mount, error) {
- tempDir, err := ioutil.TempDir(filepath.Dir(m.BaseDir()), tempPrefix)
+ tempDir, err := os.MkdirTemp(filepath.Dir(m.BaseDir()), tempPrefix)
return &Mount{Path: tempDir}, err
}
@@ -635,7 +634,7 @@ func (m *Mount) writeData(path string, data []byte, owner *user.User, mode os.Fi
// Write the data to a temporary file, sync it, then rename into place
// so that the operation will be atomic.
dirPath := filepath.Dir(path)
- tempFile, err := ioutil.TempFile(dirPath, tempPrefix)
+ tempFile, err := os.CreateTemp(dirPath, tempPrefix)
if err != nil {
log.Print(err)
if os.IsPermission(err) {
@@ -767,7 +766,7 @@ func readMetadataFileSafe(path string, trustedUser *user.User) ([]byte, int64, e
}
// Read the file contents, allowing at most maxMetadataFileSize bytes.
reader := &io.LimitedReader{R: file, N: maxMetadataFileSize + 1}
- data, err := ioutil.ReadAll(reader)
+ data, err := io.ReadAll(reader)
if err != nil {
return nil, -1, err
}
diff --git a/filesystem/filesystem_test.go b/filesystem/filesystem_test.go
index 79fb133..f9c34ae 100644
--- a/filesystem/filesystem_test.go
+++ b/filesystem/filesystem_test.go
@@ -20,7 +20,6 @@
package filesystem
import (
- "io/ioutil"
"os"
"os/user"
"path/filepath"
@@ -172,7 +171,7 @@ func TestSetupWithAbsoluteSymlink(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- tempDir, err := ioutil.TempDir("", "fscrypt")
+ tempDir, err := os.MkdirTemp("", "fscrypt")
if err != nil {
t.Fatal(err)
}
@@ -519,7 +518,7 @@ func TestLinkedProtector(t *testing.T) {
}
func createFile(path string, size int64) error {
- if err := ioutil.WriteFile(path, []byte{}, 0600); err != nil {
+ if err := os.WriteFile(path, []byte{}, 0600); err != nil {
return err
}
return os.Truncate(path, size)
@@ -532,7 +531,7 @@ func TestReadMetadataFileSafe(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- tempDir, err := ioutil.TempDir("", "fscrypt")
+ tempDir, err := os.MkdirTemp("", "fscrypt")
if err != nil {
t.Fatal(err)
}
diff --git a/filesystem/mountpoint.go b/filesystem/mountpoint.go
index 0b0693b..0abae06 100644
--- a/filesystem/mountpoint.go
+++ b/filesystem/mountpoint.go
@@ -25,7 +25,6 @@ import (
"bufio"
"fmt"
"io"
- "io/ioutil"
"log"
"os"
"path/filepath"
@@ -537,11 +536,15 @@ func getMountFromLink(link string) (*Mount, error) {
}
func (mnt *Mount) getFilesystemUUID() (string, error) {
- dirContents, err := ioutil.ReadDir(uuidDirectory)
+ dirEntries, err := os.ReadDir(uuidDirectory)
if err != nil {
return "", err
}
- for _, fileInfo := range dirContents {
+ for _, dirEntry := range dirEntries {
+ fileInfo, err := dirEntry.Info()
+ if err != nil {
+ continue
+ }
if fileInfo.Mode()&os.ModeSymlink == 0 {
continue // Only interested in UUID symlinks
}
diff --git a/filesystem/mountpoint_test.go b/filesystem/mountpoint_test.go
index 99d4b55..43b5a0d 100644
--- a/filesystem/mountpoint_test.go
+++ b/filesystem/mountpoint_test.go
@@ -26,7 +26,6 @@ package filesystem
import (
"fmt"
- "io/ioutil"
"os"
"path/filepath"
"strings"
@@ -122,7 +121,7 @@ func TestLoadSourceDevice(t *testing.T) {
func TestNondirectoryMountsIgnored(t *testing.T) {
beginLoadMountInfoTest()
defer endLoadMountInfoTest()
- file, err := ioutil.TempFile("", "fscrypt_regfile")
+ file, err := os.CreateTemp("", "fscrypt_regfile")
if err != nil {
t.Fatal(err)
}
@@ -155,7 +154,7 @@ func TestNonLatestMountsIgnored(t *testing.T) {
// Test that escape sequences in the mountinfo file are unescaped correctly.
func TestLoadMountWithSpecialCharacters(t *testing.T) {
- tempDir, err := ioutil.TempDir("", "fscrypt")
+ tempDir, err := os.MkdirTemp("", "fscrypt")
if err != nil {
t.Fatal(err)
}
@@ -296,7 +295,7 @@ func TestRootMountpointIsPreferred(t *testing.T) {
// Test that a mountpoint that is not "/" but still contains all other
// mountpoints is preferred, given independent subtrees.
func TestHighestMountpointIsPreferred(t *testing.T) {
- tempDir, err := ioutil.TempDir("", "fscrypt")
+ tempDir, err := os.MkdirTemp("", "fscrypt")
if err != nil {
t.Fatal(err)
}
@@ -331,7 +330,7 @@ func TestHighestMountpointIsPreferred(t *testing.T) {
// mountpoints are contained in other mountpoints, the chosen Mount is the root
// of a tree of mountpoints whose mounted subtrees contain all mounted subtrees.
func TestLoadContainedSubtreesAndMountpoints(t *testing.T) {
- tempDir, err := ioutil.TempDir("", "fscrypt")
+ tempDir, err := os.MkdirTemp("", "fscrypt")
if err != nil {
t.Fatal(err)
}
diff --git a/filesystem/path_test.go b/filesystem/path_test.go
index 1c59dd5..d325054 100644
--- a/filesystem/path_test.go
+++ b/filesystem/path_test.go
@@ -20,7 +20,6 @@ package filesystem
import (
"fmt"
- "io/ioutil"
"os"
"testing"
@@ -61,7 +60,7 @@ func TestHaveReadAccessTo(t *testing.T) {
if util.IsUserRoot() {
t.Skip("This test cannot be run as root")
}
- file, err := ioutil.TempFile("", "fscrypt_test")
+ file, err := os.CreateTemp("", "fscrypt_test")
if err != nil {
t.Fatal(err)
}