From 4cecda6c347bd6902b960c6a35a967add7070b0d Mon Sep 17 00:00:00 2001 From: Ondřej Surý Date: Mon, 30 Jan 2012 15:38:19 +0100 Subject: Imported Upstream version 2012.01.27 --- src/cmd/godoc/filesystem.go | 65 +++++++++------------------------------------ 1 file changed, 13 insertions(+), 52 deletions(-) (limited to 'src/cmd/godoc/filesystem.go') 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 } -- cgit v1.2.3