summaryrefslogtreecommitdiff
path: root/src/cmd/godoc/filesystem.go
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-09-13 13:13:44 +0200
committerOndřej Surý <ondrej@sury.org>2011-09-13 13:13:44 +0200
commit9464a0c36318f8a801c07d6874bd0cea40f12504 (patch)
treef0178491c19d4f1ebc7b92eede86690998466480 /src/cmd/godoc/filesystem.go
parentba9fda6068cfadd42db0b152fdca7e8b67aaf77d (diff)
parent5ff4c17907d5b19510a62e08fd8d3b11e62b431d (diff)
downloadgolang-9464a0c36318f8a801c07d6874bd0cea40f12504.tar.gz
Merge commit 'upstream/60' into debian-sid
Diffstat (limited to 'src/cmd/godoc/filesystem.go')
-rw-r--r--src/cmd/godoc/filesystem.go34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/cmd/godoc/filesystem.go b/src/cmd/godoc/filesystem.go
index bf68378d4..a68c08592 100644
--- a/src/cmd/godoc/filesystem.go
+++ b/src/cmd/godoc/filesystem.go
@@ -2,26 +2,28 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// This file defines abstract file system access.
+// This file defines types for abstract file system access and
+// provides an implementation accessing the file system of the
+// underlying OS.
package main
import (
+ "fmt"
"io"
"io/ioutil"
"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 {
@@ -32,24 +34,20 @@ type FileSystem interface {
ReadFile(path string) ([]byte, os.Error)
}
-
// ----------------------------------------------------------------------------
// OS-specific FileSystem implementation
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
@@ -57,29 +55,40 @@ func (fi osFI) Size() int64 {
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) {
- return os.Open(path)
+ f, err := os.Open(path)
+ if err != nil {
+ return nil, err
+ }
+ fi, err := f.Stat()
+ if err != nil {
+ return nil, err
+ }
+ if fi.IsDirectory() {
+ 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) Stat(path string) (FileInfo, os.Error) {
fi, err := os.Stat(path)
return osFI{fi}, err
}
-
func (osFS) ReadDir(path string) ([]FileInfo, os.Error) {
- l0, err := ioutil.ReadDir(path)
+ l0, err := ioutil.ReadDir(path) // l0 is sorted
if err != nil {
return nil, err
}
@@ -90,7 +99,6 @@ func (osFS) ReadDir(path string) ([]FileInfo, os.Error) {
return l1, nil
}
-
func (osFS) ReadFile(path string) ([]byte, os.Error) {
return ioutil.ReadFile(path)
}