Unverified Commit dca3df79 authored by Zachary Walters's avatar Zachary Walters Committed by GitHub

[skip changelog] Updated the deprecated ioutil dependency (#2054)

* [skip changelog] Updated the deprecated ioutil dependency

* Resolved the go fmt violation that causes the check go CI workflow run failure

* Removed the typo grave accent from ctags_parser_test

* Removed the arbitrary fs.FileInfo array and its iterations in legacy/builder/utils/utils.go
parent 60a8aa96
...@@ -17,7 +17,6 @@ package builder_test ...@@ -17,7 +17,6 @@ package builder_test
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
...@@ -31,7 +30,7 @@ import ( ...@@ -31,7 +30,7 @@ import (
) )
func tmpDirOrDie() *paths.Path { func tmpDirOrDie() *paths.Path {
dir, err := ioutil.TempDir(os.TempDir(), "builder_test") dir, err := os.MkdirTemp(os.TempDir(), "builder_test")
if err != nil { if err != nil {
panic(fmt.Sprintf("error creating tmp dir: %v", err)) panic(fmt.Sprintf("error creating tmp dir: %v", err))
} }
...@@ -44,7 +43,7 @@ func TestSaveSketch(t *testing.T) { ...@@ -44,7 +43,7 @@ func TestSaveSketch(t *testing.T) {
sketchFile := filepath.Join("testdata", sketchName) sketchFile := filepath.Join("testdata", sketchName)
tmp := tmpDirOrDie() tmp := tmpDirOrDie()
defer tmp.RemoveAll() defer tmp.RemoveAll()
source, err := ioutil.ReadFile(sketchFile) source, err := os.ReadFile(sketchFile)
if err != nil { if err != nil {
t.Fatalf("unable to read golden file %s: %v", sketchFile, err) t.Fatalf("unable to read golden file %s: %v", sketchFile, err)
} }
......
...@@ -17,7 +17,7 @@ package httpclient ...@@ -17,7 +17,7 @@ package httpclient
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
...@@ -42,7 +42,7 @@ func TestUserAgentHeader(t *testing.T) { ...@@ -42,7 +42,7 @@ func TestUserAgentHeader(t *testing.T) {
response, err := client.Do(request) response, err := client.Do(request)
require.NoError(t, err) require.NoError(t, err)
b, err := ioutil.ReadAll(response.Body) b, err := io.ReadAll(response.Body)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, "test-user-agent", string(b)) require.Equal(t, "test-user-agent", string(b))
......
...@@ -24,7 +24,6 @@ import ( ...@@ -24,7 +24,6 @@ import (
"fmt" "fmt"
"hash" "hash"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
...@@ -154,7 +153,7 @@ func computeDirChecksum(root string) (string, error) { ...@@ -154,7 +153,7 @@ func computeDirChecksum(root string) (string, error) {
// CheckDirChecksum reads checksum from the package.json and compares it with a recomputed value. // CheckDirChecksum reads checksum from the package.json and compares it with a recomputed value.
func CheckDirChecksum(root string) (bool, error) { func CheckDirChecksum(root string) (bool, error) {
packageJSON, err := ioutil.ReadFile(filepath.Join(root, packageFileName)) packageJSON, err := os.ReadFile(filepath.Join(root, packageFileName))
if err != nil { if err != nil {
return false, err return false, err
} }
......
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
package resources package resources
import ( import (
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os"
"strings" "strings"
"testing" "testing"
...@@ -67,7 +67,7 @@ func TestDownloadApplyUserAgentHeaderUsingConfig(t *testing.T) { ...@@ -67,7 +67,7 @@ func TestDownloadApplyUserAgentHeaderUsingConfig(t *testing.T) {
// User-Agent: arduino-cli/0.0.0-test.preview (amd64; linux; go1.12.4) Commit:deadbeef/Build:2019-06-12 11:11:11.111 // User-Agent: arduino-cli/0.0.0-test.preview (amd64; linux; go1.12.4) Commit:deadbeef/Build:2019-06-12 11:11:11.111
// Accept-Encoding: gzip // Accept-Encoding: gzip
b, err := ioutil.ReadFile(tmp.String() + "/cache/echo.txt") // just pass the file name b, err := os.ReadFile(tmp.String() + "/cache/echo.txt") // just pass the file name
require.NoError(t, err) require.NoError(t, err)
requestLines := strings.Split(string(b), "\r\n") requestLines := strings.Split(string(b), "\r\n")
......
...@@ -20,7 +20,6 @@ import ( ...@@ -20,7 +20,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"os" "os"
"path" "path"
...@@ -53,7 +52,7 @@ func main() { ...@@ -53,7 +52,7 @@ func main() {
// To avoid polluting an existing arduino-cli installation, the example // To avoid polluting an existing arduino-cli installation, the example
// client uses a temp folder to keep cores, libraries and the like. // client uses a temp folder to keep cores, libraries and the like.
// You can point `dataDir` to a location that better fits your needs. // You can point `dataDir` to a location that better fits your needs.
dataDir, err = ioutil.TempDir("", "arduino-rpc-client") dataDir, err = os.MkdirTemp("", "arduino-rpc-client")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
......
...@@ -17,7 +17,6 @@ package configuration ...@@ -17,7 +17,6 @@ package configuration
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
...@@ -27,7 +26,7 @@ import ( ...@@ -27,7 +26,7 @@ import (
) )
func tmpDirOrDie() string { func tmpDirOrDie() string {
dir, err := ioutil.TempDir(os.TempDir(), "cli_test") dir, err := os.MkdirTemp(os.TempDir(), "cli_test")
if err != nil { if err != nil {
panic(fmt.Sprintf("error creating tmp dir: %v", err)) panic(fmt.Sprintf("error creating tmp dir: %v", err))
} }
......
...@@ -20,7 +20,6 @@ import ( ...@@ -20,7 +20,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"sync" "sync"
...@@ -54,7 +53,7 @@ func getLanguages() []string { ...@@ -54,7 +53,7 @@ func getLanguages() []string {
} }
defer res.Body.Close() defer res.Body.Close()
b, err := ioutil.ReadAll(res.Body) b, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
os.Exit(1) os.Exit(1)
......
...@@ -17,7 +17,7 @@ package cli ...@@ -17,7 +17,7 @@ package cli
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"os" "os"
"strings" "strings"
...@@ -185,7 +185,7 @@ func preRun(cmd *cobra.Command, args []string) { ...@@ -185,7 +185,7 @@ func preRun(cmd *cobra.Command, args []string) {
DisableColors: color.NoColor, DisableColors: color.NoColor,
}) })
} else { } else {
logrus.SetOutput(ioutil.Discard) logrus.SetOutput(io.Discard)
} }
// set the Logger format // set the Logger format
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
package ctags package ctags
import ( import (
"io/ioutil" "os"
"path/filepath" "path/filepath"
"testing" "testing"
...@@ -26,7 +26,7 @@ import ( ...@@ -26,7 +26,7 @@ import (
) )
func produceTags(t *testing.T, filename string) []*types.CTag { func produceTags(t *testing.T, filename string) []*types.CTag {
bytes, err := ioutil.ReadFile(filepath.Join("test_data", filename)) bytes, err := os.ReadFile(filepath.Join("test_data", filename))
require.NoError(t, err) require.NoError(t, err)
parser := CTagsParser{} parser := CTagsParser{}
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
package ctags package ctags
import ( import (
"io/ioutil" "os"
"path/filepath" "path/filepath"
"testing" "testing"
...@@ -26,7 +26,7 @@ import ( ...@@ -26,7 +26,7 @@ import (
) )
func producePrototypes(t *testing.T, filename string, mainFile string) ([]*types.Prototype, int) { func producePrototypes(t *testing.T, filename string, mainFile string) ([]*types.Prototype, int) {
bytes, err := ioutil.ReadFile(filepath.Join("test_data", filename)) bytes, err := os.ReadFile(filepath.Join("test_data", filename))
require.NoError(t, err) require.NoError(t, err)
parser := &CTagsParser{} parser := &CTagsParser{}
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
package gohasissues package gohasissues
import ( import (
"io/ioutil" "io/fs"
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
...@@ -84,18 +84,24 @@ func readDirNames(dirname string) ([]string, error) { ...@@ -84,18 +84,24 @@ func readDirNames(dirname string) ([]string, error) {
} }
func ReadDir(dirname string) ([]os.FileInfo, error) { func ReadDir(dirname string) ([]os.FileInfo, error) {
infos, err := ioutil.ReadDir(dirname) entries, err := os.ReadDir(dirname)
if err != nil { if err != nil {
return nil, err return nil, err
} }
for idx, info := range infos { infos := make([]fs.FileInfo, 0, len(entries))
info, err := resolveSymlink(dirname, info) for _, entry := range entries {
info, err := entry.Info()
if err != nil {
return nil, err
}
info, err = resolveSymlink(dirname, info)
if err != nil { if err != nil {
// unresolvable symlinks should be skipped silently // unresolvable symlinks should be skipped silently
continue continue
} }
infos[idx] = info infos = append(infos, info)
} }
return infos, nil return infos, nil
......
...@@ -21,7 +21,6 @@ import ( ...@@ -21,7 +21,6 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
...@@ -443,12 +442,17 @@ func CopyDir(src string, dst string, extensions []string) (err error) { ...@@ -443,12 +442,17 @@ func CopyDir(src string, dst string, extensions []string) (err error) {
return return
} }
entries, err := ioutil.ReadDir(src) entries, err := os.ReadDir(src)
if err != nil { if err != nil {
return return
} }
for _, entry := range entries { for _, dirEntry := range entries {
entry, scopeErr := dirEntry.Info()
if scopeErr != nil {
return
}
srcPath := filepath.Join(src, entry.Name()) srcPath := filepath.Join(src, entry.Name())
dstPath := filepath.Join(dst, entry.Name()) dstPath := filepath.Join(dst, entry.Name())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment