Skip to content

[skip changelog] Updated the deprecated ioutil dependency #2054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions arduino/builder/sketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package builder_test

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand All @@ -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))
}
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions arduino/httpclient/httpclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package httpclient

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
Expand All @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions arduino/resources/checksums.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"fmt"
"hash"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions arduino/resources/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package resources

import (
"io/ioutil"
"os"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions client_example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package configuration

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -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))
}
Expand Down
3 changes: 1 addition & 2 deletions i18n/cmd/commands/transifex/pull_transifex.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"sync"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package cli

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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions legacy/builder/ctags/ctags_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.
// To purchase a commercial license, send an email to license@arduino.c`c.

package ctags

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

Expand All @@ -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{}
Expand Down
4 changes: 2 additions & 2 deletions legacy/builder/ctags/ctags_to_prototypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package ctags

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

Expand All @@ -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{}
Expand Down
16 changes: 11 additions & 5 deletions legacy/builder/gohasissues/go_has_issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package gohasissues

import (
"io/ioutil"
"io/fs"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions legacy/builder/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"io/fs"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -443,12 +443,21 @@ 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
}

infos := make([]fs.FileInfo, 0, len(entries))
for _, entry := range entries {
info, scopeErr := entry.Info()
if scopeErr != nil {
return
}
infos = append(infos, info)
}

for _, entry := range infos {
srcPath := filepath.Join(src, entry.Name())
dstPath := filepath.Join(dst, entry.Name())

Expand Down