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
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
......@@ -31,7 +30,7 @@ import (
)
func tmpDirOrDie() *paths.Path {
dir, err := ioutil.TempDir(os.TempDir(), "builder_test")
dir, err := os.MkdirTemp(os.TempDir(), "builder_test")
if err != nil {
panic(fmt.Sprintf("error creating tmp dir: %v", err))
}
......@@ -44,7 +43,7 @@ func TestSaveSketch(t *testing.T) {
sketchFile := filepath.Join("testdata", sketchName)
tmp := tmpDirOrDie()
defer tmp.RemoveAll()
source, err := ioutil.ReadFile(sketchFile)
source, err := os.ReadFile(sketchFile)
if err != nil {
t.Fatalf("unable to read golden file %s: %v", sketchFile, err)
}
......
......@@ -17,7 +17,7 @@ package httpclient
import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
......@@ -42,7 +42,7 @@ func TestUserAgentHeader(t *testing.T) {
response, err := client.Do(request)
require.NoError(t, err)
b, err := ioutil.ReadAll(response.Body)
b, err := io.ReadAll(response.Body)
require.NoError(t, err)
require.Equal(t, "test-user-agent", string(b))
......
......@@ -24,7 +24,6 @@ import (
"fmt"
"hash"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
......@@ -154,7 +153,7 @@ func computeDirChecksum(root string) (string, error) {
// CheckDirChecksum reads checksum from the package.json and compares it with a recomputed value.
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 {
return false, err
}
......
......@@ -16,9 +16,9 @@
package resources
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
......@@ -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
// 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)
requestLines := strings.Split(string(b), "\r\n")
......
......@@ -20,7 +20,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path"
......@@ -53,7 +52,7 @@ func main() {
// To avoid polluting an existing arduino-cli installation, the example
// client uses a temp folder to keep cores, libraries and the like.
// 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 {
log.Fatal(err)
}
......
......@@ -17,7 +17,6 @@ package configuration
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
......@@ -27,7 +26,7 @@ import (
)
func tmpDirOrDie() string {
dir, err := ioutil.TempDir(os.TempDir(), "cli_test")
dir, err := os.MkdirTemp(os.TempDir(), "cli_test")
if err != nil {
panic(fmt.Sprintf("error creating tmp dir: %v", err))
}
......
......@@ -20,7 +20,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"sync"
......@@ -54,7 +53,7 @@ func getLanguages() []string {
}
defer res.Body.Close()
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
......
......@@ -17,7 +17,7 @@ package cli
import (
"fmt"
"io/ioutil"
"io"
"os"
"strings"
......@@ -185,7 +185,7 @@ func preRun(cmd *cobra.Command, args []string) {
DisableColors: color.NoColor,
})
} else {
logrus.SetOutput(ioutil.Discard)
logrus.SetOutput(io.Discard)
}
// set the Logger format
......
......@@ -16,7 +16,7 @@
package ctags
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
......@@ -26,7 +26,7 @@ import (
)
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)
parser := CTagsParser{}
......
......@@ -16,7 +16,7 @@
package ctags
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
......@@ -26,7 +26,7 @@ import (
)
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)
parser := &CTagsParser{}
......
......@@ -16,7 +16,7 @@
package gohasissues
import (
"io/ioutil"
"io/fs"
"os"
"path/filepath"
"sort"
......@@ -84,18 +84,24 @@ func readDirNames(dirname string) ([]string, error) {
}
func ReadDir(dirname string) ([]os.FileInfo, error) {
infos, err := ioutil.ReadDir(dirname)
entries, err := os.ReadDir(dirname)
if err != nil {
return nil, err
}
for idx, info := range infos {
info, err := resolveSymlink(dirname, info)
infos := make([]fs.FileInfo, 0, len(entries))
for _, entry := range entries {
info, err := entry.Info()
if err != nil {
return nil, err
}
info, err = resolveSymlink(dirname, info)
if err != nil {
// unresolvable symlinks should be skipped silently
continue
}
infos[idx] = info
infos = append(infos, info)
}
return infos, nil
......
......@@ -21,7 +21,6 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
......@@ -443,12 +442,17 @@ func CopyDir(src string, dst string, extensions []string) (err error) {
return
}
entries, err := ioutil.ReadDir(src)
entries, err := os.ReadDir(src)
if err != nil {
return
}
for _, entry := range entries {
for _, dirEntry := range entries {
entry, scopeErr := dirEntry.Info()
if scopeErr != nil {
return
}
srcPath := filepath.Join(src, 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