aboutsummaryrefslogtreecommitdiff
path: root/src/net
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/net
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/net')
-rw-r--r--src/net/conf_test.go8
-rw-r--r--src/net/dnsconfig_unix_test.go3
-rw-r--r--src/net/error_test.go13
-rw-r--r--src/net/http/example_filesystem_test.go14
-rw-r--r--src/net/http/fs.go9
-rw-r--r--src/net/http/fs_test.go27
-rw-r--r--src/net/ipsock_plan9.go3
7 files changed, 41 insertions, 36 deletions
diff --git a/src/net/conf_test.go b/src/net/conf_test.go
index 3c7403eccc..4c21d56ba0 100644
--- a/src/net/conf_test.go
+++ b/src/net/conf_test.go
@@ -7,7 +7,7 @@
package net
import (
- "os"
+ "io/fs"
"strings"
"testing"
)
@@ -26,7 +26,7 @@ var defaultResolvConf = &dnsConfig{
ndots: 1,
timeout: 5,
attempts: 2,
- err: os.ErrNotExist,
+ err: fs.ErrNotExist,
}
func TestConfHostLookupOrder(t *testing.T) {
@@ -106,7 +106,7 @@ func TestConfHostLookupOrder(t *testing.T) {
name: "solaris_no_nsswitch",
c: &conf{
goos: "solaris",
- nss: &nssConf{err: os.ErrNotExist},
+ nss: &nssConf{err: fs.ErrNotExist},
resolv: defaultResolvConf,
},
hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupCgo}},
@@ -176,7 +176,7 @@ func TestConfHostLookupOrder(t *testing.T) {
name: "linux_no_nsswitch.conf",
c: &conf{
goos: "linux",
- nss: &nssConf{err: os.ErrNotExist},
+ nss: &nssConf{err: fs.ErrNotExist},
resolv: defaultResolvConf,
},
hostTests: []nssHostTest{{"google.com", "myhostname", hostLookupDNSFiles}},
diff --git a/src/net/dnsconfig_unix_test.go b/src/net/dnsconfig_unix_test.go
index 42880123c5..0d7897a813 100644
--- a/src/net/dnsconfig_unix_test.go
+++ b/src/net/dnsconfig_unix_test.go
@@ -8,6 +8,7 @@ package net
import (
"errors"
+ "io/fs"
"os"
"reflect"
"strings"
@@ -183,7 +184,7 @@ func TestDNSReadMissingFile(t *testing.T) {
conf := dnsReadConfig("a-nonexistent-file")
if !os.IsNotExist(conf.err) {
- t.Errorf("missing resolv.conf:\ngot: %v\nwant: %v", conf.err, os.ErrNotExist)
+ t.Errorf("missing resolv.conf:\ngot: %v\nwant: %v", conf.err, fs.ErrNotExist)
}
conf.err = nil
want := &dnsConfig{
diff --git a/src/net/error_test.go b/src/net/error_test.go
index 62dfb9c15d..7823fdf9d8 100644
--- a/src/net/error_test.go
+++ b/src/net/error_test.go
@@ -12,6 +12,7 @@ import (
"fmt"
"internal/poll"
"io"
+ "io/fs"
"io/ioutil"
"net/internal/socktest"
"os"
@@ -97,7 +98,7 @@ second:
case *os.SyscallError:
nestedErr = err.Err
goto third
- case *os.PathError: // for Plan 9
+ case *fs.PathError: // for Plan 9
nestedErr = err.Err
goto third
}
@@ -531,7 +532,7 @@ second:
case *os.SyscallError:
nestedErr = err.Err
goto third
- case *os.PathError: // for Plan 9
+ case *fs.PathError: // for Plan 9
nestedErr = err.Err
goto third
}
@@ -546,7 +547,7 @@ third:
return nil
}
switch nestedErr {
- case os.ErrClosed: // for Plan 9
+ case fs.ErrClosed: // for Plan 9
return nil
}
return fmt.Errorf("unexpected type on 3rd nested level: %T", nestedErr)
@@ -627,7 +628,7 @@ second:
case *os.SyscallError:
nestedErr = err.Err
goto third
- case *os.PathError: // for Plan 9
+ case *fs.PathError: // for Plan 9
nestedErr = err.Err
goto third
}
@@ -706,7 +707,7 @@ second:
case *os.LinkError:
nestedErr = err.Err
goto third
- case *os.PathError:
+ case *fs.PathError:
nestedErr = err.Err
goto third
}
@@ -799,7 +800,7 @@ func parseLookupPortError(nestedErr error) error {
switch nestedErr.(type) {
case *AddrError, *DNSError:
return nil
- case *os.PathError: // for Plan 9
+ case *fs.PathError: // for Plan 9
return nil
}
return fmt.Errorf("unexpected type on 1st nested level: %T", nestedErr)
diff --git a/src/net/http/example_filesystem_test.go b/src/net/http/example_filesystem_test.go
index e1fd42d049..0e81458a07 100644
--- a/src/net/http/example_filesystem_test.go
+++ b/src/net/http/example_filesystem_test.go
@@ -5,9 +5,9 @@
package http_test
import (
+ "io/fs"
"log"
"net/http"
- "os"
"strings"
)
@@ -33,7 +33,7 @@ type dotFileHidingFile struct {
// Readdir is a wrapper around the Readdir method of the embedded File
// that filters out all files that start with a period in their name.
-func (f dotFileHidingFile) Readdir(n int) (fis []os.FileInfo, err error) {
+func (f dotFileHidingFile) Readdir(n int) (fis []fs.FileInfo, err error) {
files, err := f.File.Readdir(n)
for _, file := range files { // Filters out the dot files
if !strings.HasPrefix(file.Name(), ".") {
@@ -52,12 +52,12 @@ type dotFileHidingFileSystem struct {
// Open is a wrapper around the Open method of the embedded FileSystem
// that serves a 403 permission error when name has a file or directory
// with whose name starts with a period in its path.
-func (fs dotFileHidingFileSystem) Open(name string) (http.File, error) {
+func (fsys dotFileHidingFileSystem) Open(name string) (http.File, error) {
if containsDotFile(name) { // If dot file, return 403 response
- return nil, os.ErrPermission
+ return nil, fs.ErrPermission
}
- file, err := fs.FileSystem.Open(name)
+ file, err := fsys.FileSystem.Open(name)
if err != nil {
return nil, err
}
@@ -65,7 +65,7 @@ func (fs dotFileHidingFileSystem) Open(name string) (http.File, error) {
}
func ExampleFileServer_dotFileHiding() {
- fs := dotFileHidingFileSystem{http.Dir(".")}
- http.Handle("/", http.FileServer(fs))
+ fsys := dotFileHidingFileSystem{http.Dir(".")}
+ http.Handle("/", http.FileServer(fsys))
log.Fatal(http.ListenAndServe(":8080", nil))
}
diff --git a/src/net/http/fs.go b/src/net/http/fs.go
index d718fffba0..0743b5b621 100644
--- a/src/net/http/fs.go
+++ b/src/net/http/fs.go
@@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"io"
+ "io/fs"
"mime"
"mime/multipart"
"net/textproto"
@@ -43,7 +44,7 @@ type Dir string
// mapDirOpenError maps the provided non-nil error from opening name
// to a possibly better non-nil error. In particular, it turns OS-specific errors
-// about opening files in non-directories into os.ErrNotExist. See Issue 18984.
+// about opening files in non-directories into fs.ErrNotExist. See Issue 18984.
func mapDirOpenError(originalErr error, name string) error {
if os.IsNotExist(originalErr) || os.IsPermission(originalErr) {
return originalErr
@@ -59,7 +60,7 @@ func mapDirOpenError(originalErr error, name string) error {
return originalErr
}
if !fi.IsDir() {
- return os.ErrNotExist
+ return fs.ErrNotExist
}
}
return originalErr
@@ -98,8 +99,8 @@ type File interface {
io.Closer
io.Reader
io.Seeker
- Readdir(count int) ([]os.FileInfo, error)
- Stat() (os.FileInfo, error)
+ Readdir(count int) ([]fs.FileInfo, error)
+ Stat() (fs.FileInfo, error)
}
func dirList(w ResponseWriter, r *Request, f File) {
diff --git a/src/net/http/fs_test.go b/src/net/http/fs_test.go
index 4ac73b728f..de793b331e 100644
--- a/src/net/http/fs_test.go
+++ b/src/net/http/fs_test.go
@@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"io"
+ "io/fs"
"io/ioutil"
"mime"
"mime/multipart"
@@ -629,9 +630,9 @@ func (f *fakeFileInfo) Sys() interface{} { return nil }
func (f *fakeFileInfo) ModTime() time.Time { return f.modtime }
func (f *fakeFileInfo) IsDir() bool { return f.dir }
func (f *fakeFileInfo) Size() int64 { return int64(len(f.contents)) }
-func (f *fakeFileInfo) Mode() os.FileMode {
+func (f *fakeFileInfo) Mode() fs.FileMode {
if f.dir {
- return 0755 | os.ModeDir
+ return 0755 | fs.ModeDir
}
return 0644
}
@@ -644,12 +645,12 @@ type fakeFile struct {
}
func (f *fakeFile) Close() error { return nil }
-func (f *fakeFile) Stat() (os.FileInfo, error) { return f.fi, nil }
-func (f *fakeFile) Readdir(count int) ([]os.FileInfo, error) {
+func (f *fakeFile) Stat() (fs.FileInfo, error) { return f.fi, nil }
+func (f *fakeFile) Readdir(count int) ([]fs.FileInfo, error) {
if !f.fi.dir {
- return nil, os.ErrInvalid
+ return nil, fs.ErrInvalid
}
- var fis []os.FileInfo
+ var fis []fs.FileInfo
limit := f.entpos + count
if count <= 0 || limit > len(f.fi.ents) {
@@ -668,11 +669,11 @@ func (f *fakeFile) Readdir(count int) ([]os.FileInfo, error) {
type fakeFS map[string]*fakeFileInfo
-func (fs fakeFS) Open(name string) (File, error) {
+func (fsys fakeFS) Open(name string) (File, error) {
name = path.Clean(name)
- f, ok := fs[name]
+ f, ok := fsys[name]
if !ok {
- return nil, os.ErrNotExist
+ return nil, fs.ErrNotExist
}
if f.err != nil {
return nil, f.err
@@ -747,7 +748,7 @@ func TestDirectoryIfNotModified(t *testing.T) {
res.Body.Close()
}
-func mustStat(t *testing.T, fileName string) os.FileInfo {
+func mustStat(t *testing.T, fileName string) fs.FileInfo {
fi, err := os.Stat(fileName)
if err != nil {
t.Fatal(err)
@@ -1081,7 +1082,7 @@ func (issue12991FS) Open(string) (File, error) { return issue12991File{}, nil }
type issue12991File struct{ File }
-func (issue12991File) Stat() (os.FileInfo, error) { return nil, os.ErrPermission }
+func (issue12991File) Stat() (fs.FileInfo, error) { return nil, fs.ErrPermission }
func (issue12991File) Close() error { return nil }
func TestServeContentErrorMessages(t *testing.T) {
@@ -1091,7 +1092,7 @@ func TestServeContentErrorMessages(t *testing.T) {
err: errors.New("random error"),
},
"/403": &fakeFileInfo{
- err: &os.PathError{Err: os.ErrPermission},
+ err: &fs.PathError{Err: fs.ErrPermission},
},
}
ts := httptest.NewServer(FileServer(fs))
@@ -1289,7 +1290,7 @@ func (d fileServerCleanPathDir) Open(path string) (File, error) {
// Just return back something that's a directory.
return Dir(".").Open(".")
}
- return nil, os.ErrNotExist
+ return nil, fs.ErrNotExist
}
type panicOnSeek struct{ io.ReadSeeker }
diff --git a/src/net/ipsock_plan9.go b/src/net/ipsock_plan9.go
index 23082366aa..7a4b7a6041 100644
--- a/src/net/ipsock_plan9.go
+++ b/src/net/ipsock_plan9.go
@@ -7,6 +7,7 @@ package net
import (
"context"
"internal/bytealg"
+ "io/fs"
"os"
"syscall"
)
@@ -164,7 +165,7 @@ func fixErr(err error) {
if nonNilInterface(oe.Addr) {
oe.Addr = nil
}
- if pe, ok := oe.Err.(*os.PathError); ok {
+ if pe, ok := oe.Err.(*fs.PathError); ok {
if _, ok = pe.Err.(syscall.ErrorString); ok {
oe.Err = pe.Err
}