Skip to content

Commit f64f119

Browse files
honour file package
Local file variable overwrites func parameter, so if you have files with same names in different packages it produces wrong results.
1 parent 2665ef4 commit f64f119

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ var pkgCache = map[string]cacheEntry{}
4343

4444
// given a module+file spec (e.g. github.com/jandelgado/gcov2lcov/main.go),
4545
// strip of the module name and return the file name (e.g. main.go).
46-
func findFile(file string) (string, error) {
47-
dir, file := filepath.Split(file)
46+
func findFile(filePath string) (string, error) {
47+
dir, file := filepath.Split(filePath)
4848
var result cacheEntry
4949
var ok bool
50-
if result, ok = pkgCache[file]; !ok {
50+
if result, ok = pkgCache[filePath]; !ok {
5151
pkg, err := build.Import(dir, ".", build.FindOnly)
5252
if err == nil {
5353
result = cacheEntry{filepath.Join(pkg.Dir, file), nil}
5454
} else {
5555
result = cacheEntry{"", err}
5656
}
57-
pkgCache[file] = result
57+
pkgCache[filePath] = result
5858
}
5959
return result.file, result.err
6060
}

0 commit comments

Comments
 (0)