summaryrefslogtreecommitdiff
path: root/src/cmd/godoc/filesystem.go
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2012-01-30 15:38:19 +0100
committerOndřej Surý <ondrej@sury.org>2012-01-30 15:38:19 +0100
commit4cecda6c347bd6902b960c6a35a967add7070b0d (patch)
treea462e224ff41ec9f3eb1a0b6e815806f9e8804ad /src/cmd/godoc/filesystem.go
parent6c7ca6e4d4e26e4c8cbe0d183966011b3b088a0a (diff)
downloadgolang-4cecda6c347bd6902b960c6a35a967add7070b0d.tar.gz
Imported Upstream version 2012.01.27upstream-weekly/2012.01.27
Diffstat (limited to 'src/cmd/godoc/filesystem.go')
-rw-r--r--src/cmd/godoc/filesystem.go65
1 files changed, 13 insertions, 52 deletions
diff --git a/src/cmd/godoc/filesystem.go b/src/cmd/godoc/filesystem.go
index 011977af9..4e48c9e68 100644
--- a/src/cmd/godoc/filesystem.go
+++ b/src/cmd/godoc/filesystem.go
@@ -15,26 +15,17 @@ import (
"os"
)
-// The FileInfo interface provides access to file information.
-type FileInfo interface {
- Name() string
- Size() int64
- Mtime_ns() int64
- 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, os.Error)
- Lstat(path string) (FileInfo, os.Error)
- Stat(path string) (FileInfo, os.Error)
- ReadDir(path string) ([]FileInfo, os.Error)
+ Open(path string) (io.ReadCloser, 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.
-func ReadFile(fs FileSystem, path string) ([]byte, os.Error) {
+func ReadFile(fs FileSystem, path string) ([]byte, error) {
rc, err := fs.Open(path)
if err != nil {
return nil, err
@@ -48,30 +39,10 @@ func ReadFile(fs FileSystem, path string) ([]byte, os.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) Mtime_ns() int64 {
- return fi.FileInfo.Mtime_ns
-}
-
// osFS is the OS-specific implementation of FileSystem
type osFS struct{}
-func (osFS) Open(path string) (io.ReadCloser, os.Error) {
+func (osFS) Open(path string) (io.ReadCloser, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
@@ -80,30 +51,20 @@ func (osFS) Open(path string) (io.ReadCloser, os.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, os.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, os.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, os.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
}