findFile searches the root for a specified file. A number of folders can be specified to search in addition to the root itself. If the file represents a symlink, this is resolved and the final path is returned.
(name string, searchIn ...string)
| 84 | // A number of folders can be specified to search in addition to the root itself. |
| 85 | // If the file represents a symlink, this is resolved and the final path is returned. |
| 86 | func (r root) findFile(name string, searchIn ...string) (string, error) { |
| 87 | |
| 88 | for _, d := range append([]string{"/"}, searchIn...) { |
| 89 | l := filepath.Join(string(r), d, name) |
| 90 | candidate, err := resolveLink(l) |
| 91 | if err != nil { |
| 92 | continue |
| 93 | } |
| 94 | return candidate, nil |
| 95 | } |
| 96 | |
| 97 | return "", fmt.Errorf("error locating %q", name) |
| 98 | } |
| 99 | |
| 100 | // resolveLink finds the target of a symlink or the file itself in the |
| 101 | // case of a regular file. |
no test coverage detected