aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/godoc/filesystem.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/godoc/filesystem.go')
-rw-r--r--src/cmd/godoc/filesystem.go60
1 files changed, 10 insertions, 50 deletions
diff --git a/src/cmd/godoc/filesystem.go b/src/cmd/godoc/filesystem.go
index aa79b3693f..4e48c9e683 100644
--- a/src/cmd/godoc/filesystem.go
+++ b/src/cmd/godoc/filesystem.go
@@ -13,25 +13,15 @@ import (
"io"
"io/ioutil"
"os"
- "time"
)
-// The FileInfo interface provides access to file information.
-type FileInfo interface {
- Name() string
- Size() int64
- ModTime() time.Time
- IsRegular() bool
- IsDirectory() bool
-}
-
// The FileSystem interface specifies the methods godoc is using
// to access the file system for which it serves documentation.
type FileSystem interface {
Open(path string) (io.ReadCloser, error)
- Lstat(path string) (FileInfo, error)
- Stat(path string) (FileInfo, error)
- ReadDir(path string) ([]FileInfo, error)
+ Lstat(path string) (os.FileInfo, error)
+ Stat(path string) (os.FileInfo, error)
+ ReadDir(path string) ([]os.FileInfo, error)
}
// ReadFile reads the file named by path from fs and returns the contents.
@@ -49,26 +39,6 @@ func ReadFile(fs FileSystem, path string) ([]byte, error) {
var OS FileSystem = osFS{}
-// osFI is the OS-specific implementation of FileInfo.
-type osFI struct {
- *os.FileInfo
-}
-
-func (fi osFI) Name() string {
- return fi.FileInfo.Name
-}
-
-func (fi osFI) Size() int64 {
- if fi.IsDirectory() {
- return 0
- }
- return fi.FileInfo.Size
-}
-
-func (fi osFI) ModTime() time.Time {
- return fi.FileInfo.ModTime
-}
-
// osFS is the OS-specific implementation of FileSystem
type osFS struct{}
@@ -81,30 +51,20 @@ func (osFS) Open(path string) (io.ReadCloser, error) {
if err != nil {
return nil, err
}
- if fi.IsDirectory() {
+ if fi.IsDir() {
return nil, fmt.Errorf("Open: %s is a directory", path)
}
return f, nil
}
-func (osFS) Lstat(path string) (FileInfo, error) {
- fi, err := os.Lstat(path)
- return osFI{fi}, err
+func (osFS) Lstat(path string) (os.FileInfo, error) {
+ return os.Lstat(path)
}
-func (osFS) Stat(path string) (FileInfo, error) {
- fi, err := os.Stat(path)
- return osFI{fi}, err
+func (osFS) Stat(path string) (os.FileInfo, error) {
+ return os.Stat(path)
}
-func (osFS) ReadDir(path string) ([]FileInfo, error) {
- l0, err := ioutil.ReadDir(path) // l0 is sorted
- if err != nil {
- return nil, err
- }
- l1 := make([]FileInfo, len(l0))
- for i, e := range l0 {
- l1[i] = osFI{e}
- }
- return l1, nil
+func (osFS) ReadDir(path string) ([]os.FileInfo, error) {
+ return ioutil.ReadDir(path) // is sorted
}