dev: add doc about internal package extracted from Go (#3204)
This commit is contained in:
parent
b1cec4755f
commit
f072d55e6d
@ -138,9 +138,8 @@ issues:
|
|||||||
|
|
||||||
run:
|
run:
|
||||||
timeout: 5m
|
timeout: 5m
|
||||||
go: '1.17' # TODO(ldez): we force to use an old version of Go for the CI and the tests.
|
|
||||||
skip-dirs:
|
skip-dirs:
|
||||||
- test/testdata_etc
|
- test/testdata_etc # test files
|
||||||
- internal/cache
|
- internal/cache # extracted from Go code
|
||||||
- internal/renameio
|
- internal/renameio # extracted from Go code
|
||||||
- internal/robustio
|
- internal/robustio # extracted from Go code
|
||||||
|
9
internal/cache/cache.go
vendored
9
internal/cache/cache.go
vendored
@ -51,7 +51,6 @@ type Cache struct {
|
|||||||
// to share a cache directory (for example, if the directory were stored
|
// to share a cache directory (for example, if the directory were stored
|
||||||
// in a network file system). File locking is notoriously unreliable in
|
// in a network file system). File locking is notoriously unreliable in
|
||||||
// network file systems and may not suffice to protect the cache.
|
// network file systems and may not suffice to protect the cache.
|
||||||
//
|
|
||||||
func Open(dir string) (*Cache, error) {
|
func Open(dir string) (*Cache, error) {
|
||||||
info, err := os.Stat(dir)
|
info, err := os.Stat(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -159,7 +158,7 @@ func (c *Cache) get(id ActionID) (Entry, error) {
|
|||||||
defer f.Close()
|
defer f.Close()
|
||||||
entry := make([]byte, entrySize+1) // +1 to detect whether f is too long
|
entry := make([]byte, entrySize+1) // +1 to detect whether f is too long
|
||||||
if n, readErr := io.ReadFull(f, entry); n != entrySize || readErr != io.ErrUnexpectedEOF {
|
if n, readErr := io.ReadFull(f, entry); n != entrySize || readErr != io.ErrUnexpectedEOF {
|
||||||
return failed(fmt.Errorf("read %d/%d bytes from %s with error %s", n, entrySize, fileName, readErr))
|
return failed(fmt.Errorf("read %d/%d bytes from %s with error %w", n, entrySize, fileName, readErr))
|
||||||
}
|
}
|
||||||
if entry[0] != 'v' || entry[1] != '1' || entry[2] != ' ' || entry[3+hexSize] != ' ' || entry[3+hexSize+1+hexSize] != ' ' || entry[3+hexSize+1+hexSize+1+20] != ' ' || entry[entrySize-1] != '\n' {
|
if entry[0] != 'v' || entry[1] != '1' || entry[2] != ' ' || entry[3+hexSize] != ' ' || entry[3+hexSize+1+hexSize] != ' ' || entry[3+hexSize+1+hexSize+1+20] != ' ' || entry[entrySize-1] != '\n' {
|
||||||
return failed(fmt.Errorf("bad data in %s", fileName))
|
return failed(fmt.Errorf("bad data in %s", fileName))
|
||||||
@ -181,7 +180,7 @@ func (c *Cache) get(id ActionID) (Entry, error) {
|
|||||||
}
|
}
|
||||||
size, err := strconv.ParseInt(string(esize[i:]), 10, 64)
|
size, err := strconv.ParseInt(string(esize[i:]), 10, 64)
|
||||||
if err != nil || size < 0 {
|
if err != nil || size < 0 {
|
||||||
return failed(fmt.Errorf("failed to parse esize int from %s with error %s", fileName, err))
|
return failed(fmt.Errorf("failed to parse esize int from %s with error %w", fileName, err))
|
||||||
}
|
}
|
||||||
i = 0
|
i = 0
|
||||||
for i < len(etime) && etime[i] == ' ' {
|
for i < len(etime) && etime[i] == ' ' {
|
||||||
@ -189,7 +188,7 @@ func (c *Cache) get(id ActionID) (Entry, error) {
|
|||||||
}
|
}
|
||||||
tm, err := strconv.ParseInt(string(etime[i:]), 10, 64)
|
tm, err := strconv.ParseInt(string(etime[i:]), 10, 64)
|
||||||
if err != nil || tm < 0 {
|
if err != nil || tm < 0 {
|
||||||
return failed(fmt.Errorf("failed to parse etime int from %s with error %s", fileName, err))
|
return failed(fmt.Errorf("failed to parse etime int from %s with error %w", fileName, err))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = c.used(fileName); err != nil {
|
if err = c.used(fileName); err != nil {
|
||||||
@ -498,7 +497,7 @@ func (c *Cache) copyFile(file io.ReadSeeker, out OutputID, size int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if n, wErr := h.Write(buf); n != len(buf) {
|
if n, wErr := h.Write(buf); n != len(buf) {
|
||||||
return fmt.Errorf("wrote to hash %d/%d bytes with error %s", n, len(buf), wErr)
|
return fmt.Errorf("wrote to hash %d/%d bytes with error %w", n, len(buf), wErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
sum := h.Sum(nil)
|
sum := h.Sum(nil)
|
||||||
|
18
internal/cache/readme.md
vendored
Normal file
18
internal/cache/readme.md
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# cache
|
||||||
|
|
||||||
|
Extracted from go/src/cmd/go/internal/cache/
|
||||||
|
I don't know what version of Go this package was pulled from.
|
||||||
|
|
||||||
|
Adapted for golangci-lint:
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/699
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/779
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/788
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/808
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/1063
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/1070
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/1162
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/2318
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/2352
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/3012
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/3096
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/3204
|
10
internal/renameio/readme.md
Normal file
10
internal/renameio/readme.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# renameio
|
||||||
|
|
||||||
|
Extracted from go/src/cmd/go/internal/renameio/
|
||||||
|
I don't know what version of Go this package was pulled from.
|
||||||
|
|
||||||
|
Adapted for golangci-lint:
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/699
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/808
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/1063
|
||||||
|
- https://github.com/golangci/golangci-lint/pull/3204
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// +build !plan9,!windows,!js
|
//go:build !plan9 && !windows && !js
|
||||||
|
|
||||||
package renameio
|
package renameio
|
||||||
|
|
||||||
|
6
internal/robustio/readme.md
Normal file
6
internal/robustio/readme.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# robustio
|
||||||
|
|
||||||
|
Extracted from go1.19.1/src/cmd/go/internal/robustio
|
||||||
|
|
||||||
|
There is only one modification:
|
||||||
|
- ERROR_SHARING_VIOLATION extracted from go1.19.1/src/internal/syscall/windows/syscall_windows.go to remove the dependencies to `internal/syscall/windows`
|
@ -5,7 +5,7 @@
|
|||||||
package robustio
|
package robustio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"errors"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,16 +13,8 @@ const errFileNotFound = syscall.ENOENT
|
|||||||
|
|
||||||
// isEphemeralError returns true if err may be resolved by waiting.
|
// isEphemeralError returns true if err may be resolved by waiting.
|
||||||
func isEphemeralError(err error) bool {
|
func isEphemeralError(err error) bool {
|
||||||
switch werr := err.(type) {
|
var errno syscall.Errno
|
||||||
case *os.PathError:
|
if errors.As(err, &errno) {
|
||||||
err = werr.Err
|
|
||||||
case *os.LinkError:
|
|
||||||
err = werr.Err
|
|
||||||
case *os.SyscallError:
|
|
||||||
err = werr.Err
|
|
||||||
|
|
||||||
}
|
|
||||||
if errno, ok := err.(syscall.Errno); ok {
|
|
||||||
return errno == errFileNotFound
|
return errno == errFileNotFound
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -2,20 +2,19 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// +build windows darwin
|
//go:build windows || darwin
|
||||||
|
|
||||||
package robustio
|
package robustio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const arbitraryTimeout = 500 * time.Millisecond
|
const arbitraryTimeout = 2000 * time.Millisecond
|
||||||
|
|
||||||
const ERROR_SHARING_VIOLATION = 32
|
|
||||||
|
|
||||||
// retry retries ephemeral errors from f up to an arbitrary timeout
|
// retry retries ephemeral errors from f up to an arbitrary timeout
|
||||||
// to work around filesystem flakiness on Windows and Darwin.
|
// to work around filesystem flakiness on Windows and Darwin.
|
||||||
@ -32,7 +31,8 @@ func retry(f func() (err error, mayRetry bool)) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if errno, ok := err.(syscall.Errno); ok && (lowestErrno == 0 || errno < lowestErrno) {
|
var errno syscall.Errno
|
||||||
|
if errors.As(err, &errno) && (lowestErrno == 0 || errno < lowestErrno) {
|
||||||
bestErr = err
|
bestErr = err
|
||||||
lowestErrno = errno
|
lowestErrno = errno
|
||||||
} else if bestErr == nil {
|
} else if bestErr == nil {
|
||||||
@ -78,8 +78,7 @@ func readFile(filename string) ([]byte, error) {
|
|||||||
// Unlike in rename, we do not retry errFileNotFound here: it can occur
|
// Unlike in rename, we do not retry errFileNotFound here: it can occur
|
||||||
// as a spurious error, but the file may also genuinely not exist, so the
|
// as a spurious error, but the file may also genuinely not exist, so the
|
||||||
// increase in robustness is probably not worth the extra latency.
|
// increase in robustness is probably not worth the extra latency.
|
||||||
|
return err, isEphemeralError(err) && !errors.Is(err, errFileNotFound)
|
||||||
return err, isEphemeralError(err) && err != errFileNotFound
|
|
||||||
})
|
})
|
||||||
return b, err
|
return b, err
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//+build !windows,!darwin
|
//go:build !windows && !darwin
|
||||||
|
|
||||||
package robustio
|
package robustio
|
||||||
|
|
||||||
|
@ -5,23 +5,20 @@
|
|||||||
package robustio
|
package robustio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"errors"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
const errFileNotFound = syscall.ERROR_FILE_NOT_FOUND
|
const errFileNotFound = syscall.ERROR_FILE_NOT_FOUND
|
||||||
|
|
||||||
|
// ERROR_SHARING_VIOLATION (ldez) extract from go1.19.1/src/internal/syscall/windows/syscall_windows.go.
|
||||||
|
// This is the only modification of this file.
|
||||||
|
const ERROR_SHARING_VIOLATION syscall.Errno = 32
|
||||||
|
|
||||||
// isEphemeralError returns true if err may be resolved by waiting.
|
// isEphemeralError returns true if err may be resolved by waiting.
|
||||||
func isEphemeralError(err error) bool {
|
func isEphemeralError(err error) bool {
|
||||||
switch werr := err.(type) {
|
var errno syscall.Errno
|
||||||
case *os.PathError:
|
if errors.As(err, &errno) {
|
||||||
err = werr.Err
|
|
||||||
case *os.LinkError:
|
|
||||||
err = werr.Err
|
|
||||||
case *os.SyscallError:
|
|
||||||
err = werr.Err
|
|
||||||
}
|
|
||||||
if errno, ok := err.(syscall.Errno); ok {
|
|
||||||
switch errno {
|
switch errno {
|
||||||
case syscall.ERROR_ACCESS_DENIED,
|
case syscall.ERROR_ACCESS_DENIED,
|
||||||
syscall.ERROR_FILE_NOT_FOUND,
|
syscall.ERROR_FILE_NOT_FOUND,
|
||||||
|
@ -3,6 +3,7 @@ package goanalysis
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"go/types"
|
"go/types"
|
||||||
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"time"
|
"time"
|
||||||
@ -331,7 +332,7 @@ func (act *action) loadPersistedFacts() bool {
|
|||||||
var facts []Fact
|
var facts []Fact
|
||||||
key := fmt.Sprintf("%s/facts", act.a.Name)
|
key := fmt.Sprintf("%s/facts", act.a.Name)
|
||||||
if err := act.r.pkgCache.Get(act.pkg, pkgcache.HashModeNeedAllDeps, key, &facts); err != nil {
|
if err := act.r.pkgCache.Get(act.pkg, pkgcache.HashModeNeedAllDeps, key, &facts); err != nil {
|
||||||
if err != pkgcache.ErrMissing {
|
if !errors.Is(err, pkgcache.ErrMissing) && !errors.Is(err, io.EOF) {
|
||||||
act.r.log.Warnf("Failed to get persisted facts: %s", err)
|
act.r.log.Warnf("Failed to get persisted facts: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user