LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // This file contains support functionality for godoc. | 5 // This file contains support functionality for godoc. |
6 | 6 |
7 package main | 7 package main |
8 | 8 |
9 import ( | 9 import ( |
10 "io" | 10 "io" |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 | 38 |
39 | 39 |
40 func (v *RWValue) get() (interface{}, int64) { | 40 func (v *RWValue) get() (interface{}, int64) { |
41 v.mutex.RLock() | 41 v.mutex.RLock() |
42 defer v.mutex.RUnlock() | 42 defer v.mutex.RUnlock() |
43 return v.value, v.timestamp | 43 return v.value, v.timestamp |
44 } | 44 } |
45 | 45 |
46 | 46 |
| 47 // TODO(gri) For now, using os.Getwd() is ok here since the functionality |
| 48 // based on this code is not invoked for the appengine version, |
| 49 // but this is fragile. Determine what the right thing to do is, |
| 50 // here (possibly have some Getwd-equivalent in FileSystem). |
47 var cwd, _ = os.Getwd() // ignore errors | 51 var cwd, _ = os.Getwd() // ignore errors |
48 | 52 |
49 // canonicalizePaths takes a list of (directory/file) paths and returns | 53 // canonicalizePaths takes a list of (directory/file) paths and returns |
50 // the list of corresponding absolute paths in sorted (increasing) order. | 54 // the list of corresponding absolute paths in sorted (increasing) order. |
51 // Relative paths are assumed to be relative to the current directory, | 55 // Relative paths are assumed to be relative to the current directory, |
52 // empty and duplicate paths as well as paths for which filter(path) is | 56 // empty and duplicate paths as well as paths for which filter(path) is |
53 // false are discarded. filter may be nil in which case it is not used. | 57 // false are discarded. filter may be nil in which case it is not used. |
54 // | 58 // |
55 func canonicalizePaths(list []string, filter func(path string) bool) []string { | 59 func canonicalizePaths(list []string, filter func(path string) bool) []string { |
56 i := 0 | 60 i := 0 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 92 } |
89 | 93 |
90 return list[0:i] | 94 return list[0:i] |
91 } | 95 } |
92 | 96 |
93 | 97 |
94 // writeFileAtomically writes data to a temporary file and then | 98 // writeFileAtomically writes data to a temporary file and then |
95 // atomically renames that file to the file named by filename. | 99 // atomically renames that file to the file named by filename. |
96 // | 100 // |
97 func writeFileAtomically(filename string, data []byte) os.Error { | 101 func writeFileAtomically(filename string, data []byte) os.Error { |
| 102 // TODO(gri) this won't work on appengine |
98 f, err := ioutil.TempFile(filepath.Split(filename)) | 103 f, err := ioutil.TempFile(filepath.Split(filename)) |
99 if err != nil { | 104 if err != nil { |
100 return err | 105 return err |
101 } | 106 } |
102 n, err := f.Write(data) | 107 n, err := f.Write(data) |
103 f.Close() | 108 f.Close() |
104 if err != nil { | 109 if err != nil { |
105 return err | 110 return err |
106 } | 111 } |
107 if n < len(data) { | 112 if n < len(data) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // readable text. | 153 // readable text. |
149 // | 154 // |
150 func isTextFile(filename string) bool { | 155 func isTextFile(filename string) bool { |
151 // if the extension is known, use it for decision making | 156 // if the extension is known, use it for decision making |
152 if isText, found := textExt[filepath.Ext(filename)]; found { | 157 if isText, found := textExt[filepath.Ext(filename)]; found { |
153 return isText | 158 return isText |
154 } | 159 } |
155 | 160 |
156 // the extension is not known; read an initial chunk | 161 // the extension is not known; read an initial chunk |
157 // of the file and check if it looks like text | 162 // of the file and check if it looks like text |
158 » f, err := os.Open(filename) | 163 » f, err := fs.Open(filename) |
159 if err != nil { | 164 if err != nil { |
160 return false | 165 return false |
161 } | 166 } |
162 defer f.Close() | 167 defer f.Close() |
163 | 168 |
164 var buf [1024]byte | 169 var buf [1024]byte |
165 n, err := f.Read(buf[0:]) | 170 n, err := f.Read(buf[0:]) |
166 if err != nil { | 171 if err != nil { |
167 return false | 172 return false |
168 } | 173 } |
169 | 174 |
170 return isText(buf[0:n]) | 175 return isText(buf[0:n]) |
171 } | 176 } |
LEFT | RIGHT |