aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2020-07-07 13:49:21 -0400
committerRuss Cox <rsc@golang.org>2020-10-20 02:32:42 +0000
commit7bb721b9384bdd196befeaed593b185f7f2a5589 (patch)
tree882f21fc2e1fbba6fb11100e4fd8efc5f973a44d /src/cmd
parentd4da735091986868015369e01c63794af9cc9b84 (diff)
downloadgo-7bb721b9384bdd196befeaed593b185f7f2a5589.tar.xz
all: update references to symbols moved from os to io/fs
The old os references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. For #41190. Change-Id: I8f9526977867c10a221e2f392f78d7dec073f1bd Reviewed-on: https://go-review.googlesource.com/c/go/+/243907 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/doc/pkg.go10
-rw-r--r--src/cmd/fix/main.go5
-rw-r--r--src/cmd/go/go_test.go7
-rw-r--r--src/cmd/go/internal/cache/cache.go3
-rw-r--r--src/cmd/go/internal/fsys/fsys.go41
-rw-r--r--src/cmd/go/internal/fsys/fsys_test.go39
-rw-r--r--src/cmd/go/internal/imports/scan.go3
-rw-r--r--src/cmd/go/internal/load/pkg.go5
-rw-r--r--src/cmd/go/internal/lockedfile/internal/filelock/filelock.go5
-rw-r--r--src/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go6
-rw-r--r--src/cmd/go/internal/lockedfile/internal/filelock/filelock_other.go6
-rw-r--r--src/cmd/go/internal/lockedfile/internal/filelock/filelock_plan9.go8
-rw-r--r--src/cmd/go/internal/lockedfile/internal/filelock/filelock_unix.go4
-rw-r--r--src/cmd/go/internal/lockedfile/internal/filelock/filelock_windows.go6
-rw-r--r--src/cmd/go/internal/lockedfile/lockedfile.go9
-rw-r--r--src/cmd/go/internal/lockedfile/lockedfile_filelock.go3
-rw-r--r--src/cmd/go/internal/lockedfile/lockedfile_plan9.go9
-rw-r--r--src/cmd/go/internal/modcmd/vendor.go7
-rw-r--r--src/cmd/go/internal/modcmd/verify.go9
-rw-r--r--src/cmd/go/internal/modfetch/cache.go7
-rw-r--r--src/cmd/go/internal/modfetch/codehost/codehost.go9
-rw-r--r--src/cmd/go/internal/modfetch/codehost/git.go15
-rw-r--r--src/cmd/go/internal/modfetch/codehost/git_test.go3
-rw-r--r--src/cmd/go/internal/modfetch/codehost/vcs.go3
-rw-r--r--src/cmd/go/internal/modfetch/coderepo.go7
-rw-r--r--src/cmd/go/internal/modfetch/fetch.go11
-rw-r--r--src/cmd/go/internal/modfetch/proxy.go8
-rw-r--r--src/cmd/go/internal/modfetch/repo.go5
-rw-r--r--src/cmd/go/internal/modfetch/sumdb.go7
-rw-r--r--src/cmd/go/internal/modload/import.go3
-rw-r--r--src/cmd/go/internal/modload/load.go3
-rw-r--r--src/cmd/go/internal/modload/query.go11
-rw-r--r--src/cmd/go/internal/modload/search.go5
-rw-r--r--src/cmd/go/internal/modload/stat_openfile.go3
-rw-r--r--src/cmd/go/internal/modload/stat_unix.go3
-rw-r--r--src/cmd/go/internal/modload/stat_windows.go6
-rw-r--r--src/cmd/go/internal/modload/vendor.go4
-rw-r--r--src/cmd/go/internal/renameio/renameio.go7
-rw-r--r--src/cmd/go/internal/renameio/umask_test.go5
-rw-r--r--src/cmd/go/internal/search/search.go7
-rw-r--r--src/cmd/go/internal/test/test.go3
-rw-r--r--src/cmd/go/internal/vcs/vcs.go5
-rw-r--r--src/cmd/go/internal/version/version.go11
-rw-r--r--src/cmd/go/internal/web/api.go6
-rw-r--r--src/cmd/go/internal/web/file_test.go5
-rw-r--r--src/cmd/go/internal/work/build_test.go3
-rw-r--r--src/cmd/go/internal/work/exec.go9
-rw-r--r--src/cmd/go/proxy_test.go5
-rw-r--r--src/cmd/go/script_test.go7
-rw-r--r--src/cmd/go/testdata/addmod.go3
-rw-r--r--src/cmd/go/testdata/savedir.go3
-rw-r--r--src/cmd/gofmt/gofmt.go9
-rw-r--r--src/cmd/gofmt/long_test.go3
-rw-r--r--src/cmd/internal/buildid/buildid.go9
-rw-r--r--src/cmd/internal/buildid/note.go7
-rw-r--r--src/cmd/internal/moddeps/moddeps_test.go3
-rw-r--r--src/cmd/pack/pack.go3
-rw-r--r--src/cmd/pack/pack_test.go11
58 files changed, 233 insertions, 189 deletions
diff --git a/src/cmd/doc/pkg.go b/src/cmd/doc/pkg.go
index ffc302c78c..c2e06ebc8b 100644
--- a/src/cmd/doc/pkg.go
+++ b/src/cmd/doc/pkg.go
@@ -16,8 +16,8 @@ import (
"go/printer"
"go/token"
"io"
+ "io/fs"
"log"
- "os"
"path/filepath"
"strings"
"unicode"
@@ -129,11 +129,10 @@ func (pkg *Package) Fatalf(format string, args ...interface{}) {
// parsePackage turns the build package we found into a parsed package
// we can then use to generate documentation.
func parsePackage(writer io.Writer, pkg *build.Package, userPath string) *Package {
- fs := token.NewFileSet()
// include tells parser.ParseDir which files to include.
// That means the file must be in the build package's GoFiles or CgoFiles
// list only (no tag-ignored files, tests, swig or other non-Go files).
- include := func(info os.FileInfo) bool {
+ include := func(info fs.FileInfo) bool {
for _, name := range pkg.GoFiles {
if name == info.Name() {
return true
@@ -146,7 +145,8 @@ func parsePackage(writer io.Writer, pkg *build.Package, userPath string) *Packag
}
return false
}
- pkgs, err := parser.ParseDir(fs, pkg.Dir, include, parser.ParseComments)
+ fset := token.NewFileSet()
+ pkgs, err := parser.ParseDir(fset, pkg.Dir, include, parser.ParseComments)
if err != nil {
log.Fatal(err)
}
@@ -203,7 +203,7 @@ func parsePackage(writer io.Writer, pkg *build.Package, userPath string) *Packag
typedValue: typedValue,
constructor: constructor,
build: pkg,
- fs: fs,
+ fs: fset,
}
p.buf.pkg = p
return p
diff --git a/src/cmd/fix/main.go b/src/cmd/fix/main.go
index d19dde6b4a..dfba902f48 100644
--- a/src/cmd/fix/main.go
+++ b/src/cmd/fix/main.go
@@ -13,6 +13,7 @@ import (
"go/parser"
"go/scanner"
"go/token"
+ "io/fs"
"io/ioutil"
"os"
"path/filepath"
@@ -235,7 +236,7 @@ func walkDir(path string) {
filepath.Walk(path, visitFile)
}
-func visitFile(path string, f os.FileInfo, err error) error {
+func visitFile(path string, f fs.FileInfo, err error) error {
if err == nil && isGoFile(f) {
err = processFile(path, false)
}
@@ -245,7 +246,7 @@ func visitFile(path string, f os.FileInfo, err error) error {
return nil
}
-func isGoFile(f os.FileInfo) bool {
+func isGoFile(f fs.FileInfo) bool {
// ignore non-Go files
name := f.Name()
return !f.IsDir() && !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".go")
diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go
index 093ea2ffa1..2c11d16959 100644
--- a/src/cmd/go/go_test.go
+++ b/src/cmd/go/go_test.go
@@ -15,6 +15,7 @@ import (
"internal/race"
"internal/testenv"
"io"
+ "io/fs"
"io/ioutil"
"log"
"os"
@@ -813,7 +814,7 @@ func (tg *testgoData) cleanup() {
func removeAll(dir string) error {
// module cache has 0444 directories;
// make them writable in order to remove content.
- filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
+ filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
// chmod not only directories, but also things that we couldn't even stat
// due to permission errors: they may also be unreadable directories.
if err != nil || info.IsDir() {
@@ -860,7 +861,7 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
srcdir := filepath.Join(testGOROOT, copydir)
tg.tempDir(filepath.Join("goroot", copydir))
err := filepath.Walk(srcdir,
- func(path string, info os.FileInfo, err error) error {
+ func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
@@ -2018,7 +2019,7 @@ func main() {
tg.run("build", "-o", exe, "p")
}
-func copyFile(src, dst string, perm os.FileMode) error {
+func copyFile(src, dst string, perm fs.FileMode) error {
sf, err := os.Open(src)
if err != nil {
return err
diff --git a/src/cmd/go/internal/cache/cache.go b/src/cmd/go/internal/cache/cache.go
index 15545ac31f..5464fe5685 100644
--- a/src/cmd/go/internal/cache/cache.go
+++ b/src/cmd/go/internal/cache/cache.go
@@ -12,6 +12,7 @@ import (
"errors"
"fmt"
"io"
+ "io/fs"
"io/ioutil"
"os"
"path/filepath"
@@ -54,7 +55,7 @@ func Open(dir string) (*Cache, error) {
return nil, err
}
if !info.IsDir() {
- return nil, &os.PathError{Op: "open", Path: dir, Err: fmt.Errorf("not a directory")}
+ return nil, &fs.PathError{Op: "open", Path: dir, Err: fmt.Errorf("not a directory")}
}
for i := 0; i < 256; i++ {
name := filepath.Join(dir, fmt.Sprintf("%02x", i))
diff --git a/src/cmd/go/internal/fsys/fsys.go b/src/cmd/go/internal/fsys/fsys.go
index 489af93496..67359ffb6d 100644
--- a/src/cmd/go/internal/fsys/fsys.go
+++ b/src/cmd/go/internal/fsys/fsys.go
@@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "io/fs"
"io/ioutil"
"os"
"path/filepath"
@@ -240,7 +241,7 @@ var errNotDir = errors.New("not a directory")
// readDir reads a dir on disk, returning an error that is errNotDir if the dir is not a directory.
// Unfortunately, the error returned by ioutil.ReadDir if dir is not a directory
// can vary depending on the OS (Linux, Mac, Windows return ENOTDIR; BSD returns EINVAL).
-func readDir(dir string) ([]os.FileInfo, error) {
+func readDir(dir string) ([]fs.FileInfo, error) {
fis, err := ioutil.ReadDir(dir)
if err == nil {
return fis, nil
@@ -249,25 +250,25 @@ func readDir(dir string) ([]os.FileInfo, error) {
if os.IsNotExist(err) {
return nil, err
} else if dirfi, staterr := os.Stat(dir); staterr == nil && !dirfi.IsDir() {
- return nil, &os.PathError{Op: "ReadDir", Path: dir, Err: errNotDir}
+ return nil, &fs.PathError{Op: "ReadDir", Path: dir, Err: errNotDir}
} else {
return nil, err
}
}
-// ReadDir provides a slice of os.FileInfo entries corresponding
+// ReadDir provides a slice of fs.FileInfo entries corresponding
// to the overlaid files in the directory.
-func ReadDir(dir string) ([]os.FileInfo, error) {
+func ReadDir(dir string) ([]fs.FileInfo, error) {
dir = canonicalize(dir)
if _, ok := parentIsOverlayFile(dir); ok {
- return nil, &os.PathError{Op: "ReadDir", Path: dir, Err: errNotDir}
+ return nil, &fs.PathError{Op: "ReadDir", Path: dir, Err: errNotDir}
}
dirNode := overlay[dir]
if dirNode == nil {
return readDir(dir)
} else if dirNode.isDeleted() {
- return nil, &os.PathError{Op: "ReadDir", Path: dir, Err: os.ErrNotExist}
+ return nil, &fs.PathError{Op: "ReadDir", Path: dir, Err: fs.ErrNotExist}
}
diskfis, err := readDir(dir)
if err != nil && !os.IsNotExist(err) && !errors.Is(err, errNotDir) {
@@ -275,7 +276,7 @@ func ReadDir(dir string) ([]os.FileInfo, error) {
}
// Stat files in overlay to make composite list of fileinfos
- files := make(map[string]os.FileInfo)
+ files := make(map[string]fs.FileInfo)
for _, f := range diskfis {
files[f.Name()] = f
}
@@ -327,14 +328,14 @@ func Open(path string) (*os.File, error) {
cpath := canonicalize(path)
if node, ok := overlay[cpath]; ok {
if node.isDir() {
- return nil, &os.PathError{Op: "Open", Path: path, Err: errors.New("fsys.Open doesn't support opening directories yet")}
+ return nil, &fs.PathError{Op: "Open", Path: path, Err: errors.New("fsys.Open doesn't support opening directories yet")}
}
return os.Open(node.actualFilePath)
} else if parent, ok := parentIsOverlayFile(filepath.Dir(cpath)); ok {
// The file is deleted explicitly in the Replace map,
// or implicitly because one of its parent directories was
// replaced by a file.
- return nil, &os.PathError{
+ return nil, &fs.PathError{
Op: "Open",
Path: path,
Err: fmt.Errorf("file %s does not exist: parent directory %s is replaced by a file in overlay", path, parent)}
@@ -387,7 +388,7 @@ func IsDirWithGoFiles(dir string) (bool, error) {
// walk recursively descends path, calling walkFn. Copied, with some
// modifications from path/filepath.walk.
-func walk(path string, info os.FileInfo, walkFn filepath.WalkFunc) error {
+func walk(path string, info fs.FileInfo, walkFn filepath.WalkFunc) error {
if !info.IsDir() {
return walkFn(path, info, nil)
}
@@ -432,11 +433,11 @@ func Walk(root string, walkFn filepath.WalkFunc) error {
}
// lstat implements a version of os.Lstat that operates on the overlay filesystem.
-func lstat(path string) (os.FileInfo, error) {
+func lstat(path string) (fs.FileInfo, error) {
cpath := canonicalize(path)
if _, ok := parentIsOverlayFile(filepath.Dir(cpath)); ok {
- return nil, &os.PathError{Op: "lstat", Path: cpath, Err: os.ErrNotExist}
+ return nil, &fs.PathError{Op: "lstat", Path: cpath, Err: fs.ErrNotExist}
}
node, ok := overlay[cpath]
@@ -447,7 +448,7 @@ func lstat(path string) (os.FileInfo, error) {
switch {
case node.isDeleted():
- return nil, &os.PathError{Op: "lstat", Path: cpath, Err: os.ErrNotExist}
+ return nil, &fs.PathError{Op: "lstat", Path: cpath, Err: fs.ErrNotExist}
case node.isDir():
return fakeDir(filepath.Base(cpath)), nil
default:
@@ -459,22 +460,22 @@ func lstat(path string) (os.FileInfo, error) {
}
}
-// fakeFile provides an os.FileInfo implementation for an overlaid file,
+// fakeFile provides an fs.FileInfo implementation for an overlaid file,
// so that the file has the name of the overlaid file, but takes all
// other characteristics of the replacement file.
type fakeFile struct {
name string
- real os.FileInfo
+ real fs.FileInfo
}
func (f fakeFile) Name() string { return f.name }
func (f fakeFile) Size() int64 { return f.real.Size() }
-func (f fakeFile) Mode() os.FileMode { return f.real.Mode() }
+func (f fakeFile) Mode() fs.FileMode { return f.real.Mode() }
func (f fakeFile) ModTime() time.Time { return f.real.ModTime() }
func (f fakeFile) IsDir() bool { return f.real.IsDir() }
func (f fakeFile) Sys() interface{} { return f.real.Sys() }
-// missingFile provides an os.FileInfo for an overlaid file where the
+// missingFile provides an fs.FileInfo for an overlaid file where the
// destination file in the overlay doesn't exist. It returns zero values
// for the fileInfo methods other than Name, set to the file's name, and Mode
// set to ModeIrregular.
@@ -482,19 +483,19 @@ type missingFile string
func (f missingFile) Name() string { return string(f) }
func (f missingFile) Size() int64 { return 0 }
-func (f missingFile) Mode() os.FileMode { return os.ModeIrregular }
+func (f missingFile) Mode() fs.FileMode { return fs.ModeIrregular }
func (f missingFile) ModTime() time.Time { return time.Unix(0, 0) }
func (f missingFile) IsDir() bool { return false }
func (f missingFile) Sys() interface{} { return nil }
-// fakeDir provides an os.FileInfo implementation for directories that are
+// fakeDir provides an fs.FileInfo implementation for directories that are
// implicitly created by overlaid files. Each directory in the
// path of an overlaid file is considered to exist in the overlay filesystem.
type fakeDir string
func (f fakeDir) Name() string { return string(f) }
func (f fakeDir) Size() int64 { return 0 }
-func (f fakeDir) Mode() os.FileMode { return os.ModeDir | 0500 }
+func (f fakeDir) Mode() fs.FileMode { return fs.ModeDir | 0500 }
func (f fakeDir) ModTime() time.Time { return time.Unix(0, 0) }
func (f fakeDir) IsDir() bool { return true }
func (f fakeDir) Sys() interface{} { return nil }
diff --git a/src/cmd/go/internal/fsys/fsys_test.go b/src/cmd/go/internal/fsys/fsys_test.go
index 6cf59fba47..ba9f05d00b 100644
--- a/src/cmd/go/internal/fsys/fsys_test.go
+++ b/src/cmd/go/internal/fsys/fsys_test.go
@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"internal/testenv"
+ "io/fs"
"io/ioutil"
"os"
"path/filepath"
@@ -291,8 +292,8 @@ x
_, gotErr := ReadDir(dir)
if gotErr == nil {
t.Errorf("ReadDir(%q): got no error, want error", dir)
- } else if _, ok := gotErr.(*os.PathError); !ok {
- t.Errorf("ReadDir(%q): got error with string %q and type %T, want os.PathError", dir, gotErr.Error(), gotErr)
+ } else if _, ok := gotErr.(*fs.PathError); !ok {
+ t.Errorf("ReadDir(%q): got error with string %q and type %T, want fs.PathError", dir, gotErr.Error(), gotErr)
}
}
}
@@ -489,7 +490,7 @@ func TestWalk(t *testing.T) {
path string
name string
size int64
- mode os.FileMode
+ mode fs.FileMode
isDir bool
}
testCases := []struct {
@@ -504,7 +505,7 @@ func TestWalk(t *testing.T) {
`,
".",
[]file{
- {".", "root", 0, os.ModeDir | 0700, true},
+ {".", "root", 0, fs.ModeDir | 0700, true},
{"file.txt", "file.txt", 0, 0600, false},
},
},
@@ -520,7 +521,7 @@ contents of other file
`,
".",
[]file{
- {".", "root", 0, os.ModeDir | 0500, true},
+ {".", "root", 0, fs.ModeDir | 0500, true},
{"file.txt", "file.txt", 23, 0600, false},
{"other.txt", "other.txt", 23, 0600, false},
},
@@ -536,7 +537,7 @@ contents of other file
`,
".",
[]file{
- {".", "root", 0, os.ModeDir | 0500, true},
+ {".", "root", 0, fs.ModeDir | 0500, true},
{"file.txt", "file.txt", 23, 0600, false},
{"other.txt", "other.txt", 23, 0600, false},
},
@@ -552,8 +553,8 @@ contents of other file
`,
".",
[]file{
- {".", "root", 0, os.ModeDir | 0500, true},
- {"dir", "dir", 0, os.ModeDir | 0500, true},
+ {".", "root", 0, fs.ModeDir | 0500, true},
+ {"dir", "dir", 0, fs.ModeDir | 0500, true},
{"dir" + string(filepath.Separator) + "file.txt", "file.txt", 23, 0600, false},
{"other.txt", "other.txt", 23, 0600, false},
},
@@ -565,7 +566,7 @@ contents of other file
initOverlay(t, tc.overlay)
var got []file
- Walk(tc.root, func(path string, info os.FileInfo, err error) error {
+ Walk(tc.root, func(path string, info fs.FileInfo, err error) error {
got = append(got, file{path, info.Name(), info.Size(), info.Mode(), info.IsDir()})
return nil
})
@@ -580,8 +581,8 @@ contents of other file
if got[i].name != tc.wantFiles[i].name {
t.Errorf("name of file #%v in walk, got %q, want %q", i, got[i].name, tc.wantFiles[i].name)
}
- if got[i].mode&(os.ModeDir|0700) != tc.wantFiles[i].mode {
- t.Errorf("mode&(os.ModeDir|0700) for mode of file #%v in walk, got %v, want %v", i, got[i].mode&(os.ModeDir|0700), tc.wantFiles[i].mode)
+ if got[i].mode&(fs.ModeDir|0700) != tc.wantFiles[i].mode {
+ t.Errorf("mode&(fs.ModeDir|0700) for mode of file #%v in walk, got %v, want %v", i, got[i].mode&(fs.ModeDir|0700), tc.wantFiles[i].mode)
}
if got[i].isDir != tc.wantFiles[i].isDir {
t.Errorf("isDir for file #%v in walk, got %v, want %v", i, got[i].isDir, tc.wantFiles[i].isDir)
@@ -610,7 +611,7 @@ func TestWalk_SkipDir(t *testing.T) {
`)
var seen []string
- Walk(".", func(path string, info os.FileInfo, err error) error {
+ Walk(".", func(path string, info fs.FileInfo, err error) error {
seen = append(seen, path)
if path == "skipthisdir" || path == filepath.Join("dontskip", "skip") {
return filepath.SkipDir
@@ -635,7 +636,7 @@ func TestWalk_Error(t *testing.T) {
initOverlay(t, "{}")
alreadyCalled := false
- err := Walk("foo", func(path string, info os.FileInfo, err error) error {
+ err := Walk("foo", func(path string, info fs.FileInfo, err error) error {
if alreadyCalled {
t.Fatal("expected walk function to be called exactly once, but it was called more than once")
}
@@ -683,7 +684,7 @@ func TestWalk_Symlink(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
var got []string
- err := Walk(tc.dir, func(path string, info os.FileInfo, err error) error {
+ err := Walk(tc.dir, func(path string, info fs.FileInfo, err error) error {
got = append(got, path)
if err != nil {
t.Errorf("walkfn: got non nil err argument: %v, want nil err argument", err)
@@ -706,7 +707,7 @@ func TestLstat(t *testing.T) {
type file struct {
name string
size int64
- mode os.FileMode // mode & (os.ModeDir|0x700): only check 'user' permissions
+ mode fs.FileMode // mode & (fs.ModeDir|0x700): only check 'user' permissions
isDir bool
}
@@ -771,7 +772,7 @@ contents`,
-- dir/foo.txt --
`,
"dir",
- file{"dir", 0, 0700 | os.ModeDir, true},
+ file{"dir", 0, 0700 | fs.ModeDir, true},
false,
},
{
@@ -780,7 +781,7 @@ contents`,
-- dummy.txt --
`,
"dir",
- file{"dir", 0, 0500 | os.ModeDir, true},
+ file{"dir", 0, 0500 | fs.ModeDir, true},
false,
},
}
@@ -801,8 +802,8 @@ contents`,
if got.Name() != tc.want.name {
t.Errorf("lstat(%q).Name(): got %q, want %q", tc.path, got.Name(), tc.want.name)
}
- if got.Mode()&(os.ModeDir|0700) != tc.want.mode {
- t.Errorf("lstat(%q).Mode()&(os.ModeDir|0700): got %v, want %v", tc.path, got.Mode()&(os.ModeDir|0700), tc.want.mode)
+ if got.Mode()&(fs.ModeDir|0700) != tc.want.mode {
+ t.Errorf("lstat(%q).Mode()&(fs.ModeDir|0700): got %v, want %v", tc.path, got.Mode()&(fs.ModeDir|0700), tc.want.mode)
}
if got.IsDir() != tc.want.isDir {
t.Errorf("lstat(%q).IsDir(): got %v, want %v", tc.path, got.IsDir(), tc.want.isDir)
diff --git a/src/cmd/go/internal/imports/scan.go b/src/cmd/go/internal/imports/scan.go
index 42ee49aaaa..d45393f36c 100644
--- a/src/cmd/go/internal/imports/scan.go
+++ b/src/cmd/go/internal/imports/scan.go
@@ -6,6 +6,7 @@ package imports
import (
"fmt"
+ "io/fs"
"os"
"path/filepath"
"sort"
@@ -26,7 +27,7 @@ func ScanDir(dir string, tags map[string]bool) ([]string, []string, error) {
// If the directory entry is a symlink, stat it to obtain the info for the
// link target instead of the link itself.
- if info.Mode()&os.ModeSymlink != 0 {
+ if info.Mode()&fs.ModeSymlink != 0 {
info, err = os.Stat(filepath.Join(dir, name))
if err != nil {
continue // Ignore broken symlinks.
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index f73b79d089..066ff6c981 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -14,6 +14,7 @@ import (
"go/build"
"go/scanner"
"go/token"
+ "io/fs"
"io/ioutil"
"os"
pathpkg "path"
@@ -2300,7 +2301,7 @@ func GoFilesPackage(ctx context.Context, gofiles []string) *Package {
// to make it look like this is a standard package or
// command directory. So that local imports resolve
// consistently, the files must all be in the same directory.
- var dirent []os.FileInfo
+ var dirent []fs.FileInfo
var dir string
for _, file := range gofiles {
fi, err := os.Stat(file)
@@ -2321,7 +2322,7 @@ func GoFilesPackage(ctx context.Context, gofiles []string) *Package {
}
dirent = append(dirent, fi)
}
- ctxt.ReadDir = func(string) ([]os.FileInfo, error) { return dirent, nil }
+ ctxt.ReadDir = func(string) ([]fs.FileInfo, error) { return dirent, nil }
if cfg.ModulesEnabled {
modload.ImportFromFiles(ctx, gofiles)
diff --git a/src/cmd/go/internal/lockedfile/internal/filelock/filelock.go b/src/cmd/go/internal/lockedfile/internal/filelock/filelock.go
index aba3eed776..05f27c321a 100644
--- a/src/cmd/go/internal/lockedfile/internal/filelock/filelock.go
+++ b/src/cmd/go/internal/lockedfile/internal/filelock/filelock.go
@@ -9,6 +9,7 @@ package filelock
import (
"errors"
+ "io/fs"
"os"
)
@@ -24,7 +25,7 @@ type File interface {
Fd() uintptr
// Stat returns the FileInfo structure describing file.
- Stat() (os.FileInfo, error)
+ Stat() (fs.FileInfo, error)
}
// Lock places an advisory write lock on the file, blocking until it can be
@@ -87,7 +88,7 @@ var ErrNotSupported = errors.New("operation not supported")
// underlyingError returns the underlying error for known os error types.
func underlyingError(err error) error {
switch err := err.(type) {
- case *os.PathError:
+ case *fs.PathError:
return err.Err
case *os.LinkError:
return err.Err
diff --git a/src/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go b/src/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go
index 8776c5741c..1fa4327a89 100644
--- a/src/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go
+++ b/src/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go
@@ -18,8 +18,8 @@ package filelock
import (
"errors"
"io"
+ "io/fs"
"math/rand"
- "os"
"sync"
"syscall"
"time"
@@ -61,7 +61,7 @@ func lock(f File, lt lockType) (err error) {
mu.Lock()
if i, dup := inodes[f]; dup && i != ino {
mu.Unlock()
- return &os.PathError{
+ return &fs.PathError{
Op: lt.String(),
Path: f.Name(),
Err: errors.New("inode for file changed since last Lock or RLock"),
@@ -152,7 +152,7 @@ func lock(f File, lt lockType) (err error) {
if err != nil {
unlock(f)
- return &os.PathError{
+ return &fs.PathError{
Op: lt.String(),
Path: f.Name(),
Err: err,
diff --git a/src/cmd/go/internal/lockedfile/internal/filelock/filelock_other.go b/src/cmd/go/internal/lockedfile/internal/filelock/filelock_other.go
index 107611e1ce..bc480343fc 100644
--- a/src/cmd/go/internal/lockedfile/internal/filelock/filelock_other.go
+++ b/src/cmd/go/internal/lockedfile/internal/filelock/filelock_other.go
@@ -6,7 +6,7 @@
package filelock
-import "os"
+import "io/fs"
type lockType int8
@@ -16,7 +16,7 @@ const (
)
func lock(f File, lt lockType) error {
- return &os.PathError{
+ return &fs.PathError{
Op: lt.String(),
Path: f.Name(),
Err: ErrNotSupported,
@@ -24,7 +24,7 @@ func lock(f File, lt lockType) error {
}
func unlock(f File) error {
- return &os.PathError{
+ return &fs.PathError{
Op: "Unlock",
Path: f.Name(),
Err: ErrNotSupported,
diff --git a/src/cmd/go/internal/lockedfile/internal/filelock/filelock_plan9.go b/src/cmd/go/internal/lockedfile/internal/filelock/filelock_plan9.go
index afdffe323f..0798ee469a 100644
--- a/src/cmd/go/internal/lockedfile/internal/filelock/filelock_plan9.go
+++ b/src/cmd/go/internal/lockedfile/internal/filelock/filelock_plan9.go
@@ -6,9 +6,7 @@
package filelock
-import (
- "os"
-)
+import "io/fs"
type lockType int8
@@ -18,7 +16,7 @@ const (
)
func lock(f File, lt lockType) error {
- return &os.PathError{
+ return &fs.PathError{
Op: lt.String(),
Path: f.Name(),
Err: ErrNotSupported,
@@ -26,7 +24,7 @@ func lock(f File, lt lockType) error {
}
func unlock(f File) error {
- return &os.PathError{
+ return &fs.PathError{
Op: "Unlock",
Path: f.Name(),
Err: ErrNotSupported,
diff --git a/src/cmd/go/internal/lockedfile/internal/filelock/filelock_unix.go b/src/cmd/go/internal/lockedfile/internal/filelock/filelock_unix.go
index 78f2c51129..ed07bac608 100644
--- a/src/cmd/go/internal/lockedfile/internal/filelock/filelock_unix.go
+++ b/src/cmd/go/internal/lockedfile/internal/filelock/filelock_unix.go
@@ -7,7 +7,7 @@
package filelock
import (
- "os"
+ "io/fs"
"syscall"
)
@@ -26,7 +26,7 @@ func lock(f File, lt lockType) (err error) {
}
}
if err != nil {
- return &os.PathError{
+ return &fs.PathError{
Op: lt.String(),
Path: f.Name(),
Err: err,
diff --git a/src/cmd/go/internal/lockedfile/internal/filelock/filelock_windows.go b/src/cmd/go/internal/lockedfile/internal/filelock/filelock_windows.go
index 43e85e450e..19de27eb9b 100644
--- a/src/cmd/go/internal/lockedfile/internal/filelock/filelock_windows.go
+++ b/src/cmd/go/internal/lockedfile/internal/filelock/filelock_windows.go
@@ -8,7 +8,7 @@ package filelock
import (
"internal/syscall/windows"
- "os"
+ "io/fs"
"syscall"
)
@@ -34,7 +34,7 @@ func lock(f File, lt lockType) error {
err := windows.LockFileEx(syscall.Handle(f.Fd()), uint32(lt), reserved, allBytes, allBytes, ol)
if err != nil {
- return &os.PathError{
+ return &fs.PathError{
Op: lt.String(),
Path: f.Name(),
Err: err,
@@ -47,7 +47,7 @@ func unlock(f File) error {
ol := new(syscall.Overlapped)
err := windows.UnlockFileEx(syscall.Handle(f.Fd()), reserved, allBytes, allBytes, ol)
if err != nil {
- return &os.PathError{
+ return &fs.PathError{
Op: "Unlock",
Path: f.Name(),
Err: err,
diff --git a/src/cmd/go/internal/lockedfile/lockedfile.go b/src/cmd/go/internal/lockedfile/lockedfile.go
index 59b2dba44c..503024da4b 100644
--- a/src/cmd/go/internal/lockedfile/lockedfile.go
+++ b/src/cmd/go/internal/lockedfile/lockedfile.go
@@ -9,6 +9,7 @@ package lockedfile
import (
"fmt"
"io"
+ "io/fs"
"io/ioutil"
"os"
"runtime"
@@ -35,7 +36,7 @@ type osFile struct {
// OpenFile is like os.OpenFile, but returns a locked file.
// If flag includes os.O_WRONLY or os.O_RDWR, the file is write-locked;
// otherwise, it is read-locked.
-func OpenFile(name string, flag int, perm os.FileMode) (*File, error) {
+func OpenFile(name string, flag int, perm fs.FileMode) (*File, error) {
var (
f = new(File)
err error
@@ -82,10 +83,10 @@ func Edit(name string) (*File, error) {
// non-nil error.
func (f *File) Close() error {
if f.closed {
- return &os.PathError{
+ return &fs.PathError{
Op: "close",
Path: f.Name(),
- Err: os.ErrClosed,
+ Err: fs.ErrClosed,
}
}
f.closed = true
@@ -108,7 +109,7 @@ func Read(name string) ([]byte, error) {
// Write opens the named file (creating it with the given permissions if needed),
// then write-locks it and overwrites it with the given content.
-func Write(name string, content io.Reader, perm os.FileMode) (err error) {
+func Write(name string, content io.Reader, perm fs.FileMode) (err error) {
f, err := OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
if err != nil {
return err
diff --git a/src/cmd/go/internal/lockedfile/lockedfile_filelock.go b/src/cmd/go/internal/lockedfile/lockedfile_filelock.go
index f63dd8664b..10e1240efd 100644
--- a/src/cmd/go/internal/lockedfile/lockedfile_filelock.go
+++ b/src/cmd/go/internal/lockedfile/lockedfile_filelock.go
@@ -7,12 +7,13 @@
package lockedfile
import (
+ "io/fs"
"os"
"cmd/go/internal/lockedfile/internal/filelock"
)
-func openFile(name string, flag int, perm os.FileMode) (*os.File, error) {
+func openFile(name string, flag int, perm fs.FileMode) (*os.File, error) {
// On BSD systems, we could add the O_SHLOCK or O_EXLOCK flag to the OpenFile
// call instead of locking separately, but we have to support separate locking
// calls for Linux and Windows anyway, so it's simpler to use that approach
diff --git a/src/cmd/go/internal/lockedfile/lockedfile_plan9.go b/src/cmd/go/internal/lockedfile/lockedfile_plan9.go
index 4a52c94976..51681381d7 100644
--- a/src/cmd/go/internal/lockedfile/lockedfile_plan9.go
+++ b/src/cmd/go/internal/lockedfile/lockedfile_plan9.go
@@ -7,6 +7,7 @@
package lockedfile
import (
+ "io/fs"
"math/rand"
"os"
"strings"
@@ -41,7 +42,7 @@ func isLocked(err error) bool {
return false
}
-func openFile(name string, flag int, perm os.FileMode) (*os.File, error) {
+func openFile(name string, flag int, perm fs.FileMode) (*os.File, error) {
// Plan 9 uses a mode bit instead of explicit lock/unlock syscalls.
//
// Per http://man.cat-v.org/plan_9/5/stat: “Exclusive use files may be open
@@ -56,8 +57,8 @@ func openFile(name string, flag int, perm os.FileMode) (*os.File, error) {
// have the ModeExclusive bit set. Set it before we call OpenFile, so that we
// can be confident that a successful OpenFile implies exclusive use.
if fi, err := os.Stat(name); err == nil {
- if fi.Mode()&os.ModeExclusive == 0 {
- if err := os.Chmod(name, fi.Mode()|os.ModeExclusive); err != nil {
+ if fi.Mode()&fs.ModeExclusive == 0 {
+ if err := os.Chmod(name, fi.Mode()|fs.ModeExclusive); err != nil {
return nil, err
}
}
@@ -68,7 +69,7 @@ func openFile(name string, flag int, perm os.FileMode) (*os.File, error) {
nextSleep := 1 * time.Millisecond
const maxSleep = 500 * time.Millisecond
for {
- f, err := os.OpenFile(name, flag, perm|os.ModeExclusive)
+ f, err := os.OpenFile(name, flag, perm|fs.ModeExclusive)
if err == nil {
return f, nil
}
diff --git a/src/cmd/go/internal/modcmd/vendor.go b/src/cmd/go/internal/modcmd/vendor.go
index 1bc4ab3def..1b9ce60529 100644
--- a/src/cmd/go/internal/modcmd/vendor.go
+++ b/src/cmd/go/internal/modcmd/vendor.go
@@ -9,6 +9,7 @@ import (
"context"
"fmt"
"io"
+ "io/fs"
"io/ioutil"
"os"
"path/filepath"
@@ -232,7 +233,7 @@ var metaPrefixes = []string{
}
// matchMetadata reports whether info is a metadata file.
-func matchMetadata(dir string, info os.FileInfo) bool {
+func matchMetadata(dir string, info fs.FileInfo) bool {
name := info.Name()
for _, p := range metaPrefixes {
if strings.HasPrefix(name, p) {
@@ -243,7 +244,7 @@ func matchMetadata(dir string, info os.FileInfo) bool {
}
// matchPotentialSourceFile reports whether info may be relevant to a build operation.
-func matchPotentialSourceFile(dir string, info os.FileInfo) bool {
+func matchPotentialSourceFile(dir string, info fs.FileInfo) bool {
if strings.HasSuffix(info.Name(), "_test.go") {
return false
}
@@ -269,7 +270,7 @@ func matchPotentialSourceFile(dir string, info os.FileInfo) bool {
}
// copyDir copies all regular files satisfying match(info) from src to dst.
-func copyDir(dst, src string, match func(dir string, info os.FileInfo) bool) {
+func copyDir(dst, src string, match func(dir string, info fs.FileInfo) bool) {
files, err := ioutil.ReadDir(src)
if err != nil {
base.Fatalf("go mod vendor: %v", err)
diff --git a/src/cmd/go/internal/modcmd/verify.go b/src/cmd/go/internal/modcmd/verify.go
index bd591d3f32..ce24793929 100644
--- a/src/cmd/go/internal/modcmd/verify.go
+++ b/src/cmd/go/internal/modcmd/verify.go
@@ -9,6 +9,7 @@ import (
"context"
"errors"
"fmt"
+ "io/fs"
"io/ioutil"
"os"
"runtime"
@@ -88,8 +89,8 @@ func verifyMod(mod module.Version) []error {
dir, dirErr := modfetch.DownloadDir(mod)
data, err := ioutil.ReadFile(zip + "hash")
if err != nil {
- if zipErr != nil && errors.Is(zipErr, os.ErrNotExist) &&
- dirErr != nil && errors.Is(dirErr, os.ErrNotExist) {
+ if zipErr != nil && errors.Is(zipErr, fs.ErrNotExist) &&
+ dirErr != nil && errors.Is(dirErr, fs.ErrNotExist) {
// Nothing downloaded yet. Nothing to verify.
return nil
}
@@ -98,7 +99,7 @@ func verifyMod(mod module.Version) []error {
}
h := string(bytes.TrimSpace(data))
- if zipErr != nil && errors.Is(zipErr, os.ErrNotExist) {
+ if zipErr != nil && errors.Is(zipErr, fs.ErrNotExist) {
// ok
} else {
hZ, err := dirhash.HashZip(zip, dirhash.DefaultHash)
@@ -109,7 +110,7 @@ func verifyMod(mod module.Version) []error {
errs = append(errs, fmt.Errorf("%s %s: zip has been modified (%v)", mod.Path, mod.Version, zip))
}
}
- if dirErr != nil && errors.Is(dirErr, os.ErrNotExist) {
+ if dirErr != nil && errors.Is(dirErr, fs.ErrNotExist) {
// ok
} else {
hD, err := dirhash.HashDir(dir, mod.Path+"@"+mod.Version, dirhash.DefaultHash)
diff --git a/src/cmd/go/internal/modfetch/cache.go b/src/cmd/go/internal/modfetch/cache.go
index 6eadb026c9..b7aa670250 100644
--- a/src/cmd/go/internal/modfetch/cache.go
+++ b/src/cmd/go/internal/modfetch/cache.go
@@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"io"
+ "io/fs"
"io/ioutil"
"os"
"path/filepath"
@@ -60,7 +61,7 @@ func CachePath(m module.Version, suffix string) (string, error) {
// DownloadDir returns the directory to which m should have been downloaded.
// An error will be returned if the module path or version cannot be escaped.
-// An error satisfying errors.Is(err, os.ErrNotExist) will be returned
+// An error satisfying errors.Is(err, fs.ErrNotExist) will be returned
// along with the directory if the directory does not exist or if the directory
// is not completely populated.
func DownloadDir(m module.Version) (string, error) {
@@ -107,14 +108,14 @@ func DownloadDir(m module.Version) (string, error) {
// DownloadDirPartialError is returned by DownloadDir if a module directory
// exists but was not completely populated.
//
-// DownloadDirPartialError is equivalent to os.ErrNotExist.
+// DownloadDirPartialError is equivalent to fs.ErrNotExist.
type DownloadDirPartialError struct {
Dir string
Err error
}
func (e *DownloadDirPartialError) Error() string { return fmt.Sprintf("%s: %v", e.Dir, e.Err) }
-func (e *DownloadDirPartialError) Is(err error) bool { return err == os.ErrNotExist }
+func (e *DownloadDirPartialError) Is(err error) bool { return err == fs.ErrNotExist }
// lockVersion locks a file within the module cache that guards the downloading
// and extraction of the zipfile for the given module version.
diff --git a/src/cmd/go/internal/modfetch/codehost/codehost.go b/src/cmd/go/internal/modfetch/codehost/codehost.go
index df4cfdab1a..c5fbb31b2b 100644
--- a/src/cmd/go/internal/modfetch/codehost/codehost.go
+++ b/src/cmd/go/internal/modfetch/codehost/codehost.go
@@ -11,6 +11,7 @@ import (
"crypto/sha256"
"fmt"
"io"
+ "io/fs"
"io/ioutil"
"os"
"os/exec"
@@ -105,7 +106,7 @@ type FileRev struct {
Err error // error if any; os.IsNotExist(Err)==true if rev exists but file does not exist in that rev
}
-// UnknownRevisionError is an error equivalent to os.ErrNotExist, but for a
+// UnknownRevisionError is an error equivalent to fs.ErrNotExist, but for a
// revision rather than a file.
type UnknownRevisionError struct {
Rev string
@@ -115,10 +116,10 @@ func (e *UnknownRevisionError) Error() string {
return "unknown revision " + e.Rev
}
func (UnknownRevisionError) Is(err error) bool {
- return err == os.ErrNotExist
+ return err == fs.ErrNotExist
}
-// ErrNoCommits is an error equivalent to os.ErrNotExist indicating that a given
+// ErrNoCommits is an error equivalent to fs.ErrNotExist indicating that a given
// repository or module contains no commits.
var ErrNoCommits error = noCommitsError{}
@@ -128,7 +129,7 @@ func (noCommitsError) Error() string {
return "no commits"
}
func (noCommitsError) Is(err error) bool {
- return err == os.ErrNotExist
+ return err == fs.ErrNotExist
}
// AllHex reports whether the revision rev is entirely lower-case hexadecimal digits.
diff --git a/src/cmd/go/internal/modfetch/codehost/git.go b/src/cmd/go/internal/modfetch/codehost/git.go
index 5a35829c98..58b4b2f2d3 100644
--- a/src/cmd/go/internal/modfetch/codehost/git.go
+++ b/src/cmd/go/internal/modfetch/codehost/git.go
@@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"io"
+ "io/fs"
"io/ioutil"
"net/url"
"os"
@@ -34,13 +35,13 @@ func LocalGitRepo(remote string) (Repo, error) {
}
// A notExistError wraps another error to retain its original text
-// but makes it opaquely equivalent to os.ErrNotExist.
+// but makes it opaquely equivalent to fs.ErrNotExist.
type notExistError struct {
err error
}
func (e notExistError) Error() string { return e.err.Error() }
-func (notExistError) Is(err error) bool { return err == os.ErrNotExist }
+func (notExistError) Is(err error) bool { return err == fs.ErrNotExist }
const gitWorkDirType = "git3"
@@ -188,7 +189,7 @@ func (r *gitRepo) loadRefs() {
// For HTTP and HTTPS, that's easy to detect: we'll try to fetch the URL
// ourselves and see what code it serves.
if u, err := url.Parse(r.remoteURL); err == nil && (u.Scheme == "http" || u.Scheme == "https") {
- if _, err := web.GetBytes(u); errors.Is(err, os.ErrNotExist) {
+ if _, err := web.GetBytes(u); errors.Is(err, fs.ErrNotExist) {
gitErr = notExistError{gitErr}
}
}
@@ -505,7 +506,7 @@ func (r *gitRepo) ReadFile(rev, file string, maxSize int64) ([]byte, error) {
}
out, err := Run(r.dir, "git", "cat-file", "blob", info.Name+":"+file)
if err != nil {
- return nil, os.ErrNotExist
+ return nil, fs.ErrNotExist
}
return out, nil
}
@@ -629,9 +630,9 @@ func (r *gitRepo) readFileRevs(tags []string, file string, fileMap map[string]*F
case "tag", "commit":
switch fileType {
default:
- f.Err = &os.PathError{Path: tag + ":" + file, Op: "read", Err: fmt.Errorf("unexpected non-blob type %q", fileType)}
+ f.Err = &fs.PathError{Path: tag + ":" + file, Op: "read", Err: fmt.Errorf("unexpected non-blob type %q", fileType)}
case "missing":
- f.Err = &os.PathError{Path: tag + ":" + file, Op: "read", Err: os.ErrNotExist}
+ f.Err = &fs.PathError{Path: tag + ":" + file, Op: "read", Err: fs.ErrNotExist}
case "blob":
f.Data = fileData
}
@@ -826,7 +827,7 @@ func (r *gitRepo) ReadZip(rev, subdir string, maxSize int64) (zip io.ReadCloser,
archive, err := Run(r.dir, "git", "-c", "core.autocrlf=input", "-c", "core.eol=lf", "archive", "--format=zip", "--prefix=prefix/", info.Name, args)
if err != nil {
if bytes.Contains(err.(*RunError).Stderr, []byte("did not match any files")) {
- return nil, os.ErrNotExist
+ return nil, fs.ErrNotExist
}
return nil, err
}
diff --git a/src/cmd/go/internal/modfetch/codehost/git_test.go b/src/cmd/go/internal/modfetch/codehost/git_test.go
index ba27c70f5a..16908b3e84 100644
--- a/src/cmd/go/internal/modfetch/codehost/git_test.go
+++ b/src/cmd/go/internal/modfetch/codehost/git_test.go
@@ -10,6 +10,7 @@ import (
"flag"
"fmt"
"internal/testenv"
+ "io/fs"
"io/ioutil"
"log"
"os"
@@ -210,7 +211,7 @@ var readFileTests = []struct {
repo: gitrepo1,
rev: "v2.3.4",
file: "another.txt",
- err: os.ErrNotExist.Error(),
+ err: fs.ErrNotExist.Error(),
},
}
diff --git a/src/cmd/go/internal/modfetch/codehost/vcs.go b/src/cmd/go/internal/modfetch/codehost/vcs.go
index 6278cb21e1..ec97fc7e1b 100644
--- a/src/cmd/go/internal/modfetch/codehost/vcs.go
+++ b/src/cmd/go/internal/modfetch/codehost/vcs.go
@@ -9,6 +9,7 @@ import (
"fmt"
"internal/lazyregexp"
"io"
+ "io/fs"
"io/ioutil"
"os"
"path/filepath"
@@ -377,7 +378,7 @@ func (r *vcsRepo) ReadFile(rev, file string, maxSize int64) ([]byte, error) {
out, err := Run(r.dir, r.cmd.readFile(rev, file, r.remote))
if err != nil {
- return nil, os.ErrNotExist
+ return nil, fs.ErrNotExist
}
return out, nil
}
diff --git a/src/cmd/go/internal/modfetch/coderepo.go b/src/cmd/go/internal/modfetch/coderepo.go
index d99a31d360..7f44e18a70 100644
--- a/src/cmd/go/internal/modfetch/coderepo.go
+++ b/src/cmd/go/internal/modfetch/coderepo.go
@@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"io"
+ "io/fs"
"io/ioutil"
"os"
"path"
@@ -1040,7 +1041,7 @@ type zipFile struct {
}
func (f zipFile) Path() string { return f.name }
-func (f zipFile) Lstat() (os.FileInfo, error) { return f.f.FileInfo(), nil }
+func (f zipFile) Lstat() (fs.FileInfo, error) { return f.f.FileInfo(), nil }
func (f zipFile) Open() (io.ReadCloser, error) { return f.f.Open() }
type dataFile struct {
@@ -1049,7 +1050,7 @@ type dataFile struct {
}
func (f dataFile) Path() string { return f.name }
-func (f dataFile) Lstat() (os.FileInfo, error) { return dataFileInfo{f}, nil }
+func (f dataFile) Lstat() (fs.FileInfo, error) { return dataFileInfo{f}, nil }
func (f dataFile) Open() (io.ReadCloser, error) {
return ioutil.NopCloser(bytes.NewReader(f.data)), nil
}
@@ -1060,7 +1061,7 @@ type dataFileInfo struct {
func (fi dataFileInfo) Name() string { return path.Base(fi.f.name) }
func (fi dataFileInfo) Size() int64 { return int64(len(fi.f.data)) }
-func (fi dataFileInfo) Mode() os.FileMode { return 0644 }
+func (fi dataFileInfo) Mode() fs.FileMode { return 0644 }
func (fi dataFileInfo) ModTime() time.Time { return time.Time{} }
func (fi dataFileInfo) IsDir() bool { return false }
func (fi dataFileInfo) Sys() interface{} { return nil }
diff --git a/src/cmd/go/internal/modfetch/fetch.go b/src/cmd/go/internal/modfetch/fetch.go
index 599419977a..6ff455e89c 100644
--- a/src/cmd/go/internal/modfetch/fetch.go
+++ b/src/cmd/go/internal/modfetch/fetch.go
@@ -11,6 +11,7 @@ import (
"errors"
"fmt"
"io"
+ "io/fs"
"io/ioutil"
"os"
"path/filepath"
@@ -67,7 +68,7 @@ func download(ctx context.Context, mod module.Version) (dir string, err error) {
if err == nil {
// The directory has already been completely extracted (no .partial file exists).
return dir, nil
- } else if dir == "" || !errors.Is(err, os.ErrNotExist) {
+ } else if dir == "" || !errors.Is(err, fs.ErrNotExist) {
return "", err
}
@@ -314,10 +315,10 @@ func downloadZip(ctx context.Context, mod module.Version, zipfile string) (err e
func makeDirsReadOnly(dir string) {
type pathMode struct {
path string
- mode os.FileMode
+ mode fs.FileMode
}
var dirs []pathMode // in lexical order
- filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
+ filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
if err == nil && info.Mode()&0222 != 0 {
if info.IsDir() {
dirs = append(dirs, pathMode{path, info.Mode()})
@@ -336,7 +337,7 @@ func makeDirsReadOnly(dir string) {
// any permission changes needed to do so.
func RemoveAll(dir string) error {
// Module cache has 0555 directories; make them writable in order to remove content.
- filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
+ filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return nil // ignore errors walking in file system
}
@@ -441,7 +442,7 @@ func checkMod(mod module.Version) {
}
data, err := renameio.ReadFile(ziphash)
if err != nil {
- if errors.Is(err, os.ErrNotExist) {
+ if errors.Is(err, fs.ErrNotExist) {
// This can happen if someone does rm -rf GOPATH/src/cache/download. So it goes.
return
}
diff --git a/src/cmd/go/internal/modfetch/proxy.go b/src/cmd/go/internal/modfetch/proxy.go
index 4ac26650a9..819990b403 100644
--- a/src/cmd/go/internal/modfetch/proxy.go
+++ b/src/cmd/go/internal/modfetch/proxy.go
@@ -9,9 +9,9 @@ import (
"errors"
"fmt"
"io"
+ "io/fs"
"io/ioutil"
"net/url"
- "os"
"path"
pathpkg "path"
"path/filepath"
@@ -186,7 +186,7 @@ func proxyList() ([]proxySpec, error) {
// TryProxies iterates f over each configured proxy (including "noproxy" and
// "direct" if applicable) until f returns no error or until f returns an
-// error that is not equivalent to os.ErrNotExist on a proxy configured
+// error that is not equivalent to fs.ErrNotExist on a proxy configured
// not to fall back on errors.
//
// TryProxies then returns that final error.
@@ -222,7 +222,7 @@ func TryProxies(f func(proxy string) error) error {
if err == nil {
return nil
}
- isNotExistErr := errors.Is(err, os.ErrNotExist)
+ isNotExistErr := errors.Is(err, fs.ErrNotExist)
if proxy.url == "direct" || (proxy.url == "noproxy" && err != errUseProxy) {
bestErr = err
@@ -428,7 +428,7 @@ func (p *proxyRepo) Stat(rev string) (*RevInfo, error) {
func (p *proxyRepo) Latest() (*RevInfo, error) {
data, err := p.getBytes("@latest")
if err != nil {
- if !errors.Is(err, os.ErrNotExist) {
+ if !errors.Is(err, fs.ErrNotExist) {
return nil, p.versionError("", err)
}
return p.latest()
diff --git a/src/cmd/go/internal/modfetch/repo.go b/src/cmd/go/internal/modfetch/repo.go
index c7cf5595bd..af9e24cefd 100644
--- a/src/cmd/go/internal/modfetch/repo.go
+++ b/src/cmd/go/internal/modfetch/repo.go
@@ -7,6 +7,7 @@ package modfetch
import (
"fmt"
"io"
+ "io/fs"
"os"
"sort"
"strconv"
@@ -432,7 +433,7 @@ func (r errRepo) Latest() (*RevInfo, error) { return nil
func (r errRepo) GoMod(version string) ([]byte, error) { return nil, r.err }
func (r errRepo) Zip(dst io.Writer, version string) error { return r.err }
-// A notExistError is like os.ErrNotExist, but with a custom message
+// A notExistError is like fs.ErrNotExist, but with a custom message
type notExistError struct {
err error
}
@@ -446,7 +447,7 @@ func (e notExistError) Error() string {
}
func (notExistError) Is(target error) bool {
- return target == os.ErrNotExist
+ return target == fs.ErrNotExist
}
func (e notExistError) Unwrap() error {
diff --git a/src/cmd/go/internal/modfetch/sumdb.go b/src/cmd/go/internal/modfetch/sumdb.go
index 47a2571531..5108961a33 100644
--- a/src/cmd/go/internal/modfetch/sumdb.go
+++ b/src/cmd/go/internal/modfetch/sumdb.go
@@ -12,6 +12,7 @@ import (
"bytes"
"errors"
"fmt"
+ "io/fs"
"io/ioutil"
"net/url"
"os"
@@ -182,7 +183,7 @@ func (c *dbClient) initBase() {
return nil
}
})
- if errors.Is(err, os.ErrNotExist) {
+ if errors.Is(err, fs.ErrNotExist) {
// No proxies, or all proxies failed (with 404, 410, or were were allowed
// to fall back), or we reached an explicit "direct" or "off".
c.base = c.direct
@@ -203,7 +204,7 @@ func (c *dbClient) ReadConfig(file string) (data []byte, err error) {
}
targ := filepath.Join(cfg.SumdbDir, file)
data, err = lockedfile.Read(targ)
- if errors.Is(err, os.ErrNotExist) {
+ if errors.Is(err, fs.ErrNotExist) {
// Treat non-existent as empty, to bootstrap the "latest" file
// the first time we connect to a given database.
return []byte{}, nil
@@ -257,7 +258,7 @@ func (*dbClient) ReadCache(file string) ([]byte, error) {
// during which the empty file can be locked for reading.
// Treat observing an empty file as file not found.
if err == nil && len(data) == 0 {
- err = &os.PathError{Op: "read", Path: targ, Err: os.ErrNotExist}
+ err = &fs.PathError{Op: "read", Path: targ, Err: fs.ErrNotExist}
}
return data, err
}
diff --git a/src/cmd/go/internal/modload/import.go b/src/cmd/go/internal/modload/import.go
index 6d0d8de944..bcbc9b0c3a 100644
--- a/src/cmd/go/internal/modload/import.go
+++ b/src/cmd/go/internal/modload/import.go
@@ -10,6 +10,7 @@ import (
"fmt"
"go/build"
"internal/goroot"
+ "io/fs"
"os"
"path/filepath"
"sort"
@@ -347,7 +348,7 @@ func queryImport(ctx context.Context, path string) (module.Version, error) {
candidates, err := QueryPattern(ctx, path, "latest", Selected, CheckAllowed)
if err != nil {
- if errors.Is(err, os.ErrNotExist) {
+ if errors.Is(err, fs.ErrNotExist) {
// Return "cannot find module providing package […]" instead of whatever
// low-level error QueryPattern produced.
return module.Version{}, &ImportMissingError{Path: path, QueryErr: err}
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go
index 4ddb817cf1..4b3ded8326 100644
--- a/src/cmd/go/internal/modload/load.go
+++ b/src/cmd/go/internal/modload/load.go
@@ -98,6 +98,7 @@ import (
"errors"
"fmt"
"go/build"
+ "io/fs"
"os"
"path"
pathpkg "path"
@@ -364,7 +365,7 @@ func resolveLocalPackage(dir string) (string, error) {
if os.IsNotExist(err) {
// Canonicalize OS-specific errors to errDirectoryNotFound so that error
// messages will be easier for users to search for.
- return "", &os.PathError{Op: "stat", Path: absDir, Err: errDirectoryNotFound}
+ return "", &fs.PathError{Op: "stat", Path: absDir, Err: errDirectoryNotFound}
}
return "", err
}
diff --git a/src/cmd/go/internal/modload/query.go b/src/cmd/go/internal/modload/query.go
index 3b27e66d01..6b14768388 100644
--- a/src/cmd/go/internal/modload/query.go
+++ b/src/cmd/go/internal/modload/query.go
@@ -8,6 +8,7 @@ import (
"context"
"errors"
"fmt"
+ "io/fs"
"os"
pathpkg "path"
"path/filepath"
@@ -145,7 +146,7 @@ func queryProxy(ctx context.Context, proxy, path, query, current string, allowed
canonicalQuery := module.CanonicalVersion(query)
if canonicalQuery != "" && query != canonicalQuery {
info, err = repo.Stat(canonicalQuery)
- if err != nil && !errors.Is(err, os.ErrNotExist) {
+ if err != nil && !errors.Is(err, fs.ErrNotExist) {
return info, err
}
}
@@ -230,7 +231,7 @@ func queryProxy(ctx context.Context, proxy, path, query, current string, allowed
if qm.allowsVersion(ctx, latest.Version) {
return lookup(latest.Version)
}
- } else if !errors.Is(err, os.ErrNotExist) {
+ } else if !errors.Is(err, fs.ErrNotExist) {
return nil, err
}
}
@@ -701,7 +702,7 @@ func queryPrefixModules(ctx context.Context, candidateModules []string, queryMod
noVersion = rErr
}
default:
- if errors.Is(rErr, os.ErrNotExist) {
+ if errors.Is(rErr, fs.ErrNotExist) {
if notExistErr == nil {
notExistErr = rErr
}
@@ -744,7 +745,7 @@ func queryPrefixModules(ctx context.Context, candidateModules []string, queryMod
// A NoMatchingVersionError indicates that Query found a module at the requested
// path, but not at any versions satisfying the query string and allow-function.
//
-// NOTE: NoMatchingVersionError MUST NOT implement Is(os.ErrNotExist).
+// NOTE: NoMatchingVersionError MUST NOT implement Is(fs.ErrNotExist).
//
// If the module came from a proxy, that proxy had to return a successful status
// code for the versions it knows about, and thus did not have the opportunity
@@ -765,7 +766,7 @@ func (e *NoMatchingVersionError) Error() string {
// module at the requested version, but that module did not contain any packages
// matching the requested pattern.
//
-// NOTE: PackageNotInModuleError MUST NOT implement Is(os.ErrNotExist).
+// NOTE: PackageNotInModuleError MUST NOT implement Is(fs.ErrNotExist).
//
// If the module came from a proxy, that proxy had to return a successful status
// code for the versions it knows about, and thus did not have the opportunity
diff --git a/src/cmd/go/internal/modload/search.go b/src/cmd/go/internal/modload/search.go
index 0f82026732..19289ceb9c 100644
--- a/src/cmd/go/internal/modload/search.go
+++ b/src/cmd/go/internal/modload/search.go
@@ -7,6 +7,7 @@ package modload
import (
"context"
"fmt"
+ "io/fs"
"os"
"path/filepath"
"strings"
@@ -54,7 +55,7 @@ func matchPackages(ctx context.Context, m *search.Match, tags map[string]bool, f
walkPkgs := func(root, importPathRoot string, prune pruning) {
root = filepath.Clean(root)
- err := fsys.Walk(root, func(path string, fi os.FileInfo, err error) error {
+ err := fsys.Walk(root, func(path string, fi fs.FileInfo, err error) error {
if err != nil {
m.AddError(err)
return nil
@@ -85,7 +86,7 @@ func matchPackages(ctx context.Context, m *search.Match, tags map[string]bool, f
}
if !fi.IsDir() {
- if fi.Mode()&os.ModeSymlink != 0 && want {
+ if fi.Mode()&fs.ModeSymlink != 0 && want {
if target, err := os.Stat(path); err == nil && target.IsDir() {
fmt.Fprintf(os.Stderr, "warning: ignoring symlink %s\n", path)
}
diff --git a/src/cmd/go/internal/modload/stat_openfile.go b/src/cmd/go/internal/modload/stat_openfile.go
index 931aaf1577..7cdeaf47a2 100644
--- a/src/cmd/go/internal/modload/stat_openfile.go
+++ b/src/cmd/go/internal/modload/stat_openfile.go
@@ -13,12 +13,13 @@
package modload
import (
+ "io/fs"
"os"
)
// hasWritePerm reports whether the current user has permission to write to the
// file with the given info.
-func hasWritePerm(path string, _ os.FileInfo) bool {
+func hasWritePerm(path string, _ fs.FileInfo) bool {
if f, err := os.OpenFile(path, os.O_WRONLY, 0); err == nil {
f.Close()
return true
diff --git a/src/cmd/go/internal/modload/stat_unix.go b/src/cmd/go/internal/modload/stat_unix.go
index ea3b801f2c..65068444d0 100644
--- a/src/cmd/go/internal/modload/stat_unix.go
+++ b/src/cmd/go/internal/modload/stat_unix.go
@@ -7,6 +7,7 @@
package modload
import (
+ "io/fs"
"os"
"syscall"
)
@@ -17,7 +18,7 @@ import (
// Although the root user on most Unix systems can write to files even without
// permission, hasWritePerm reports false if no appropriate permission bit is
// set even if the current user is root.
-func hasWritePerm(path string, fi os.FileInfo) bool {
+func hasWritePerm(path string, fi fs.FileInfo) bool {
if os.Getuid() == 0 {
// The root user can access any file, but we still want to default to
// read-only mode if the go.mod file is marked as globally non-writable.
diff --git a/src/cmd/go/internal/modload/stat_windows.go b/src/cmd/go/internal/modload/stat_windows.go
index d7826cfc6b..0ac2391347 100644
--- a/src/cmd/go/internal/modload/stat_windows.go
+++ b/src/cmd/go/internal/modload/stat_windows.go
@@ -6,13 +6,11 @@
package modload
-import (
- "os"
-)
+import "io/fs"
// hasWritePerm reports whether the current user has permission to write to the
// file with the given info.
-func hasWritePerm(_ string, fi os.FileInfo) bool {
+func hasWritePerm(_ string, fi fs.FileInfo) bool {
// Windows has a read-only attribute independent of ACLs, so use that to
// determine whether the file is intended to be overwritten.
//
diff --git a/src/cmd/go/internal/modload/vendor.go b/src/cmd/go/internal/modload/vendor.go
index 9f34b829fc..ab29d4d014 100644
--- a/src/cmd/go/internal/modload/vendor.go
+++ b/src/cmd/go/internal/modload/vendor.go
@@ -7,8 +7,8 @@ package modload
import (
"errors"
"fmt"
+ "io/fs"
"io/ioutil"
- "os"
"path/filepath"
"strings"
"sync"
@@ -42,7 +42,7 @@ func readVendorList() {
vendorMeta = make(map[module.Version]vendorMetadata)
data, err := ioutil.ReadFile(filepath.Join(ModRoot(), "vendor/modules.txt"))
if err != nil {
- if !errors.Is(err, os.ErrNotExist) {
+ if !errors.Is(err, fs.ErrNotExist) {
base.Fatalf("go: %s", err)
}
return
diff --git a/src/cmd/go/internal/renameio/renameio.go b/src/cmd/go/internal/renameio/renameio.go
index d573cc690d..60a7138a76 100644
--- a/src/cmd/go/internal/renameio/renameio.go
+++ b/src/cmd/go/internal/renameio/renameio.go
@@ -8,6 +8,7 @@ package renameio
import (
"bytes"
"io"
+ "io/fs"
"math/rand"
"os"
"path/filepath"
@@ -29,13 +30,13 @@ func Pattern(filename string) string {
// final name.
//
// That ensures that the final location, if it exists, is always a complete file.
-func WriteFile(filename string, data []byte, perm os.FileMode) (err error) {
+func WriteFile(filename string, data []byte, perm fs.FileMode) (err error) {
return WriteToFile(filename, bytes.NewReader(data), perm)
}
// WriteToFile is a variant of WriteFile that accepts the data as an io.Reader
// instead of a slice.
-func WriteToFile(filename string, data io.Reader, perm os.FileMode) (err error) {
+func WriteToFile(filename string, data io.Reader, perm fs.FileMode) (err error) {
f, err := tempFile(filepath.Dir(filename), filepath.Base(filename), perm)
if err != nil {
return err
@@ -80,7 +81,7 @@ func ReadFile(filename string) ([]byte, error) {
}
// tempFile creates a new temporary file with given permission bits.
-func tempFile(dir, prefix string, perm os.FileMode) (f *os.File, err error) {
+func tempFile(dir, prefix string, perm fs.FileMode) (f *os.File, err error) {
for i := 0; i < 10000; i++ {
name := filepath.Join(dir, prefix+strconv.Itoa(rand.Intn(1000000000))+patternSuffix)
f, err = os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, perm)
diff --git a/src/cmd/go/internal/renameio/umask_test.go b/src/cmd/go/internal/renameio/umask_test.go
index d75d67c9a9..19e217c548 100644
--- a/src/cmd/go/internal/renameio/umask_test.go
+++ b/src/cmd/go/internal/renameio/umask_test.go
@@ -7,6 +7,7 @@
package renameio
import (
+ "io/fs"
"io/ioutil"
"os"
"path/filepath"
@@ -36,7 +37,7 @@ func TestWriteFileModeAppliesUmask(t *testing.T) {
t.Fatalf("Stat %q (looking for mode %#o): %s", file, mode, err)
}
- if fi.Mode()&os.ModePerm != 0640 {
- t.Errorf("Stat %q: mode %#o want %#o", file, fi.Mode()&os.ModePerm, 0640)
+ if fi.Mode()&fs.ModePerm != 0640 {
+ t.Errorf("Stat %q: mode %#o want %#o", file, fi.Mode()&fs.ModePerm, 0640)
}
}
diff --git a/src/cmd/go/internal/search/search.go b/src/cmd/go/internal/search/search.go
index b1d2a9376b..e4784e9478 100644
--- a/src/cmd/go/internal/search/search.go
+++ b/src/cmd/go/internal/search/search.go
@@ -10,6 +10,7 @@ import (
"cmd/go/internal/fsys"
"fmt"
"go/build"
+ "io/fs"
"os"
"path"
"path/filepath"
@@ -128,7 +129,7 @@ func (m *Match) MatchPackages() {
if m.pattern == "cmd" {
root += "cmd" + string(filepath.Separator)
}
- err := fsys.Walk(root, func(path string, fi os.FileInfo, err error) error {
+ err := fsys.Walk(root, func(path string, fi fs.FileInfo, err error) error {
if err != nil {
return err // Likely a permission error, which could interfere with matching.
}
@@ -154,7 +155,7 @@ func (m *Match) MatchPackages() {
}
if !fi.IsDir() {
- if fi.Mode()&os.ModeSymlink != 0 && want {
+ if fi.Mode()&fs.ModeSymlink != 0 && want {
if target, err := os.Stat(path); err == nil && target.IsDir() {
fmt.Fprintf(os.Stderr, "warning: ignoring symlink %s\n", path)
}
@@ -264,7 +265,7 @@ func (m *Match) MatchDirs() {
}
}
- err := fsys.Walk(dir, func(path string, fi os.FileInfo, err error) error {
+ err := fsys.Walk(dir, func(path string, fi fs.FileInfo, err error) error {
if err != nil {
return err // Likely a permission error, which could interfere with matching.
}
diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go
index 51d333d866..00da9770df 100644
--- a/src/cmd/go/internal/test/test.go
+++ b/src/cmd/go/internal/test/test.go
@@ -12,6 +12,7 @@ import (
"fmt"
"go/build"
"io"
+ "io/fs"
"io/ioutil"
"os"
"os/exec"
@@ -1598,7 +1599,7 @@ func hashStat(name string) cache.ActionID {
return h.Sum()
}
-func hashWriteStat(h io.Writer, info os.FileInfo) {
+func hashWriteStat(h io.Writer, info fs.FileInfo) {
fmt.Fprintf(h, "stat %d %x %v %v\n", info.Size(), uint64(info.Mode()), info.ModTime(), info.IsDir())
}
diff --git a/src/cmd/go/internal/vcs/vcs.go b/src/cmd/go/internal/vcs/vcs.go
index 90bf10244d..7812afd488 100644
--- a/src/cmd/go/internal/vcs/vcs.go
+++ b/src/cmd/go/internal/vcs/vcs.go
@@ -10,6 +10,7 @@ import (
"fmt"
"internal/lazyregexp"
"internal/singleflight"
+ "io/fs"
"log"
urlpkg "net/url"
"os"
@@ -404,9 +405,9 @@ func (v *Cmd) run1(dir string, cmdline string, keyval []string, verbose bool) ([
if len(args) >= 2 && args[0] == "-go-internal-mkdir" {
var err error
if filepath.IsAbs(args[1]) {
- err = os.Mkdir(args[1], os.ModePerm)
+ err = os.Mkdir(args[1], fs.ModePerm)
} else {
- err = os.Mkdir(filepath.Join(dir, args[1]), os.ModePerm)
+ err = os.Mkdir(filepath.Join(dir, args[1]), fs.ModePerm)
}
if err != nil {
return nil, err
diff --git a/src/cmd/go/internal/version/version.go b/src/cmd/go/internal/version/version.go
index 5aa0f8e7ed..44ac24c62d 100644
--- a/src/cmd/go/internal/version/version.go
+++ b/src/cmd/go/internal/version/version.go
@@ -10,6 +10,7 @@ import (
"context"
"encoding/binary"
"fmt"
+ "io/fs"
"os"
"path/filepath"
"runtime"
@@ -87,8 +88,8 @@ func runVersion(ctx context.Context, cmd *base.Command, args []string) {
// scanDir scans a directory for executables to run scanFile on.
func scanDir(dir string) {
- filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
- if info.Mode().IsRegular() || info.Mode()&os.ModeSymlink != 0 {
+ filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
+ if info.Mode().IsRegular() || info.Mode()&fs.ModeSymlink != 0 {
scanFile(path, info, *versionV)
}
return nil
@@ -96,7 +97,7 @@ func scanDir(dir string) {
}
// isExe reports whether the file should be considered executable.
-func isExe(file string, info os.FileInfo) bool {
+func isExe(file string, info fs.FileInfo) bool {
if runtime.GOOS == "windows" {
return strings.HasSuffix(strings.ToLower(file), ".exe")
}
@@ -107,8 +108,8 @@ func isExe(file string, info os.FileInfo) bool {
// If mustPrint is true, scanFile will report any error reading file.
// Otherwise (mustPrint is false, because scanFile is being called
// by scanDir) scanFile prints nothing for non-Go executables.
-func scanFile(file string, info os.FileInfo, mustPrint bool) {
- if info.Mode()&os.ModeSymlink != 0 {
+func scanFile(file string, info fs.FileInfo, mustPrint bool) {
+ if info.Mode()&fs.ModeSymlink != 0 {
// Accept file symlinks only.
i, err := os.Stat(file)
if err != nil || !i.Mode().IsRegular() {
diff --git a/src/cmd/go/internal/web/api.go b/src/cmd/go/internal/web/api.go
index 570818843b..f7d3ed60f6 100644
--- a/src/cmd/go/internal/web/api.go
+++ b/src/cmd/go/internal/web/api.go
@@ -13,9 +13,9 @@ import (
"bytes"
"fmt"
"io"
+ "io/fs"
"io/ioutil"
"net/url"
- "os"
"strings"
"unicode"
"unicode/utf8"
@@ -56,7 +56,7 @@ func (e *HTTPError) Error() string {
}
if err := e.Err; err != nil {
- if pErr, ok := e.Err.(*os.PathError); ok && strings.HasSuffix(e.URL, pErr.Path) {
+ if pErr, ok := e.Err.(*fs.PathError); ok && strings.HasSuffix(e.URL, pErr.Path) {
// Remove the redundant copy of the path.
err = pErr.Err
}
@@ -67,7 +67,7 @@ func (e *HTTPError) Error() string {
}
func (e *HTTPError) Is(target error) bool {
- return target == os.ErrNotExist && (e.StatusCode == 404 || e.StatusCode == 410)
+ return target == fs.ErrNotExist && (e.StatusCode == 404 || e.StatusCode == 410)
}
func (e *HTTPError) Unwrap() error {
diff --git a/src/cmd/go/internal/web/file_test.go b/src/cmd/go/internal/web/file_test.go
index 6339469045..a1bb080e07 100644
--- a/src/cmd/go/internal/web/file_test.go
+++ b/src/cmd/go/internal/web/file_test.go
@@ -6,6 +6,7 @@ package web
import (
"errors"
+ "io/fs"
"io/ioutil"
"os"
"path/filepath"
@@ -54,7 +55,7 @@ func TestGetNonexistentFile(t *testing.T) {
}
b, err := GetBytes(u)
- if !errors.Is(err, os.ErrNotExist) {
- t.Fatalf("GetBytes(%v) = %q, %v; want _, os.ErrNotExist", u, b, err)
+ if !errors.Is(err, fs.ErrNotExist) {
+ t.Fatalf("GetBytes(%v) = %q, %v; want _, fs.ErrNotExist", u, b, err)
}
}
diff --git a/src/cmd/go/internal/work/build_test.go b/src/cmd/go/internal/work/build_test.go
index 904aee0684..e941729734 100644
--- a/src/cmd/go/internal/work/build_test.go
+++ b/src/cmd/go/internal/work/build_test.go
@@ -7,6 +7,7 @@ package work
import (
"bytes"
"fmt"
+ "io/fs"
"io/ioutil"
"os"
"path/filepath"
@@ -253,7 +254,7 @@ func TestRespectSetgidDir(t *testing.T) {
}
// Change setgiddir's permissions to include the SetGID bit.
- if err := os.Chmod(setgiddir, 0755|os.ModeSetgid); err != nil {
+ if err := os.Chmod(setgiddir, 0755|fs.ModeSetgid); err != nil {
t.Fatal(err)
}
diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
index 824a4b5a0a..717b0cc3af 100644
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -14,6 +14,7 @@ import (
"fmt"
"internal/lazyregexp"
"io"
+ "io/fs"
"io/ioutil"
"log"
"math/rand"
@@ -1560,7 +1561,7 @@ func BuildInstallFunc(b *Builder, ctx context.Context, a *Action) (err error) {
return err
}
- perm := os.FileMode(0666)
+ perm := fs.FileMode(0666)
if a1.Mode == "link" {
switch cfg.BuildBuildmode {
case "c-archive", "c-shared", "plugin":
@@ -1609,7 +1610,7 @@ func (b *Builder) cleanup(a *Action) {
}
// moveOrCopyFile is like 'mv src dst' or 'cp src dst'.
-func (b *Builder) moveOrCopyFile(dst, src string, perm os.FileMode, force bool) error {
+func (b *Builder) moveOrCopyFile(dst, src string, perm fs.FileMode, force bool) error {
if cfg.BuildN {
b.Showcmd("", "mv %s %s", src, dst)
return nil
@@ -1635,7 +1636,7 @@ func (b *Builder) moveOrCopyFile(dst, src string, perm os.FileMode, force bool)
// we have to copy the file to retain the correct permissions.
// https://golang.org/issue/18878
if fi, err := os.Stat(filepath.Dir(dst)); err == nil {
- if fi.IsDir() && (fi.Mode()&os.ModeSetgid) != 0 {
+ if fi.IsDir() && (fi.Mode()&fs.ModeSetgid) != 0 {
return b.copyFile(dst, src, perm, force)
}
}
@@ -1670,7 +1671,7 @@ func (b *Builder) moveOrCopyFile(dst, src string, perm os.FileMode, force bool)
}
// copyFile is like 'cp src dst'.
-func (b *Builder) copyFile(dst, src string, perm os.FileMode, force bool) error {
+func (b *Builder) copyFile(dst, src string, perm fs.FileMode, force bool) error {
if cfg.BuildN || cfg.BuildX {
b.Showcmd("", "cp %s %s", src, dst)
if cfg.BuildN {
diff --git a/src/cmd/go/proxy_test.go b/src/cmd/go/proxy_test.go
index 42972f5b2a..8b0dbb74b2 100644
--- a/src/cmd/go/proxy_test.go
+++ b/src/cmd/go/proxy_test.go
@@ -12,6 +12,7 @@ import (
"flag"
"fmt"
"io"
+ "io/fs"
"io/ioutil"
"log"
"net"
@@ -335,7 +336,7 @@ func proxyHandler(w http.ResponseWriter, r *http.Request) {
if testing.Verbose() {
fmt.Fprintf(os.Stderr, "go proxy: no archive %s %s: %v\n", path, vers, err)
}
- if errors.Is(err, os.ErrNotExist) {
+ if errors.Is(err, fs.ErrNotExist) {
http.NotFound(w, r)
} else {
http.Error(w, "cannot load archive", 500)
@@ -443,7 +444,7 @@ func readArchive(path, vers string) (*txtar.Archive, error) {
return a
}).(*txtar.Archive)
if a == nil {
- return nil, os.ErrNotExist
+ return nil, fs.ErrNotExist
}
return a, nil
}
diff --git a/src/cmd/go/script_test.go b/src/cmd/go/script_test.go
index 986646252a..a31561cd86 100644
--- a/src/cmd/go/script_test.go
+++ b/src/cmd/go/script_test.go
@@ -14,6 +14,7 @@ import (
"fmt"
"go/build"
"internal/testenv"
+ "io/fs"
"io/ioutil"
"os"
"os/exec"
@@ -500,7 +501,7 @@ func (ts *testScript) cmdChmod(want simpleStatus, args []string) {
ts.fatalf("usage: chmod perm paths...")
}
perm, err := strconv.ParseUint(args[0], 0, 32)
- if err != nil || perm&uint64(os.ModePerm) != perm {
+ if err != nil || perm&uint64(fs.ModePerm) != perm {
ts.fatalf("invalid mode: %s", args[0])
}
for _, arg := range args[1:] {
@@ -508,7 +509,7 @@ func (ts *testScript) cmdChmod(want simpleStatus, args []string) {
if !filepath.IsAbs(path) {
path = filepath.Join(ts.cd, arg)
}
- err := os.Chmod(path, os.FileMode(perm))
+ err := os.Chmod(path, fs.FileMode(perm))
ts.check(err)
}
}
@@ -595,7 +596,7 @@ func (ts *testScript) cmdCp(want simpleStatus, args []string) {
var (
src string
data []byte
- mode os.FileMode
+ mode fs.FileMode
)
switch arg {
case "stdout":
diff --git a/src/cmd/go/testdata/addmod.go b/src/cmd/go/testdata/addmod.go
index d9c3aab9c4..d1b6467c5d 100644
--- a/src/cmd/go/testdata/addmod.go
+++ b/src/cmd/go/testdata/addmod.go
@@ -22,6 +22,7 @@ import (
"bytes"
"flag"
"fmt"
+ "io/fs"
"io/ioutil"
"log"
"os"
@@ -121,7 +122,7 @@ func main() {
{Name: ".info", Data: info},
}
dir = filepath.Clean(dir)
- err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
+ err = filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
if !info.Mode().IsRegular() {
return nil
}
diff --git a/src/cmd/go/testdata/savedir.go b/src/cmd/go/testdata/savedir.go
index 48a6318860..04902df61e 100644
--- a/src/cmd/go/testdata/savedir.go
+++ b/src/cmd/go/testdata/savedir.go
@@ -17,6 +17,7 @@ package main
import (
"flag"
"fmt"
+ "io/fs"
"io/ioutil"
"log"
"os"
@@ -48,7 +49,7 @@ func main() {
a := new(txtar.Archive)
dir = filepath.Clean(dir)
- filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
+ filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
if path == dir {
return nil
}
diff --git a/src/cmd/gofmt/gofmt.go b/src/cmd/gofmt/gofmt.go
index 8c56af7559..48b6ad6f53 100644
--- a/src/cmd/gofmt/gofmt.go
+++ b/src/cmd/gofmt/gofmt.go
@@ -14,6 +14,7 @@ import (
"go/scanner"
"go/token"
"io"
+ "io/fs"
"io/ioutil"
"os"
"path/filepath"
@@ -73,7 +74,7 @@ func initParserMode() {
}
}
-func isGoFile(f os.FileInfo) bool {
+func isGoFile(f fs.FileInfo) bool {
// ignore non-Go files
name := f.Name()
return !f.IsDir() && !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".go")
@@ -81,7 +82,7 @@ func isGoFile(f os.FileInfo) bool {
// If in == nil, the source is the contents of the file with the given filename.
func processFile(filename string, in io.Reader, out io.Writer, stdin bool) error {
- var perm os.FileMode = 0644
+ var perm fs.FileMode = 0644
if in == nil {
f, err := os.Open(filename)
if err != nil {
@@ -163,7 +164,7 @@ func processFile(filename string, in io.Reader, out io.Writer, stdin bool) error
return err
}
-func visitFile(path string, f os.FileInfo, err error) error {
+func visitFile(path string, f fs.FileInfo, err error) error {
if err == nil && isGoFile(f) {
err = processFile(path, nil, os.Stdout, false)
}
@@ -275,7 +276,7 @@ const chmodSupported = runtime.GOOS != "windows"
// backupFile writes data to a new file named filename<number> with permissions perm,
// with <number randomly chosen such that the file name is unique. backupFile returns
// the chosen file name.
-func backupFile(filename string, data []byte, perm os.FileMode) (string, error) {
+func backupFile(filename string, data []byte, perm fs.FileMode) (string, error) {
// create backup file
f, err := ioutil.TempFile(filepath.Dir(filename), filepath.Base(filename))
if err != nil {
diff --git a/src/cmd/gofmt/long_test.go b/src/cmd/gofmt/long_test.go
index e2a6208f87..28306ce83e 100644
--- a/src/cmd/gofmt/long_test.go
+++ b/src/cmd/gofmt/long_test.go
@@ -16,6 +16,7 @@ import (
"go/printer"
"go/token"
"io"
+ "io/fs"
"os"
"path/filepath"
"runtime"
@@ -107,7 +108,7 @@ func testFiles(t *testing.T, filenames <-chan string, done chan<- int) {
func genFilenames(t *testing.T, filenames chan<- string) {
defer close(filenames)
- handleFile := func(filename string, fi os.FileInfo, err error) error {
+ handleFile := func(filename string, fi fs.FileInfo, err error) error {
if err != nil {
t.Error(err)
return nil
diff --git a/src/cmd/internal/buildid/buildid.go b/src/cmd/internal/buildid/buildid.go
index ac238d70ea..1d6563cafc 100644
--- a/src/cmd/internal/buildid/buildid.go
+++ b/src/cmd/internal/buildid/buildid.go
@@ -10,6 +10,7 @@ import (
"fmt"
"internal/xcoff"
"io"
+ "io/fs"
"os"
"strconv"
"strings"
@@ -109,7 +110,7 @@ func ReadFile(name string) (id string, err error) {
// in cmd/go/internal/work/exec.go.
func readGccgoArchive(name string, f *os.File) (string, error) {
bad := func() (string, error) {
- return "", &os.PathError{Op: "parse", Path: name, Err: errBuildIDMalformed}
+ return "", &fs.PathError{Op: "parse", Path: name, Err: errBuildIDMalformed}
}
off := int64(8)
@@ -167,7 +168,7 @@ func readGccgoArchive(name string, f *os.File) (string, error) {
// in cmd/go/internal/work/exec.go.
func readGccgoBigArchive(name string, f *os.File) (string, error) {
bad := func() (string, error) {
- return "", &os.PathError{Op: "parse", Path: name, Err: errBuildIDMalformed}
+ return "", &fs.PathError{Op: "parse", Path: name, Err: errBuildIDMalformed}
}
// Read fixed-length header.
@@ -309,13 +310,13 @@ func readRaw(name string, data []byte) (id string, err error) {
j := bytes.Index(data[i+len(goBuildPrefix):], goBuildEnd)
if j < 0 {
- return "", &os.PathError{Op: "parse", Path: name, Err: errBuildIDMalformed}
+ return "", &fs.PathError{Op: "parse", Path: name, Err: errBuildIDMalformed}
}
quoted := data[i+len(goBuildPrefix)-1 : i+len(goBuildPrefix)+j+1]
id, err = strconv.Unquote(string(quoted))
if err != nil {
- return "", &os.PathError{Op: "parse", Path: name, Err: errBuildIDMalformed}
+ return "", &fs.PathError{Op: "parse", Path: name, Err: errBuildIDMalformed}
}
return id, nil
}
diff --git a/src/cmd/internal/buildid/note.go b/src/cmd/internal/buildid/note.go
index 2d26ea9961..f5b6fc565f 100644
--- a/src/cmd/internal/buildid/note.go
+++ b/src/cmd/internal/buildid/note.go
@@ -11,6 +11,7 @@ import (
"encoding/binary"
"fmt"
"io"
+ "io/fs"
"os"
)
@@ -96,7 +97,7 @@ func readELF(name string, f *os.File, data []byte) (buildid string, err error) {
ef, err := elf.NewFile(bytes.NewReader(data))
if err != nil {
- return "", &os.PathError{Path: name, Op: "parse", Err: err}
+ return "", &fs.PathError{Path: name, Op: "parse", Err: err}
}
var gnu string
for _, p := range ef.Progs {
@@ -181,13 +182,13 @@ func readMacho(name string, f *os.File, data []byte) (buildid string, err error)
mf, err := macho.NewFile(f)
if err != nil {
- return "", &os.PathError{Path: name, Op: "parse", Err: err}
+ return "", &fs.PathError{Path: name, Op: "parse", Err: err}
}
sect := mf.Section("__text")
if sect == nil {
// Every binary has a __text section. Something is wrong.
- return "", &os.PathError{Path: name, Op: "parse", Err: fmt.Errorf("cannot find __text section")}
+ return "", &fs.PathError{Path: name, Op: "parse", Err: fmt.Errorf("cannot find __text section")}
}
// It should be in the first few bytes, but read a lot just in case,
diff --git a/src/cmd/internal/moddeps/moddeps_test.go b/src/cmd/internal/moddeps/moddeps_test.go
index 2e6167322e..7362e7868b 100644
--- a/src/cmd/internal/moddeps/moddeps_test.go
+++ b/src/cmd/internal/moddeps/moddeps_test.go
@@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"internal/testenv"
+ "io/fs"
"io/ioutil"
"os"
"os/exec"
@@ -32,7 +33,7 @@ func findGorootModules(t *testing.T) []gorootModule {
goBin := testenv.GoToolPath(t)
goroot.once.Do(func() {
- goroot.err = filepath.Walk(runtime.GOROOT(), func(path string, info os.FileInfo, err error) error {
+ goroot.err = filepath.Walk(runtime.GOROOT(), func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
diff --git a/src/cmd/pack/pack.go b/src/cmd/pack/pack.go
index c4e116becd..82546ea7dc 100644
--- a/src/cmd/pack/pack.go
+++ b/src/cmd/pack/pack.go
@@ -8,6 +8,7 @@ import (
"cmd/internal/archive"
"fmt"
"io"
+ "io/fs"
"log"
"os"
"path/filepath"
@@ -221,7 +222,7 @@ func (ar *Archive) addFiles() {
// FileLike abstracts the few methods we need, so we can test without needing real files.
type FileLike interface {
Name() string
- Stat() (os.FileInfo, error)
+ Stat() (fs.FileInfo, error)
Read([]byte) (int, error)
Close() error
}
diff --git a/src/cmd/pack/pack_test.go b/src/cmd/pack/pack_test.go
index 2108330742..9f65705def 100644
--- a/src/cmd/pack/pack_test.go
+++ b/src/cmd/pack/pack_test.go
@@ -11,6 +11,7 @@ import (
"fmt"
"internal/testenv"
"io"
+ "io/fs"
"io/ioutil"
"os"
"os/exec"
@@ -327,11 +328,11 @@ var goodbyeFile = &FakeFile{
mode: 0644,
}
-// FakeFile implements FileLike and also os.FileInfo.
+// FakeFile implements FileLike and also fs.FileInfo.
type FakeFile struct {
name string
contents string
- mode os.FileMode
+ mode fs.FileMode
offset int
}
@@ -348,7 +349,7 @@ func (f *FakeFile) Name() string {
return f.name
}
-func (f *FakeFile) Stat() (os.FileInfo, error) {
+func (f *FakeFile) Stat() (fs.FileInfo, error) {
return f, nil
}
@@ -365,13 +366,13 @@ func (f *FakeFile) Close() error {
return nil
}
-// os.FileInfo methods.
+// fs.FileInfo methods.
func (f *FakeFile) Size() int64 {
return int64(len(f.contents))
}
-func (f *FakeFile) Mode() os.FileMode {
+func (f *FakeFile) Mode() fs.FileMode {
return f.mode
}