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/cmd/gofmt | |
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/cmd/gofmt')
-rw-r--r-- | src/cmd/gofmt/gofmt.go | 9 | ||||
-rw-r--r-- | src/cmd/gofmt/long_test.go | 3 |
2 files changed, 7 insertions, 5 deletions
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 |