diff options
author | Russ Cox <rsc@golang.org> | 2020-07-07 13:49:21 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2020-10-20 02:32:42 +0000 |
commit | 7bb721b9384bdd196befeaed593b185f7f2a5589 (patch) | |
tree | 882f21fc2e1fbba6fb11100e4fd8efc5f973a44d /src/go | |
parent | d4da735091986868015369e01c63794af9cc9b84 (diff) | |
download | go-7bb721b9384bdd196befeaed593b185f7f2a5589.tar.gz go-7bb721b9384bdd196befeaed593b185f7f2a5589.zip |
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/go')
-rw-r--r-- | src/go/build/build.go | 9 | ||||
-rw-r--r-- | src/go/build/deps_test.go | 3 | ||||
-rw-r--r-- | src/go/doc/doc_test.go | 6 | ||||
-rw-r--r-- | src/go/doc/headscan.go | 5 | ||||
-rw-r--r-- | src/go/parser/interface.go | 6 | ||||
-rw-r--r-- | src/go/parser/parser_test.go | 4 |
6 files changed, 18 insertions, 15 deletions
diff --git a/src/go/build/build.go b/src/go/build/build.go index 7a96680e77..6141f4a90e 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -15,6 +15,7 @@ import ( "internal/goroot" "internal/goversion" "io" + "io/fs" "io/ioutil" "os" "os/exec" @@ -98,10 +99,10 @@ type Context struct { // filepath.EvalSymlinks. HasSubdir func(root, dir string) (rel string, ok bool) - // ReadDir returns a slice of os.FileInfo, sorted by Name, + // ReadDir returns a slice of fs.FileInfo, sorted by Name, // describing the content of the named directory. // If ReadDir is nil, Import uses ioutil.ReadDir. - ReadDir func(dir string) ([]os.FileInfo, error) + ReadDir func(dir string) ([]fs.FileInfo, error) // OpenFile opens a file (not a directory) for reading. // If OpenFile is nil, Import uses os.Open. @@ -183,7 +184,7 @@ func hasSubdir(root, dir string) (rel string, ok bool) { } // readDir calls ctxt.ReadDir (if not nil) or else ioutil.ReadDir. -func (ctxt *Context) readDir(path string) ([]os.FileInfo, error) { +func (ctxt *Context) readDir(path string) ([]fs.FileInfo, error) { if f := ctxt.ReadDir; f != nil { return f(path) } @@ -794,7 +795,7 @@ Found: if d.IsDir() { continue } - if (d.Mode() & os.ModeSymlink) != 0 { + if d.Mode()&fs.ModeSymlink != 0 { if fi, err := os.Stat(filepath.Join(p.Dir, d.Name())); err == nil && fi.IsDir() { // Symlinks to directories are not source files. continue diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go index 96e239ad77..9e72c8f234 100644 --- a/src/go/build/deps_test.go +++ b/src/go/build/deps_test.go @@ -11,6 +11,7 @@ import ( "bytes" "fmt" "internal/testenv" + "io/fs" "io/ioutil" "os" "path/filepath" @@ -500,7 +501,7 @@ func listStdPkgs(goroot string) ([]string, error) { var pkgs []string src := filepath.Join(goroot, "src") + string(filepath.Separator) - walkFn := func(path string, fi os.FileInfo, err error) error { + walkFn := func(path string, fi fs.FileInfo, err error) error { if err != nil || !fi.IsDir() || path == src { return nil } diff --git a/src/go/doc/doc_test.go b/src/go/doc/doc_test.go index f1e612c18b..ab98bed62b 100644 --- a/src/go/doc/doc_test.go +++ b/src/go/doc/doc_test.go @@ -12,8 +12,8 @@ import ( "go/parser" "go/printer" "go/token" + "io/fs" "io/ioutil" - "os" "path/filepath" "regexp" "strings" @@ -66,7 +66,7 @@ func indentFmt(indent, s string) string { return indent + strings.ReplaceAll(s, "\n", "\n"+indent) + end } -func isGoFile(fi os.FileInfo) bool { +func isGoFile(fi fs.FileInfo) bool { name := fi.Name() return !fi.IsDir() && len(name) > 0 && name[0] != '.' && // ignore .files @@ -86,7 +86,7 @@ func test(t *testing.T, mode Mode) { if err != nil { t.Fatal(err) } - filter = func(fi os.FileInfo) bool { + filter = func(fi fs.FileInfo) bool { return isGoFile(fi) && rx.MatchString(fi.Name()) } } diff --git a/src/go/doc/headscan.go b/src/go/doc/headscan.go index 3f782cc1b4..8ea462366e 100644 --- a/src/go/doc/headscan.go +++ b/src/go/doc/headscan.go @@ -23,6 +23,7 @@ import ( "go/parser" "go/token" "internal/lazyregexp" + "io/fs" "os" "path/filepath" "runtime" @@ -39,7 +40,7 @@ var html_h = lazyregexp.New(`<h3 id="[^"]*">`) const html_endh = "</h3>\n" -func isGoFile(fi os.FileInfo) bool { +func isGoFile(fi fs.FileInfo) bool { return strings.HasSuffix(fi.Name(), ".go") && !strings.HasSuffix(fi.Name(), "_test.go") } @@ -68,7 +69,7 @@ func main() { flag.Parse() fset := token.NewFileSet() nheadings := 0 - err := filepath.Walk(*root, func(path string, fi os.FileInfo, err error) error { + err := filepath.Walk(*root, func(path string, fi fs.FileInfo, err error) error { if !fi.IsDir() { return nil } diff --git a/src/go/parser/interface.go b/src/go/parser/interface.go index 54f9d7b80a..b2d834fdec 100644 --- a/src/go/parser/interface.go +++ b/src/go/parser/interface.go @@ -12,8 +12,8 @@ import ( "go/ast" "go/token" "io" + "io/fs" "io/ioutil" - "os" "path/filepath" "strings" ) @@ -123,7 +123,7 @@ func ParseFile(fset *token.FileSet, filename string, src interface{}, mode Mode) // directory specified by path and returns a map of package name -> package // AST with all the packages found. // -// If filter != nil, only the files with os.FileInfo entries passing through +// If filter != nil, only the files with fs.FileInfo entries passing through // the filter (and ending in ".go") are considered. The mode bits are passed // to ParseFile unchanged. Position information is recorded in fset, which // must not be nil. @@ -132,7 +132,7 @@ func ParseFile(fset *token.FileSet, filename string, src interface{}, mode Mode) // returned. If a parse error occurred, a non-nil but incomplete map and the // first error encountered are returned. // -func ParseDir(fset *token.FileSet, path string, filter func(os.FileInfo) bool, mode Mode) (pkgs map[string]*ast.Package, first error) { +func ParseDir(fset *token.FileSet, path string, filter func(fs.FileInfo) bool, mode Mode) (pkgs map[string]*ast.Package, first error) { list, err := ioutil.ReadDir(path) if err != nil { return nil, err diff --git a/src/go/parser/parser_test.go b/src/go/parser/parser_test.go index 25a374eeef..7193a329fe 100644 --- a/src/go/parser/parser_test.go +++ b/src/go/parser/parser_test.go @@ -9,7 +9,7 @@ import ( "fmt" "go/ast" "go/token" - "os" + "io/fs" "strings" "testing" ) @@ -40,7 +40,7 @@ func nameFilter(filename string) bool { return false } -func dirFilter(f os.FileInfo) bool { return nameFilter(f.Name()) } +func dirFilter(f fs.FileInfo) bool { return nameFilter(f.Name()) } func TestParseFile(t *testing.T) { src := "package p\nvar _=s[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]+\ns[::]" |