diff options
Diffstat (limited to 'src/cmd/godoc/utils.go')
-rw-r--r-- | src/cmd/godoc/utils.go | 87 |
1 files changed, 6 insertions, 81 deletions
diff --git a/src/cmd/godoc/utils.go b/src/cmd/godoc/utils.go index 11e46aee5..7def015c8 100644 --- a/src/cmd/godoc/utils.go +++ b/src/cmd/godoc/utils.go @@ -7,15 +7,10 @@ package main import ( - "io" - "io/ioutil" - "os" - "path/filepath" - "sort" - "strings" + pathpkg "path" "sync" "time" - "utf8" + "unicode/utf8" ) // An RWValue wraps a value and permits mutually exclusive @@ -24,92 +19,22 @@ import ( type RWValue struct { mutex sync.RWMutex value interface{} - timestamp int64 // time of last set(), in seconds since epoch + timestamp time.Time // time of last set() } func (v *RWValue) set(value interface{}) { v.mutex.Lock() v.value = value - v.timestamp = time.Seconds() + v.timestamp = time.Now() v.mutex.Unlock() } -func (v *RWValue) get() (interface{}, int64) { +func (v *RWValue) get() (interface{}, time.Time) { v.mutex.RLock() defer v.mutex.RUnlock() return v.value, v.timestamp } -// TODO(gri) For now, using os.Getwd() is ok here since the functionality -// based on this code is not invoked for the appengine version, -// but this is fragile. Determine what the right thing to do is, -// here (possibly have some Getwd-equivalent in FileSystem). -var cwd, _ = os.Getwd() // ignore errors - -// canonicalizePaths takes a list of (directory/file) paths and returns -// the list of corresponding absolute paths in sorted (increasing) order. -// Relative paths are assumed to be relative to the current directory, -// empty and duplicate paths as well as paths for which filter(path) is -// false are discarded. filter may be nil in which case it is not used. -// -func canonicalizePaths(list []string, filter func(path string) bool) []string { - i := 0 - for _, path := range list { - path = strings.TrimSpace(path) - if len(path) == 0 { - continue // ignore empty paths (don't assume ".") - } - // len(path) > 0: normalize path - if filepath.IsAbs(path) { - path = filepath.Clean(path) - } else { - path = filepath.Join(cwd, path) - } - // we have a non-empty absolute path - if filter != nil && !filter(path) { - continue - } - // keep the path - list[i] = path - i++ - } - list = list[0:i] - - // sort the list and remove duplicate entries - sort.Strings(list) - i = 0 - prev := "" - for _, path := range list { - if path != prev { - list[i] = path - i++ - prev = path - } - } - - return list[0:i] -} - -// writeFileAtomically writes data to a temporary file and then -// atomically renames that file to the file named by filename. -// -func writeFileAtomically(filename string, data []byte) os.Error { - // TODO(gri) this won't work on appengine - f, err := ioutil.TempFile(filepath.Split(filename)) - if err != nil { - return err - } - n, err := f.Write(data) - f.Close() - if err != nil { - return err - } - if n < len(data) { - return io.ErrShortWrite - } - return os.Rename(f.Name(), filename) -} - // isText returns true if a significant prefix of s looks like correct UTF-8; // that is, if it is likely that s is human-readable text. // @@ -146,7 +71,7 @@ var textExt = map[string]bool{ // func isTextFile(filename string) bool { // if the extension is known, use it for decision making - if isText, found := textExt[filepath.Ext(filename)]; found { + if isText, found := textExt[pathpkg.Ext(filename)]; found { return isText } |