Skip to content

Commit dca3df7

Browse files
[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
1 parent 60a8aa9 commit dca3df7

File tree

12 files changed

+34
-29
lines changed

12 files changed

+34
-29
lines changed

Diff for: arduino/builder/sketch_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package builder_test
1717

1818
import (
1919
"fmt"
20-
"io/ioutil"
2120
"os"
2221
"path/filepath"
2322
"runtime"
@@ -31,7 +30,7 @@ import (
3130
)
3231

3332
func tmpDirOrDie() *paths.Path {
34-
dir, err := ioutil.TempDir(os.TempDir(), "builder_test")
33+
dir, err := os.MkdirTemp(os.TempDir(), "builder_test")
3534
if err != nil {
3635
panic(fmt.Sprintf("error creating tmp dir: %v", err))
3736
}
@@ -44,7 +43,7 @@ func TestSaveSketch(t *testing.T) {
4443
sketchFile := filepath.Join("testdata", sketchName)
4544
tmp := tmpDirOrDie()
4645
defer tmp.RemoveAll()
47-
source, err := ioutil.ReadFile(sketchFile)
46+
source, err := os.ReadFile(sketchFile)
4847
if err != nil {
4948
t.Fatalf("unable to read golden file %s: %v", sketchFile, err)
5049
}

Diff for: arduino/httpclient/httpclient_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package httpclient
1717

1818
import (
1919
"fmt"
20-
"io/ioutil"
20+
"io"
2121
"net/http"
2222
"net/http/httptest"
2323
"net/url"
@@ -42,7 +42,7 @@ func TestUserAgentHeader(t *testing.T) {
4242
response, err := client.Do(request)
4343
require.NoError(t, err)
4444

45-
b, err := ioutil.ReadAll(response.Body)
45+
b, err := io.ReadAll(response.Body)
4646
require.NoError(t, err)
4747

4848
require.Equal(t, "test-user-agent", string(b))

Diff for: arduino/resources/checksums.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"fmt"
2525
"hash"
2626
"io"
27-
"io/ioutil"
2827
"os"
2928
"path/filepath"
3029
"strings"
@@ -154,7 +153,7 @@ func computeDirChecksum(root string) (string, error) {
154153

155154
// CheckDirChecksum reads checksum from the package.json and compares it with a recomputed value.
156155
func CheckDirChecksum(root string) (bool, error) {
157-
packageJSON, err := ioutil.ReadFile(filepath.Join(root, packageFileName))
156+
packageJSON, err := os.ReadFile(filepath.Join(root, packageFileName))
158157
if err != nil {
159158
return false, err
160159
}

Diff for: arduino/resources/helpers_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
package resources
1717

1818
import (
19-
"io/ioutil"
2019
"net/http"
2120
"net/http/httptest"
21+
"os"
2222
"strings"
2323
"testing"
2424

@@ -67,7 +67,7 @@ func TestDownloadApplyUserAgentHeaderUsingConfig(t *testing.T) {
6767
// User-Agent: arduino-cli/0.0.0-test.preview (amd64; linux; go1.12.4) Commit:deadbeef/Build:2019-06-12 11:11:11.111
6868
// Accept-Encoding: gzip
6969

70-
b, err := ioutil.ReadFile(tmp.String() + "/cache/echo.txt") // just pass the file name
70+
b, err := os.ReadFile(tmp.String() + "/cache/echo.txt") // just pass the file name
7171
require.NoError(t, err)
7272

7373
requestLines := strings.Split(string(b), "\r\n")

Diff for: client_example/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"fmt"
2222
"io"
23-
"io/ioutil"
2423
"log"
2524
"os"
2625
"path"
@@ -53,7 +52,7 @@ func main() {
5352
// To avoid polluting an existing arduino-cli installation, the example
5453
// client uses a temp folder to keep cores, libraries and the like.
5554
// You can point `dataDir` to a location that better fits your needs.
56-
dataDir, err = ioutil.TempDir("", "arduino-rpc-client")
55+
dataDir, err = os.MkdirTemp("", "arduino-rpc-client")
5756
if err != nil {
5857
log.Fatal(err)
5958
}

Diff for: configuration/configuration_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package configuration
1717

1818
import (
1919
"fmt"
20-
"io/ioutil"
2120
"os"
2221
"path/filepath"
2322
"testing"
@@ -27,7 +26,7 @@ import (
2726
)
2827

2928
func tmpDirOrDie() string {
30-
dir, err := ioutil.TempDir(os.TempDir(), "cli_test")
29+
dir, err := os.MkdirTemp(os.TempDir(), "cli_test")
3130
if err != nil {
3231
panic(fmt.Sprintf("error creating tmp dir: %v", err))
3332
}

Diff for: i18n/cmd/commands/transifex/pull_transifex.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"encoding/json"
2121
"fmt"
2222
"io"
23-
"io/ioutil"
2423
"net/http"
2524
"os"
2625
"sync"
@@ -54,7 +53,7 @@ func getLanguages() []string {
5453
}
5554

5655
defer res.Body.Close()
57-
b, err := ioutil.ReadAll(res.Body)
56+
b, err := io.ReadAll(res.Body)
5857
if err != nil {
5958
fmt.Println(err.Error())
6059
os.Exit(1)

Diff for: internal/cli/cli.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package cli
1717

1818
import (
1919
"fmt"
20-
"io/ioutil"
20+
"io"
2121
"os"
2222
"strings"
2323

@@ -185,7 +185,7 @@ func preRun(cmd *cobra.Command, args []string) {
185185
DisableColors: color.NoColor,
186186
})
187187
} else {
188-
logrus.SetOutput(ioutil.Discard)
188+
logrus.SetOutput(io.Discard)
189189
}
190190

191191
// set the Logger format

Diff for: legacy/builder/ctags/ctags_parser_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package ctags
1717

1818
import (
19-
"io/ioutil"
19+
"os"
2020
"path/filepath"
2121
"testing"
2222

@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
func produceTags(t *testing.T, filename string) []*types.CTag {
29-
bytes, err := ioutil.ReadFile(filepath.Join("test_data", filename))
29+
bytes, err := os.ReadFile(filepath.Join("test_data", filename))
3030
require.NoError(t, err)
3131

3232
parser := CTagsParser{}

Diff for: legacy/builder/ctags/ctags_to_prototypes_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package ctags
1717

1818
import (
19-
"io/ioutil"
19+
"os"
2020
"path/filepath"
2121
"testing"
2222

@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
func producePrototypes(t *testing.T, filename string, mainFile string) ([]*types.Prototype, int) {
29-
bytes, err := ioutil.ReadFile(filepath.Join("test_data", filename))
29+
bytes, err := os.ReadFile(filepath.Join("test_data", filename))
3030
require.NoError(t, err)
3131

3232
parser := &CTagsParser{}

Diff for: legacy/builder/gohasissues/go_has_issues.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package gohasissues
1717

1818
import (
19-
"io/ioutil"
19+
"io/fs"
2020
"os"
2121
"path/filepath"
2222
"sort"
@@ -84,18 +84,24 @@ func readDirNames(dirname string) ([]string, error) {
8484
}
8585

8686
func ReadDir(dirname string) ([]os.FileInfo, error) {
87-
infos, err := ioutil.ReadDir(dirname)
87+
entries, err := os.ReadDir(dirname)
8888
if err != nil {
8989
return nil, err
9090
}
9191

92-
for idx, info := range infos {
93-
info, err := resolveSymlink(dirname, info)
92+
infos := make([]fs.FileInfo, 0, len(entries))
93+
for _, entry := range entries {
94+
info, err := entry.Info()
95+
if err != nil {
96+
return nil, err
97+
}
98+
99+
info, err = resolveSymlink(dirname, info)
94100
if err != nil {
95101
// unresolvable symlinks should be skipped silently
96102
continue
97103
}
98-
infos[idx] = info
104+
infos = append(infos, info)
99105
}
100106

101107
return infos, nil

Diff for: legacy/builder/utils/utils.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"encoding/hex"
2222
"fmt"
2323
"io"
24-
"io/ioutil"
2524
"os"
2625
"os/exec"
2726
"path/filepath"
@@ -443,12 +442,17 @@ func CopyDir(src string, dst string, extensions []string) (err error) {
443442
return
444443
}
445444

446-
entries, err := ioutil.ReadDir(src)
445+
entries, err := os.ReadDir(src)
447446
if err != nil {
448447
return
449448
}
450449

451-
for _, entry := range entries {
450+
for _, dirEntry := range entries {
451+
entry, scopeErr := dirEntry.Info()
452+
if scopeErr != nil {
453+
return
454+
}
455+
452456
srcPath := filepath.Join(src, entry.Name())
453457
dstPath := filepath.Join(dst, entry.Name())
454458

0 commit comments

Comments
 (0)