findFileInDir searches for a file by name within dir (recursively). Returns the first matching path, or empty string if not found.
(dir, name string)
| 139 | // findFileInDir searches for a file by name within dir (recursively). |
| 140 | // Returns the first matching path, or empty string if not found. |
| 141 | func findFileInDir(dir, name string) string { |
| 142 | var found string |
| 143 | if walkErr := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { |
| 144 | if err != nil { |
| 145 | copilotEventsJSONLLog.Printf("walk error at %s: %v", path, err) |
| 146 | return nil |
| 147 | } |
| 148 | if info == nil { |
| 149 | return nil |
| 150 | } |
| 151 | if !info.IsDir() && info.Name() == name && found == "" { |
| 152 | found = path |
| 153 | return errWalkStop |
| 154 | } |
| 155 | return nil |
| 156 | }); walkErr != nil && !errors.Is(walkErr, errWalkStop) { |
| 157 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("filesystem error walking %s: %v", dir, walkErr))) |
| 158 | } |
| 159 | return found |
| 160 | } |
| 161 | |
| 162 | // parseEventsJSONLMetrics parses a Copilot events.jsonl file and extracts log metrics. |
| 163 | // |
no test coverage detected