fileRoot returns the absolute path for Root.
(root *Root)
| 148 | |
| 149 | // fileRoot returns the absolute path for Root. |
| 150 | func fileRoot(root *Root) (_ string, err error) { |
| 151 | defer util.Wrapf(&err, "root %q", root.URI) |
| 152 | |
| 153 | // Convert to absolute file path. |
| 154 | rurl, err := url.Parse(root.URI) |
| 155 | if err != nil { |
| 156 | return "", err |
| 157 | } |
| 158 | if rurl.Scheme != "file" { |
| 159 | return "", errors.New("not a file URI") |
| 160 | } |
| 161 | if rurl.Path == "" { |
| 162 | // A more specific error than the one below, to catch the |
| 163 | // common mistake "file://foo". |
| 164 | return "", errors.New("empty path") |
| 165 | } |
| 166 | // We don't want Localize here: we want an absolute path, which is not local. |
| 167 | fileRoot := filepath.Clean(filepath.FromSlash(rurl.Path)) |
| 168 | if !filepath.IsAbs(fileRoot) { |
| 169 | return "", errors.New("not an absolute path") |
| 170 | } |
| 171 | return fileRoot, nil |
| 172 | } |
| 173 | |
| 174 | // Matches reports whether the receiver's uri template matches the uri. |
| 175 | func (sr *serverResourceTemplate) Matches(uri string) bool { |
searching dependent graphs…