Skip to content

Commit 7df2ba5

Browse files
committed
chore: sync with go1.17.13
1 parent d26cd85 commit 7df2ba5

File tree

11 files changed

+35
-304
lines changed

11 files changed

+35
-304
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ issues:
222222
exclude-dirs:
223223
- test/testdata_etc # test files
224224
- internal/cache # extracted from Go code
225-
- internal/renameio # extracted from Go code
226225
- internal/robustio # extracted from Go code
227226

228227
run:

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ require (
8787
github.com/polyfloyd/go-errorlint v1.6.0
8888
github.com/quasilyte/go-ruleguard/dsl v0.3.22
8989
github.com/raeperd/recvcheck v0.1.2
90+
github.com/rogpeppe/go-internal v1.13.1
9091
github.com/ryancurrah/gomodguard v1.3.5
9192
github.com/ryanrolds/sqlclosecheck v0.5.1
9293
github.com/sanposhiho/wastedassign/v2 v2.0.7

go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/cache/cache.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"strings"
2323
"time"
2424

25-
"github.com/golangci/golangci-lint/internal/renameio"
25+
"github.com/rogpeppe/go-internal/lockedfile"
2626
)
2727

2828
// An ActionID is a cache action key, the hash of a complete description of a
@@ -323,10 +323,17 @@ func (c *Cache) Trim() {
323323
// We maintain in dir/trim.txt the time of the last completed cache trim.
324324
// If the cache has been trimmed recently enough, do nothing.
325325
// This is the common case.
326-
data, _ := renameio.ReadFile(filepath.Join(c.dir, "trim.txt"))
327-
t, err := strconv.ParseInt(strings.TrimSpace(string(data)), 10, 64)
328-
if err == nil && now.Sub(time.Unix(t, 0)) < trimInterval {
329-
return
326+
// If the trim file is corrupt, detected if the file can't be parsed, or the
327+
// trim time is too far in the future, attempt the trim anyway. It's possible that
328+
// the cache was full when the corruption happened. Attempting a trim on
329+
// an empty cache is cheap, so there wouldn't be a big performance hit in that case.
330+
if data, err := lockedfile.Read(filepath.Join(c.dir, "trim.txt")); err == nil {
331+
if t, err := strconv.ParseInt(strings.TrimSpace(string(data)), 10, 64); err == nil {
332+
lastTrim := time.Unix(t, 0)
333+
if d := now.Sub(lastTrim); d < trimInterval && d > -mtimeInterval {
334+
return
335+
}
336+
}
330337
}
331338

332339
// Trim each of the 256 subdirectories.
@@ -340,7 +347,11 @@ func (c *Cache) Trim() {
340347

341348
// Ignore errors from here: if we don't write the complete timestamp, the
342349
// cache will appear older than it is, and we'll trim it again next time.
343-
renameio.WriteFile(filepath.Join(c.dir, "trim.txt"), []byte(fmt.Sprintf("%d", now.Unix())), 0666)
350+
var b bytes.Buffer
351+
fmt.Fprintf(&b, "%d", now.Unix())
352+
if err := lockedfile.Write(filepath.Join(c.dir, "trim.txt"), &b, 0666); err != nil {
353+
return
354+
}
344355
}
345356

346357
// trimSubdir trims a single cache subdirectory.

internal/cache/hash.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"hash"
1212
"io"
1313
"os"
14+
"strings"
1415
"sync"
1516
)
1617

@@ -36,6 +37,15 @@ type Hash struct {
3637
// which are still addressed by unsalted SHA256.
3738
var hashSalt []byte
3839

40+
// stripExperiment strips any GOEXPERIMENT configuration from the Go
41+
// version string.
42+
func stripExperiment(version string) string {
43+
if i := strings.Index(version, " X:"); i >= 0 {
44+
return version[:i]
45+
}
46+
return version
47+
}
48+
3949
// Subkey returns an action ID corresponding to mixing a parent
4050
// action ID with a string description of the subkey.
4151
func Subkey(parent ActionID, desc string) (ActionID, error) {

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.17.13
56
- sync with go1.16.15
67
- sync with go1.15.15
78
- sync with go1.14.15

internal/renameio/readme.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

internal/renameio/renameio.go

Lines changed: 0 additions & 93 deletions
This file was deleted.

internal/renameio/renameio_test.go

Lines changed: 0 additions & 149 deletions
This file was deleted.

internal/renameio/umask_test.go

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)