Skip to content

Commit d26cd85

Browse files
committed
chore: sync with go1.16.15
1 parent 3592d07 commit d26cd85

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

internal/cache/cache.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"errors"
1616
"fmt"
1717
"io"
18+
"io/fs"
1819
"os"
1920
"path/filepath"
2021
"strconv"
@@ -55,7 +56,7 @@ func Open(dir string) (*Cache, error) {
5556
return nil, err
5657
}
5758
if !info.IsDir() {
58-
return nil, &os.PathError{Op: "open", Path: dir, Err: fmt.Errorf("not a directory")}
59+
return nil, &fs.PathError{Op: "open", Path: dir, Err: fmt.Errorf("not a directory")}
5960
}
6061
for i := 0; i < 256; i++ {
6162
name := filepath.Join(dir, fmt.Sprintf("%02x", i))
@@ -405,7 +406,7 @@ func (c *Cache) putIndexEntry(id ActionID, out OutputID, size int64, allowVerify
405406
// Truncate the file only *after* writing it.
406407
// (This should be a no-op, but truncate just in case of previous corruption.)
407408
//
408-
// This differs from ioutil.WriteFile, which truncates to 0 *before* writing
409+
// This differs from os.WriteFile, which truncates to 0 *before* writing
409410
// via os.O_TRUNC. Truncating only after writing ensures that a second write
410411
// of the same content to the same file is idempotent, and does not — even
411412
// temporarily! — undo the effect of the first write.

internal/cache/cache_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"bytes"
99
"encoding/binary"
1010
"fmt"
11-
"io/ioutil"
1211
"os"
1312
"path/filepath"
1413
"testing"
@@ -20,7 +19,7 @@ func init() {
2019
}
2120

2221
func TestBasic(t *testing.T) {
23-
dir, err := ioutil.TempDir("", "cachetest-")
22+
dir, err := os.MkdirTemp("", "cachetest-")
2423
if err != nil {
2524
t.Fatal(err)
2625
}
@@ -65,7 +64,7 @@ func TestBasic(t *testing.T) {
6564
}
6665

6766
func TestGrowth(t *testing.T) {
68-
dir, err := ioutil.TempDir("", "cachetest-")
67+
dir, err := os.MkdirTemp("", "cachetest-")
6968
if err != nil {
7069
t.Fatal(err)
7170
}
@@ -118,7 +117,7 @@ func TestVerifyPanic(t *testing.T) {
118117
t.Fatal("initEnv did not set verify")
119118
}
120119

121-
dir, err := ioutil.TempDir("", "cachetest-")
120+
dir, err := os.MkdirTemp("", "cachetest-")
122121
if err != nil {
123122
t.Fatal(err)
124123
}
@@ -151,7 +150,7 @@ func dummyID(x int) [HashSize]byte {
151150
}
152151

153152
func TestCacheTrim(t *testing.T) {
154-
dir, err := ioutil.TempDir("", "cachetest-")
153+
dir, err := os.MkdirTemp("", "cachetest-")
155154
if err != nil {
156155
t.Fatal(err)
157156
}
@@ -207,7 +206,7 @@ func TestCacheTrim(t *testing.T) {
207206
t.Fatal(err)
208207
}
209208
c.OutputFile(entry.OutputID)
210-
data, err := ioutil.ReadFile(filepath.Join(dir, "trim.txt"))
209+
data, err := os.ReadFile(filepath.Join(dir, "trim.txt"))
211210
if err != nil {
212211
t.Fatal(err)
213212
}
@@ -220,7 +219,7 @@ func TestCacheTrim(t *testing.T) {
220219
t.Fatal(err)
221220
}
222221
c.OutputFile(entry.OutputID)
223-
data2, err := ioutil.ReadFile(filepath.Join(dir, "trim.txt"))
222+
data2, err := os.ReadFile(filepath.Join(dir, "trim.txt"))
224223
if err != nil {
225224
t.Fatal(err)
226225
}

internal/cache/default.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package cache
66

77
import (
88
"fmt"
9-
"io/ioutil"
109
base "log"
1110
"os"
1211
"path/filepath"
@@ -39,7 +38,7 @@ func initDefaultCache() {
3938
}
4039
if _, err := os.Stat(filepath.Join(dir, "README")); err != nil {
4140
// Best effort.
42-
if wErr := ioutil.WriteFile(filepath.Join(dir, "README"), []byte(cacheREADME), 0666); wErr != nil {
41+
if wErr := os.WriteFile(filepath.Join(dir, "README"), []byte(cacheREADME), 0666); wErr != nil {
4342
base.Fatalf("Failed to write README file to cache dir %s: %s", dir, err)
4443
}
4544
}

internal/cache/hash_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package cache
66

77
import (
88
"fmt"
9-
"io/ioutil"
109
"os"
1110
"testing"
1211
)
@@ -28,7 +27,7 @@ func TestHash(t *testing.T) {
2827
}
2928

3029
func TestHashFile(t *testing.T) {
31-
f, err := ioutil.TempFile("", "cmd-go-test-")
30+
f, err := os.CreateTemp("", "cmd-go-test-")
3231
if err != nil {
3332
t.Fatal(err)
3433
}

internal/cache/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Extracted from `go/src/cmd/go/internal/cache/`.
44

5+
- sync with go1.16.15
56
- sync with go1.15.15
67
- sync with go1.14.15
78

0 commit comments

Comments
 (0)