diff options
author | Ondřej Surý <ondrej@sury.org> | 2012-03-26 16:50:58 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2012-03-26 16:50:58 +0200 |
commit | 519725bb3c075ee2462c929f5997cb068e18466a (patch) | |
tree | 5b162e8488ad147a645048c073577821b4a2bee9 /src/cmd/godoc/utils.go | |
parent | 842623c5dd2819d980ca9c58048d6bc6ed82475f (diff) | |
download | golang-upstream-weekly/2012.03.22.tar.gz |
Imported Upstream version 2012.03.22upstream-weekly/2012.03.22
Diffstat (limited to 'src/cmd/godoc/utils.go')
-rw-r--r-- | src/cmd/godoc/utils.go | 79 |
1 files changed, 2 insertions, 77 deletions
diff --git a/src/cmd/godoc/utils.go b/src/cmd/godoc/utils.go index be0bdc306..7def015c8 100644 --- a/src/cmd/godoc/utils.go +++ b/src/cmd/godoc/utils.go @@ -7,12 +7,7 @@ package main import ( - "io" - "io/ioutil" - "os" - "path/filepath" - "sort" - "strings" + pathpkg "path" "sync" "time" "unicode/utf8" @@ -40,76 +35,6 @@ func (v *RWValue) get() (interface{}, time.Time) { 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) 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 } |